Ruchiyu Tries Things

vi and vim editor commands

· Read the Korean original
AI-adapted translation. The original date and content are preserved.

Today I’d like to put together a list of basic commands for vi and vim, two of the best-known Linux text editors.

 

First, some of you might think vi and vim are the same thing, but they have different origins, 

 

so you can think of them as separate editors. On many versions of Linux today, typing vi automatically

 

opens vim. On Unix, however, where vi first appeared, these commands might not work properly,

 

or you might run into bugs.

 


◆ Command mode

▶ Moving the cursor

h Move the cursor left ←
j Move the cursor down ↓
k Move the cursor up ↑
l Move the cursor right →

 

 

▶ Moving the cursor by word

W,w Move to the start of the next word
E,e Move to the end of the word
B,b Move to the start of the word

※ The uppercase commands ignore special characters and symbols when looking for word boundaries.

 

 

 

▶ Moving the cursor within a line

0(zero) Move to the start of the line
$ Move to the end of the line

 

 

▶ Moving the cursor within the document

G Move to the end of the document
gg Move to the start of the document

 

i Enter insert mode at the current cursor position
I Enter insert mode at the very start of the line
a Move one character to the right, then enter insert mode
A Enter insert mode at the very end of the line
o Add a new line below the cursor and enter insert mode
O Add a new line above the cursor
s Delete the character under the cursor and enter insert mode
S Delete all the characters on the current line and enter insert mode
x Delete the character under the cursor
X Delete the character before the cursor
dd Delete the current line
number + dd Delete that many lines, starting with the current line
yy Copy the current line
number + yy Copy that many lines, starting with the current line
p Paste the copied text below the current line
P Paste the copied text above the current line

 

 

◆ File commands

:e [filename] Open a file
:enew Close the current window and open a blank document
:q Quit (if there are no unsaved changes)
:q! Force quit (discard any unsaved changes)
:W Save the file
:wq Save the file and quit