Notes From "Mastering Vim Quickly"
Contents:
Verbs
s- delete char under cursor and enter Insert Mode.r- replace char under cursor.c/hello- change until next occurrence of 'hello'
Registers
"ayyyank the entire row into registera."Ayyank to register A and append the new text to the existing contents of the register.:registers- preview the contents of your registers.
Insert Mode
<C-W>- delete back one word.<C-U>- delete back to the start of the line or start of current insert.cgn- if you are searching for a word (either by using/or*or#) and you want to change each instance of the search result, use<verb>gnto change or delete and then go to the next result. This will let you use the.dotoperator to repeat both the steps (moving and changing).<C-R> 0- paste.<C-R><C-P>0if there are new-line chars causing trouble.
Normal Mode
<C-A>or<C-Xincrease or decrease a number.
Command Mode
set ft?- find out which filetype is loaded.
Visual Block Mode <C-V>
- Select a column of numbers you want to increment, then
g<C-A>will turn them into an incremented list.
Ranges
:put =range(1,10)- insert a list of ascending numbers.:for i in range(1,100) | put ='192.168.1.'.i | endfor- use a loop to generate a long list.
Searching
g#org*for partial matches, like#or*for exact matches.- Search for the word under the cursor, or similar:
- Press
/. <C-R><C-W>- this will copy and paste the word under the cursor into the search box. Edit it as necessary.- After you've done your search,
<C-o>to jump back to where your cursor was before.
- Press
- Find and replace whole words only:
:s/<old_word\>/new/g - Find and replace either old-word1 or old_word2:
:s/(old_word1\|old_word2\)/new/g g <C-G>- show some stats about current bugger - word count, line count, char count.
Undo
g-andg+- undo branches.- Under changes within a period of time:
:earlier 2d- undo changes in the last 2 days:later 5m- redo all changes in the last 5 minutes:earlier 3f- undo all changes in the last three buffer writessseconds,mminutes,hhours,ddays,fsaves
:g/my_string/normal @a- Use the global command to execute macroaon all lines of the current buffer containing string 'my_string':g/good/s/bad/ugly/g- For every line containing “good” substitute all “bad” with “ugly”
Splits
<C-W> r- rotate the splits from left to right but only if they are split vertically.<C-W> R- rotate the splits from right to left.<C-W> H- move the current split to the far left and make it full height.<C-W> J- move the current split to the bottom of the screen and use the full width.:only- close all splits except the current split.
Macros
:g/pattern/norm @o- do the macro stored in bufferOon all lines that match the pattern "pattern"
Other
<C-O>in Insert Mode will jump you into Command Mode for one command only and then put you back into Insert Mode automatically.- The
.dotcommand only repeats commands that changes the buffer content. It wont repeat navigation commands.