Low Orbit Flux Logo 2 F

VIM Cheat Sheet

Pay attention to uppercase vs lowercase characters in commands.

vi filename launch vi, open/create file
vi -R filename launch vi, open file in read only mode
view filename open file in read only mode

Basic Commands

i Insert text before cursor
I Insert text at beginning of line
a Insert text after cursor
A Insert text at end of line
o Create new line below and change to insert mode
O Create new line above and change to insert mode
r Replace single character with single character
R Replace text from cursor going right
s Replace character with multiple characters
S Replace entire line

Deleting

X Delete character before cursor ( like backspace )
x Delete character at cursor ( like delete button )
dw Deletes from cursor to next word
d^ Deletes from cursor to the beginning of the line
d$ Deletes from cursor to the end of the line
dd Deletes the line the cursor is on

Copy and Paste

yy Yank - copy current line
5yy Yank - copy current line and 5 lines below
p Put - paste below current line
P Put - paste above current line

Registers

“ry Yank/copy from register ‘r’
“rp Put/paste from register ‘r’
Ctrl-r r Paste from register ‘r’ in insert/command mode
:reg Show all registers
:reg a b c Show registers a, b, and c

Deleted and yanked ….

Copying and Pasting

Moving

k Move up ( same as arrow key )
j Move Down ( same as arrow key )
h Moves left ( same as arrow key )
l Moves right ( same as arrow key )
0 or | Move to beginning of line
$ Move to end of line
W or w Move to next word
B or b Move to previous word
( Move to beginning of current sentence
) Move to beginning of next sentence
H Move to top of screen
9H Moves to 9th line from the top of the screen
M Move to middle of screen
L Move to bottom of screen
9L Moves to 9th line from the bottom of the screen
:37 go to line 37

More Moving

CTRL+d Move forward 1/2 screen
CTRL+f Move forward one full screen
CTRL+u Move backward 1/2 screen
CTRL+b Move backward one full screen
CTRL+e Move screen up one line
CTRL+y Move screen down one line
CTRL+u Move screen up 1/2 page
CTRL+d Move screen down 1/2 page
CTRL+b Move screen up one page
CTRL+f Move screen down one page
CTRL+I Redraw screen

Quit, Save, and More

q Quit
q! Quit without saving changes ( discard changes )
r fileName Read data from file called fileName
wq Write and quit (save and exit)
w fileName Write to file called fileName (save as)
w! fileName Overwrite to file called fileName (save as forcefully)
!cmd Runs shell commands and returns to Command mode

Search and Replace

/test search for string “test”
n find next match after search
:s/string search
:s/pattern/replace/ search and replace first match
:%s/pattern/replace/ search and replace all matches

Macros

References