Vim Tip #1

I. Space is your Leader

Leader is an awesome idea. It allows for executing actions by key sequences instead of key combinations. Because I'm using it, I rarely need to press Ctrl-something combo to make things work.

For long time I used , as my Leader key. Then, I realized I can map it to the most prominent key on my keyboard. Space.

let mapleader = "\<Space>"

This turned my Vim life upside down. Now I can press Leader with both of my thumbs, and my fingers are always on home row. Leader became so easy to use I began to notoriously use it in various keybindings.

II. Map your most frequent actions to Leader

I identified the actions that consumed most of my time while working in Vim. I mapped them using Leader key. Among others I decided to:

Type <Space>o to open a new file:

nnoremap <Leader>o :CtrlP<CR>

Type <Space>w to save file (a lot faster than :w<Enter>):

nnoremap <Leader>w :w<CR>

Copy & paste to system clipboard with <Space>p and <Space>y:

vmap <Leader>y "+y
vmap <Leader>d "+d
nmap <Leader>p "+p
nmap <Leader>P "+P
vmap <Leader>p "+p
vmap <Leader>P "+P

Enter visual line mode with <Space><Space>:

nmap <Leader><Leader> V

I encourage you to identify your most frequent actions, and map them.

III. Use region expanding

I use terryma/vim-expand-region with following mapping:

vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)

It allows me to:

It seems like vvv is slower than vp but in practice I don’t need to think beforehand what to select, and what key combination to use.

This way v replaces viw, vaw, vi", va", vi(, va(, vi[, va[, vi{, va{, vip, vap, vit, vat, ... you get the idea.