Skip to content

Latest commit

 

History

History
98 lines (74 loc) · 3.73 KB

Auto-Complete-Tags.md

File metadata and controls

98 lines (74 loc) · 3.73 KB

Auto Complete Tags in Vim

Home

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 #tags to [TMSU after exams and put a link here.

This is really written with Linux in mind.

Usage

  1. Download the printMarkdownTags folder to ~/bin/
    1. Alternatively download it to ~/DotFiles/Scripts/bin and then perform stow -S -t $HOME ~/DotFiles/Scripts
  2. Install FZF.Vim
  3. If youre Notes are in ~/Notes/MD/notes then 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')
  1. 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-t will offer a popup of #tags like 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 recoll but handy if you know the exact term your looking for
  • Tags
    • It's easy to pass both #tags and yaml tags to TMSU so that you can browse them using mount
      • TODO Post this script up

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!