These are my notes on “Mastering VIM” by Ruslan Osipov. Also contains my own knowledge.
dd — delete linecc — delete line and go into INSERT mode
Movements
uppercase is for “words separated by whitespace”
e or E — move to the End of the wordw or W — move between Wordsb or B — move Back_ jump to the beginning of the line:N where N is a number line. Will move you to that line numbergi places you in INSERT mode you were last time
zz move current line the the center
s delete single character and enter INSERT mode
Buffers
:ls list buffers:bn and :bp next and previous buffer:bd delete buffer
“vim-unimpaired” makes some navigation and motions much easier
de delete from cursor position till the end of the word
Splits
:sp horizontal split:vs vertical split
Windows
Ctrl+w -> q close current windowCtrl+w -> j, k, l or h move between windowsCtrl+w -> J, K, L or H move w:indows
:wqa write and quit all windowsCtrl+w -> o close all window except current oneCtrl+w -> R flip windows placement
Tabs
:tabnew create new tabgt or gT to navigate between tabs
you can load your vim config with
:source $MYVIMRC
Text objects
delete inside smth., e.g. di( delete everyting inside matching braces (
:help text-objects
Registers
powerful multi-bucket storage for stuff you copy paste
:reg view list of registers
call register with "
interact with register “a” with "a
e.g. yank word to “a” register with "ayw
Ctrl+r -> <name of registry> paste from register in INSERT mode, e.g. paste from “a” registry with Ctrl+r -> a
gd navigate to definitiongD will look for definition from the beginning of the file
Diff
as in vim diff tool
:do move change to active window:dp push change from active windowc[ next changec] prev change
Quickfix list
usually gets filled in by results from make, or vimgrep and etc.
:copen open quickfix list:cclose or :bd close list:cnext next item in a list:cprev previous item in a list
Replacements
:s/repl/subj/flags replace “repl” on the line:%s/repl/subj/flags do the relpacement but for the whole file
Macros
a way to replay annoying bits you have to do right now
- enter macro mode by hitting
qand followed by any register, e.g. “a”, as inqa - do your actions in a repeatable way
- finish your macro by hitting
q
Play macro with @ followed by registry name. For example if you saved macro in “a” registry,
then you can replay it with @a
In order to replay last used macro, hit @@
when macro hits bottom of a file, it starts again from the top of the file. To forbid that use
set nowrapscanin your config file
macros are stored in registers, you can view created/saved macro with
:reg
Misc
:terminal or :term turns on terminal mode