Today I Learned

A Hashrocket project

Your own vim <leader> key in a pairing situation

Leader keys in Vim let you set up powerful and easy to access shortcuts for commands you use often.

For example I use <leader>vr to open my .vimrc in a split. That looks something like this:

nnoremap <leader>vr :vsp $MYVIMRC<cr>

I also use it to edit my vim bundles which are managed using the amazing vim-plug:

nnoremap <leader>vb :vsp ~/.vimrc.bundles<cr>

Finally, after making changes to both I need to source my vimrc:

nnoremap <leader>so :source $MYVIMRC<cr>

This allows for quick iteration on my vim configuration.

In a pair scenario though I cannot use my own configuration and more often than not the differences can be problematic for my muscle memory. For example at Hashrocket we use the \ key as leader. In my personal vim setup I have <space> setup as the leader key. I find it to be more ergonomic and easier to access since I can slam it with either thumb. Since there can only be one leader key you might need to add a leader alias. That can be done simply by adding this: viml nmap <space> \ Remember not to use nnoremap if you wan this to work.

Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the monthly Vim Chicago Meetup hosted at our Chicago office.