https://www.dendron.so/ logo
#chat
Title
# chat
k

kevins8

11/20/2021, 5:05 AM
dendron + vim
@icedwater @User starting a thread of folks interested in using dendron with vim. for bystanders, feel free to add yourself here if interested
b

benhsm | Jack of N trades

11/20/2021, 5:07 AM
Really happy about this, I was thinking of asking you at some point for a channel or thread on this 😁
i

icedwater

11/20/2021, 5:43 AM
I'm following the regular getting started tutorial and trying to see what in the CLI corresponds. Like the green Initialize Workspace button would be
mkdir $dirname && dendron workspace init --wsRoot $dirname
Oof.
dendron note lookup --query $notename
works but it also spits a lot of json at you haha
b

benhsm | Jack of N trades

11/20/2021, 6:18 AM
gotta use the "quiet" option
I'm wrapping something up right now, half an hour or so, but then I'll post my configs and some scripts in some form
i

icedwater

11/20/2021, 6:25 AM
Good point.
I'll see how much quieter
--quiet
is, heh
Shall be back on this after my German practice session
b

benhsm | Jack of N trades

11/20/2021, 6:46 AM
alright, about 2AM for me
I'll put my stuff here and then sleep
since this is a dedicated thread, I'll just put things directly here rather than using paste bins. Later, if things seem ok for public consumption, I'll figure out some other way to distribute
Here's the script I've been using for most of my lookups:
Copy code
sh
#!/bin/sh
# Looks up a Dendron note and opens it in an editor

# Dependencies:
# fzf, fd, bat dendron-cli
#   fd and bat could have just been find and cat
# 
# Required env variables:
#   DENDRON_DIR -> Set to workspace root directory
#   DENDRON_VAULT -> Set this to the vault you want to use

# Usage: if a note exists, select it from the fzf prompt with 'enter' to view/edit it.
#        if the note doesn't exist, use the binding 'ctrl-l' to create a new note with that name

cd "$DENDRON_VAULT" || exit

NOTE="${1:-$(fd --exclude assets --exclude ./*.yml | sed -E 's/\.[^.]*$//' | fzf --height 90% --margin 5% --layout=reverse --border --bind ctrl-l:print-query --preview='bat --terminal-width 70 --wrap=auto --style numbers,changes --color=always {}.md')}"

if test -z "$NOTE"; then 
#    printf "\nNo input. Doing nothing.\n"
    exit;
fi;

if test -f "$NOTE.md"; then
    exec $EDITOR "${NOTE}.md" || echo "There was a problem"
else
    dendron note lookup --quiet --wsRoot "$DENDRON_DIR" --query "$NOTE" && exec "$EDITOR" + "${NOTE}.md" || echo "There was a problem"
fi

clear
then in $ZDOTDIR/.zshrc I have a binding:
Copy code
zsh
lookup-note() {
  lookup
  zle reset-prompt
  # see: https://stackoverflow.com/questions/9212508/how-to-redraw-the-zsh-prompt-after-widget-action
}
zle -N lookup-note
bindkey -v '^L' lookup-note
where '^L' is the literal for . So hitting that keybind brings up fzf in my terminal with the notes in my vault and a preview
i

icedwater

11/20/2021, 6:52 AM
Thanks @benhsm | Jack of N trades!
Rest well!
b

benhsm | Jack of N trades

11/20/2021, 6:53 AM
sure thing
thanks for documenting this
Here's what the above script looks like in action on my setup
i

icedwater

11/20/2021, 6:59 AM
Oh, you have a lookup in the terminal, nice
b

benhsm | Jack of N trades

11/20/2021, 7:01 AM
there were some kinks recently with connecting to a running engine, so it's a little slow for making new notes
but hopefully with the recent fixes that shouldn't be a problem anymore, and I can reconfigure the look-up options accordingly
also using fzf we can get the same thing in vim/nvim
here's the section in my vimrc pertaining to Dendron:
Copy code
vim
" Dendron config
" see: https://damien.pobel.fr/post/configure-neovim-vim-gf-javascript-import/
augroup dendron
    autocmd!
    au BufReadPost $DENDRON_VAULT* setlocal path+=$DENDRON_VAULT
    au BufReadPost $DENDRON_VAULT* setlocal suffixesadd=.md
    au BufReadPost $DENDRON_VAULT* lcd $DENDRON_VAULT
augroup END

function! LookupHandler(note) abort
    let fullpath = $DENDRON_VAULT . '/' . a:note . ".md"
    if filereadable(fullpath)
        execute "edit " . fullpath
    else
        execute '!dendron note lookup --quiet --wsRoot "$DENDRON_DIR" --query ' . a:note
        execute "edit " . fullpath
    endif
endfunction

function! FzfLookUp()
    cd $DENDRON_VAULT
    let options = ['--layout=reverse', '--info=inline', '--preview', 'bat --wrap=auto --style numbers,changes --color=always {}.md', '--bind', 'ctrl-l:print-query']
    let window = {'width': 0.9, 'height': 0.9}
    call fzf#run({'source': 'fd --exclude assets --exclude ./*.yml | sed -E "s/\.[^.]*$//"', 'sink': funcref('LookupHandler'), 'window': window, 'options': options})
    cd -
endfunction

function! DendronSearch(term)
    cd $DENDRON_VAULT
    let options = ['--layout=reverse', '--info=inline', '--preview', 'bat --wrap=auto --style numbers,changes --color=always {}.md', '--bind', 'ctrl-l:print-query']
    let window = {'width': 0.9, 'height': 0.9}
    call fzf#run({'source': 'rg --files-with-matches --smart-case ' . a:term . ' | sed -E "s/\.[^.]*$//"', 'sink': funcref('LookupHandler'), 'window': window, 'options': options})
    cd -
endfunction

command! -nargs=1 Search call DendronSearch("<args>")
and then FzfLookUp gets mapped to a key combo somewhere else
this gets us lookup and text search with fuzzy finding, and navigating wikilinks using
gf
also filename omnicompletion, though I haven't yet figured out how to chop off the file extension in the completed text
fzf.vim stuff is needed, but I think that's the only plugin needed here I haven't yet implemented syntax highlighting for wikilinks, but I'm thinking I can copy something from the vimwiki plugin
one thing to note, you can also use the
--output
option to get it to spit out markdown
I have a text-search script which is almost the same as the lookup script except that the
fd
command is swapped out with a ripgrep command:
Copy code
zsh
rg --files-with-matches --smart-case "$@"
similar to the vim function just above
the cli doesn't facilitate special note types the way the VSCode plugin does, so scripts like this for journal notes:
Copy code
sh
#!/bin/sh
# Queries a Dendron journal note and opens it in an editor
# If called with an argument, makes a journal note in that domain
# If called with no argument, makes a journal note in the 'daily' domain

JOURNAL_ROOT="${1-daily}"
JOURNAL_NOTE="$JOURNAL_ROOT.journal.$(date +%Y.%m.%d)"

if test -f "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"; then
    if test "$EDITOR" = "nvim" || test "$EDITOR" = "vim"; then
        exec "$EDITOR" + "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"
    else
        exec "$EDITOR" "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"
    fi
fi

dendron note lookup --wsRoot "$DENDRON_DIR" --query "$JOURNAL_NOTE" --quiet && exec $EDITOR "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"
Things my setup is not robust to: - I haven't played around with multi-vault, so all my stuff just assumes one vault and one workspace that have environment variables pointing to them - it is assumed that all the notes are markdown, though dendron could index other filetypes - everything is based around fzf. The other stuff, rg, fd, bat, there are standard GNU programs that are equivalent (grep, find, cat)
The biggest limitation for basic functionality right now is not being able to rename/move notes and refactor hierarchies from the CLI
without breaking links
that's the stuff I still need to fire up VSCode for
I think that I'm pretty close and I'll have a pull request for this soon
... and that's about all I've put together as far as Dendron-Vim integration goes
it works for my modest daily needs
however slapdash it may be
let me know if you notice any obvious improvements I can make to this code
I have some extra scripts for fun things like
opening random notes
Copy code
sh
#!/bin/sh
# Opens a random Dendron note

cd "$DENDRON_VAULT" || exit
nvim -c "call TogglePager()"  "$(fd --exclude assets --exclude ./*.yml | shuf | head -n 1)"
converting notes into pdfs and opening them in zathura
the other stuff that I want to work on in the future that relates to the dendron engine itself and not just scripting around it:
- querying for a note and getting all the backlinks to it
- speeding up the lookup process by having things stored in a database
quite soon I'm going to need to refactor all of this stuff to work with an engine running in the background
oh yeah, one more thing
there's some interesting possibilities with ctags, with some sort of regexp extension
i

icedwater

11/20/2021, 8:00 AM
Nice hah
Do get some sleep 😃
I had a nap myself, not many people came for the German session
Most of the initial JSON output was an ENOENT because probably I hadn't configured the workspace right and it didn't find dendron.code-workspace
I'll be putting my work in https://github.com/icedwater/vimdendron as and when I remember to...
Thanks for recommending fzf. I think I'd rather rely first on a tree view of the hierarchy like in vscode, if I can figure out how to do that
b

benhsm | Jack of N trades

11/20/2021, 2:12 PM
afaik, for now if you want that you'll need to code something
are you thinking about something like the unix tree?
or more like nerdtree or nnn?
actually, nnn complements fzf very well anyways
i

icedwater

11/20/2021, 2:52 PM
The message caching is a bit strange here. But eh
Yeah, I saw nnn. I don't know which sort of plugins to use so that we can parse filenames into hierarchies
But it's not on my priority list. I'm writing a create_workspace, create_vault, lookup_note etc function first
b

benhsm | Jack of N trades

11/20/2021, 3:28 PM
as in vim functions?
i

icedwater

11/20/2021, 4:07 PM
Yeah
First cut is already in the repo. It's basically a wrapper for the CLI... But I'm also learning vimscript on the fly
Anyway, my turn to head to bed. Cheers!
b

benhsm | Jack of N trades

11/20/2021, 4:14 PM
for those kinds of things, I tend to think that shell-script wrappers are better suited
called from vim with
:! [...]
type stuff
the useability from within Vim ends up being about the same, and you get loads more interoperability with everything else
you could say one of my priorities is to write as little vimscript as may be necessary for functional integration
i

icedwater

11/25/2021, 5:31 PM
That's a good point, actually. But I've always been thinking about using vim as an IDE of sorts, so I have had an interest in building more plugins for some time now
b

benhsm | Jack of N trades

11/25/2021, 5:35 PM
The direction that it seems to me like things are going in, the most fruitful path for feature-ful, "tight" integration with Dendron would be building a Dendron-client as a node-based Neovim plugin
probably using Coc.Nvim: https://github.com/neoclide/coc.nvim
given that Dendron is node-based and that there are plans to make use of language servers for interoperability
meanwhile, vim functions and shellscripts get us cheap, fast integration which is more widely compatible
i

icedwater

11/30/2021, 3:59 AM
I'm not familiar enough with neovim to comment on this, but it does sound like something lazy me would use if someone else does it. How's backwards compatibility for neovim stuff with regular vim?
I will try to make time to peek at coc.nvim...
b

benhsm | Jack of N trades

11/30/2021, 10:45 AM
it is almost the case that everything you can do in vim can be done in neovim, but the converse is often not true; particularly, wrt what we're talking about, it seems unlikely that vim would support nodeJS plugins
nvim also has built-in stuff for LSP, which Vim has external plugins for that aren't quite as integrated
i

icedwater

11/30/2021, 12:58 PM
Ah, nodejs plugins
k

kevins8

11/30/2021, 4:06 PM
neovim has been a breath of fresh air in terms of vim development. having worked on a few vim plugins, as much as I love vim, developing for it is a pain. vscode also supports native neovim integration
m

mandarvaze

12/11/2021, 5:17 AM
I'm looking for neovim GUI that I can start from cmdline on macOS A few I tried are packaged as
.app
which is a directory, not a binary - so while macOS/finder understands them, terminal does not "execute" it - it can
cd
into it. Any suggestions ? In the mean time, I'm OK w/ nvim binary, which is not a GUI. so it is OK.
b

benhsm | Jack of N trades

12/11/2021, 12:30 PM
says "no nonsense", but actually has a lot of nice graphical extras, like cursor smearing
it is not without kinks. I've had some font and driver issues in the past, and there's been some bumps with emoji
I use linux, so I don't know how it will rum on a mac
f

fudo

02/27/2022, 4:33 PM
@User did you have any luck? if not you may want to symlink the executable that is found within the
.app
into a folder that loads your bin into your path
Or you could use the
open
command wich takes the
{application}.app
name / path and executes as if you double clicked on it
8 Views