In this article, I am going to share a list of Linux vi commands.

Linux vi commands list :

Typically we have 8 types of vi commands, those are listed below.

  • Cursor Movement Commands
  • Scrolling Commands
  • Delete Commands
  • Yanking Commands
  • Paste Commands
  • Insert Mode Commands
  • Colon Commands and
  • Special Commands

Lets see each one in detail:

Vi Cursor Movement Commands :

Command Action
h Used to move the cursor one character left
j Used to move the cursor one character down
k Used to move the cursor one character up
l Used to move the cursor towards right direction
w Used to move the cursor to next line of first character
2w Used to move the cursor 2 words forward
nw Used to move the cursor "n" words forward
b Used to move the cursor to previous word.
nb Used to move the cursor to "n" previous words.
e Used to move the cursor to next word last character.
$ Used to move the cursor to end of the current line
^ Used to move the cursor to starting of the current line
ngg Used to move the cursor to starting line of the file.
gg Used to move the cursor to first line.
G Used to move the cursor to last line of the file.
M Used to move the cursor to middle line of the file

Vi Scrolling Commands :

Command Action
Ctrl+f Used to scroll the page forward
Ctrl+b Used to scroll the page backward
Ctrl+d Used to scroll half page forward
Ctrl+u Used to scroll half page backword

Delete Commands :

Command Action
dd Used to delete current line
ndd Used to delete n lines from current position
x Used to delete the character at present cursor position
X Used to delete previous character of the present current position
dw Used to delete a word
db Used to delete previous word
ndb Used to delete "n" previous words
d$ Used to delete characters from current cursor position to end of the line
d^ Used to delete characters from current cursor position to starting of the line

Yanking Commands :

Command Action
Y Used to yank a single character.
Y^ Used to yank present cursor position to starting of the line
Y$ Used to yank present cursor position to ending of the line
yy Used to yank the current line
nyy Used to yank the n lines from current position
ngg Used to yank from current position to first position
YG Used to yank present cursor position to last position
yw Used to yank a word
yb Used to yank previous word
nyb Used to yank "n" previous words

Paste Commands :

Command Action
p Used to paste below the cursor position
P Used to paste above the cursor position

InsertMode Commands :

Command Action
A Used to append the text at the end of line
a Used to append the text after cursor position
i Used to append a letter before the cursor position
I Used to append a letter to beginning of line
o Open a new line below the present line
O Open a new line above the present line
s Delete the present cursor position

Colon Commands :

Command Action
:w Used to save file
:q Used to Quit from file without saving
:wq Used to Quit from file with saving (Save + Quit)

Special Commands :

Command Action
U Used to undo the previous action.
T Used to join the lines
. Used to redo the previous action
~ Used to change the case of present character.(Upper to Lower and vice-versa)

Happy Learning 🙂