vim commands Flashcards
:e filename
Open filename for edition
:w
Save file
:q
Exit Vim
:q!
Quit without saving
:x
Write file (if changes has been made) and exit
:sav
filename Saves file as filename
.
Repeats the last change made in normal mode
5.
Repeats 5 times the last change made in normal mode
k or Up Arrow
move the cursor up one line
j or Down Arrow
move the cursor down one line
e
move the cursor to the end of the word
b
move the cursor to the beginning of the word
0
move the cursor to the beginning of the line
G
move the cursor to the end of the file
gg
move the cursor to the beginning of the file
L
move the cursor to the bottom of the screen
:59
move cursor to line 59. Replace 59 by the desired line number.
20|
move cursor to column 20.
%
Move cursor to matching parenthesis
[[
Jump to function start
[{
Jump to block start
y
Copy the selected text to clipboard
p
Paste clipboard contents
dd
Cut current line
yy
Copy current line
y$
Copy to end of line
D
Cut to end of line
/word
Search word from top to bottom
?word
Search word from bottom to top
*
Search the word under cursor
/\cstring
Search STRING or string - case insensitive
/jo[ha]n
Search john or joan
/< the
Search the or theater or then
/the>
Search the or breathe
/< the>
Search the
/< ¦.>
Search all words of 4 letters
/\/
Search fred but not alfred or frederick
/fred|joe
Search fred or joe
/\
Search exactly 4 digits
/^\n{3}
Find 3 empty lines
:bufdo /searchstr/
Search in all open files
bufdo %s/something/somethingelse/g
Search something in all the open buffers and replace it with somethingelse
:%s/old/new/g
Replace all occurrences of old by new in file
:%s/onward/forward/gi
Replace onward by forward - case insensitive
:%s/old/new/gc
Replace all occurrences with confirmation
:%s/^/hello/g
Replace the beginning of each line by hello
:%s/$/Harry/g
Replace the end of each line by Harry
:%s/onward/forward/gi
Replace onward by forward - case insensitive
:%s/ *$//g
Delete all white spaces
:g/string/d
Delete all lines containing string
:v/string/d
Delete all lines containing which didn’t contain string
:s/Bill/Steve/
Replace the first occurrence of Bill by Steve in current line
:s/Bill/Steve/g
Replace Bill by Steve in current line
:%s/Bill/Steve/g
Replace Bill by Steve in all the file
:%s/^M//g
Delete DOS carriage returns (^M)