Movement commands in vi

Move by one character
h – Move cursor left
j – Move cursor down
k – Move cursor up
l – Move cursor right

Move by word
w or W – Move forward by word, cursor is beginning of the word
b or B – Move backward by word, cursor is beginning of the word
e or E – Move forward by word, cursor is end of the word

Move by line
0 – Move to start of line (Position 0)
$ – Move to end of line
^ – Move to start of line (exclude leading spaces)
j – Move down one line
+ – Move down one line to first character (exclude leading spaces)
– – Move up one line to first character (exclude leading spaces)
H – Move to first line on the screen
M – Move to middle line on the screen
L – Move to last line on the screen

Scroll
Ctrl-F – Scroll down by one screen
Ctrl-B – Scroll backward by one screen
Ctrl-D – Scroll down by half screen
Ctrl-U – Scroll backward by half screen
Ctrl-E – Scroll down by one line
Ctrl-Y – Scroll backward by one line

Search
/pattern + [Enter] – Search for pattern forward
?pattern + [Enter] – Search for pattern backward
n – Search for next pattern in the same direction as the last one
N – Search of next pattern in the opposite direction as the last one
/ – Search for the last pattern forward and sets direction to forward
? – Search for the last pattern backward and sets direction to backward

Search options
set ignorecase – Option sets which allows to search case insensitive
set noignorecase – Option sets which allows to search case sensitive
set nowrapscan – Search is not scrolled wrapped i.e. after reaching the end of the file it will stop searching and it will display message “Search hit BOTTOM”
set wrapscan – Search is scrolled wrapped i.e. after reaching the end of the file it will start searching for the next from top of the file and it will display message Search has hit bottom and starting from the top.

Mark current position
my – Mark current position as y
`y – Move cursor to y

Ctrl-G – Print current cursor position
nG – Move line number n
G – Move to last line in a file
1G – Move to first line in a file

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.