Auto Complete Tags in Vim
July 11, 2020 ยท View on GitHub
This is essentially an easy way to get tags auto completed in vim.
Requirements
Recommended
- GNU Stow will make life a little easier with respect to copying scripts etc.
- Vim-Plug
- This will make FZF.Vim easier to install.
- ripgrep
- This provides an easy way to insert
#tags- I'll post up a simple R script to pass
#tagsto [TMSU after exams and put a link here.
- I'll post up a simple R script to pass
- This provides an easy way to insert
This is really written with Linux in mind.
Usage
- Download the
printMarkdownTagsfolder to~/bin/- Alternatively download it to
~/DotFiles/Scripts/binand then performstow -S -t $HOME ~/DotFiles/Scripts
- Alternatively download it to
- Install FZF.Vim
- If youre Notes are in
~/Notes/MD/notesthen Add the following to your~/.vimrc(and/or possibly~/.config/nvim/init.vim), otherwise modify the directory to match your flavour:
imap <expr> <C-c><C-y> fzf#vim#complete('node ~/bin/printMarkdownTags/yaml-parse.js $HOME/Notes/MD/notes \| sort -u')
imap <expr> <C-c><C-t> fzf#vim#complete('rg --pcre2 "\s#[a-zA-Z-@]+\s" -o --no-filename $HOME/Notes/MD -t md \| sort -u')
- Open a fresh vim instance, open a markdown file and hit
C-c C-y, you should get a popup of all the yaml tags in the notes folder,C-c C-twill offer a popup of#tagslike in iaWriter, Zettlr or Obsidian
Demo
Check out this quick gif:

Other Useful Vim Integrations for Notable
- Searching
- It is very simple to integrate a terminal search with recoll such that
you never need to leave your terminal.
- TODO Put up this script
- Notational-fzf-vim is essentially a vim front end for fzf and
ripgrep, not as powerful as
recollbut handy if you know the exact term your looking for
- It is very simple to integrate a terminal search with recoll such that
you never need to leave your terminal.
- Tags
- It's easy to pass both
#tagsandyamltags to TMSU so that you can browse them using mount- TODO Post this script up
- It's easy to pass both
Alternative Method
I initially tried this in R because I didn't actually know any JavaScript, but it was too slow, the tags took just long enough to pop up that I found it irritating and did it in JS, if you want to play around with that R-script you can add the following to your vimrc:
"" RScript to give tags to FZF
imap <expr> <C-c><C-r> fzf#vim#complete('Rscript ~/bin/printMarkdownTags/ListTags.R > /dev/null 2>&1; cat /tmp/00tags.csv')
TODO Emacs
I couldn't figure out an easy way to do this in Emacs, the best method I currently have is to open vim from emacs like this:
(defun my-open-current-file-in-vim ()
(interactive)
(async-shell-command
; (format "gvim +%d %s"
(format "~/.local/kitty.app/bin/kitty -e nvim +%d %s"
(+ (if (bolp) 1 0) (count-lines 1 (point)))
(shell-quote-argument buffer-file-name))))
(global-set-key (kbd "C-c v") 'my-open-current-file-in-vim)
If anybody knows of a better way to do this from Emacs let me know!