Notes From "Mastering Vim Quickly"
s- delete char under cursor and enter Insert Mode.
r- replace char under cursor.
c/hello- change until next occurrence of 'hello'
"ayyyank the entire row into register
"Ayyank to register A and append the new text to the existing contents of the register.
:registers- preview the contents of your registers.
<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
#) 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.
<C-Xincrease or decrease a number.
set ft?- find out which filetype is loaded.
Visual Block Mode
- Select a column of numbers you want to increment, then
g<C-A>will turn them into an incremented list.
: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.
g*for partial matches, like
*for exact matches.
- Search for the word under the cursor, or similar:
<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.
- Find and replace whole words only:
- Find and replace either old-word1 or old_word2:
g <C-G>- show some stats about current bugger - word count, line count, char count.
g+- 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 writes
:g/my_string/normal @a- Use the global command to execute macro
aon 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”
<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.
:g/pattern/norm @o- do the macro stored in buffer
Oon all lines that match the pattern "pattern"
<C-O>in Insert Mode will jump you into Command Mode for one command only and then put you back into Insert Mode automatically.
.dotcommand only repeats commands that changes the buffer content. It wont repeat navigation commands.