Vim leader key
Disclaimer: This is by no means an introduction to what the leader key in vim is. There are a lot more exhaustive resources out on the internet for that. It's more of a why and a story around how I use it everyday in my workflow.
In vim contexts, it's known as a fact that leader key is used as a prefix/namespace to the key mappings that are used very often. This achieves two things at once:
- Avoids key clashes with vim's native mappings
- Allows you to create very short mappings to, potentially, very complex actions
You can set the leader like this, which will make it the comma:
I've used this setup for quite some time, but then I started to hate it for one reason: it hides away the vim's core function for comma -- to actually jump back on to previous character occurence on the current line. I just love using this keystroke.
I cannot compromise on it.
What I like doing now, instead, is to set the leader key to the space bar. This gives the opportunity of using a key with a lot of real estate space on it, which makes it easily reachable with both of my thumbs, shall I need it.
The config I actually use:
let mapleader=" "
This makes up for a nice combo of mappings:
Launch the extraordinary CtrlP plugin, I never really liked pressing ctrl-p, in fact I disabled this mapping
nnoremap <leader>F :CtrlP .<cr>
This one's interesting. It takes the current buffer and creates a new tab with it, but keeps it around in its old place too. Quite handy to focus on a single file sometimes when you have lots of splits.
map <leader>tt :tabedit %<cr>
Hopefully this will make a brief overview of how I use the leader key and maybe I'll come up with describing more useful mappings with it.