Published: 18.03.2021 | Edited: 18.03.2021 | Tags: 100daystooffload,vim

Using mnemonics outside of my vim

Vim. Many swear by it, many hate it. It has a steep learning curve, but once I got proficient, I really saw the benefits. As with everything muscle memory related, it is now even harder for me to use a normal writing mode, for instance on web sites. :wq

In vim I build a memory map of key presses needed to do the given task. Some default key sequences are based on mnemonics. Mnemonics help remember larger amounts of information based on short patterns. One of the many common key sequences in vim is diw, which would delete inner word. Since vim is very configurable, it's users are encouraged to build their own key sequences for the task they face repeatedly.

What I do when creating a new combination is to also try to use mnemonics as much as possible, usually by using the starting letters of the words describing the task. Most default vim key sequences start with a verb. I agree with this approach, because it feels more natural, examples:

delete inner word, goto type definition, list commands

There are exceptions of course. Sometimes, usually when the key sequences I integrate into vim is centered around another external command, the sequence starts with a noun, and there are also commands that have no verbs in them:

git chunk undo, npm run dev, quick fix

I have discovered a nice integration based on the principles above. It is centered around the FuZzy Finder - fzf and it's vim plugin, fzf-vim. When installed in vim, I insert this line into my .vimrc file:

nmap <silent> gf :<C-u>Files<CR>

Disclaimer: I am not a vimscript specialist, so there might be better approaches. Use only when you know what you are doing.

What the vimscript line above does is that it opens a dialog in vim, where I can choose file in the current directory tree by matching it's name fuzzily (meaning not exactly). For me, it is one of the more effective ways of navigating the project.

Now what I do next is to insert this line in my .zshrc file:

alias gf='nvim `fzf -i`'

Together, these two lines create a mnemonic gf that I remember as goto file, that uses fuzzy filename matching and is ingrained in my muscle memory. No matter if I am in the terminal or already inside vim, typing gf opens the file I need very quickly. A very powerful combo!

This is a 8th post of #100daystooffload.