Vim
I’ve been using vim for more than 10 years. Here are a list of things I usually forget from time to time that are extremely useful.
- You can use
giin normal mode to start inserting in the last position you inserted even if you have moved through the buffer. - To emulate the power of multiple cursors we can make use of the
cgntext object:- Search a word with
/or* - Use
cgnto change the word - Use dot repeat to keep going or use
gnso skip a word
- Search a word with
- Fuzzy find files with
:find *. This works on other directories as well, not only the root:find ../../../**/woah - Use
:b whateverto switch to an open buffer in vim with a whatever substring in the file name. - Tags navigation is awesome:
- Go to next tag:
C-] - Find ambiguous tag:
gC-] - Go back:
C-t
- Go to next tag:
- We don’t necessarily need completion plugins. Instead here are some commands for more powerful completion:
- Simple completion with:
C-norC-p - Restrict to current file:
C-x C-norC-x C-p - Complete only file names:
C-x C-f - Restrict to tags only:
C-x C-] - Use omnicompletion
C-x C-o - Complete definition:
C-x C-d - Complete from included file:
C-x C-i - Complete line already present in file:
C-x C-l
- Simple completion with:
- Working with the quickfix window:
- Open it with:
:copen - Open it only if there are errors, otherwise close it:
:cw - Close it:
:ccl - Go to next error:
:cn - Go to previous error:
:cp - Filter entries by a pattern with:
:Cfilteror for exclusion:Cfilter! - Execute an action on the items from the quickix:
:cdo s/foo/bar/ | update - When on the quickfix window, press
<CR>to open on the top window or<C-W><CR>to open on a new window.
- Open it with:
- Use
gfto open the file under the cursor. - You can use vim as a mergetool, if configured:
git mergetool- Move to merge conflict on the bottom window
- Keep local changes with
:diffget LOCALor:diffg LO - Keep local changes with
:diffget REMOTEor:diffg RE - Navigate conflicts with
C-w,j - After saving, commit the changes.
- Searching files is amazing with just
greporvimgrepcommands. They all fill the quickfix window.- Search local buffer:
:vimgrep /pattern/ % - Search from the current working directory:
:vimgrep /pattern/ **or:Vimgrep /pattern/ - Use an external tool for grepping (i.e.
ripgrep)::Grep /pattern/ - Use
:Ggrepif interested only in filtering by the files on the git repository.
- Search local buffer:
- Using the plugin
vim-unimpairedis very practical:- Jump between quickfix items:
]qor[q - Jump between spelling errors:
]sor[s - Add space before/after the line:
]<space>or]<space> - Jump between buffers:
]bor[b - Jump between files in the directory:
]for[f - Exchange lines up/down:
]eor[e
- Jump between quickfix items:
- Increase/decrease numbers by using
<C-A>and<C-X>respectively.