← Back to blogVIM: quick look up
Basic Editing
x to delete the current word where cursor is at
A to append, it doesn't matter which line
dw to delete a word
d$ to delete everything from there
Movement
2w moves the cursor two words forward
3e moves the cursor to the end of 3rd word
e to move cursor word by word
Deletion
d3w deletes 3 words from current cursor
dd to delete a whole line (it also puts it in the register which u can use to rearrange line by using p later)
Replace
rx to replace the word ur cursor is on
R to replace more than one word
Change
c [number] motion to change and get into insert mode
Line Navigation
ctrl g to check current line number
gg to end of file
G to start of file
number g to go to that line
Search
/[word] to search in forward direction ?[word] in reverse
- press
n to loop through, N in reverse
% to find matching closing parenthesis
Substitution
:s/oldword/newword replaces the old word with new word in the current line of cursor
- adding
g to the above command in end, will substitute globally in that line
:#,#s/old/new/g replaces in range which is defined in #
:#,#s/old/new/gc replaces in range which is defined in # with a confirmation prompt
External Commands
:! ! after this any external command, then u don't have to leave vim
Opening Lines
o to open a line below the cursor
O to open a line above
a to append a word to end of word
Yank (Copy/Paste)
y to yank (copy) after entering into visual mode and then j$ to end of next line and pressing p to put the copied text