Basic commands for the Linux vi Editor

From SynologyWiki

(Redirected from Linux VI Editor)
Jump to: navigation, search

The Linux VI Editor is a text based editor used Linux, useful for editing configuration files or creating plain text documents.

vi is started by simply entering "vi" (it is case sensitive) at the linux prompt, and once started is exited using ESC:q! to abandon changes or SHIFT+ZZ (case sensitve) to save changes. If you want to edit (or create) a specific file use the command "vi /path_to_file/name_of_file". "path_to_file" must already exist as vi will not make any required directories.

Command Description
iinsert mode, (ESC to exit insert mode) allows text to be entered on the screen
aAppend to right mode
/wordMove to the occurrence of "word"
nLocate the next occurrence
wAdvance to the next word
eAdvance to the next end of a word
bMove to the previous word
3bMove backward 3 words
yyCopy line (then move cursor and use p to paste after current cursor line)
dddelete line
3dddelete 3 lines
DDelete remainder of a line
dwDelete word
xDelete character
oOpen space for new line below the cursor line
OOpen a line above the cursor
CTRL-wMove back a word in append mode
uUndo last
UUndo all changes to current line
.In command mode, repeat the last text changing the command on the current line
:w newfilename save the file to newfilename from the command mode
:wq save and quit
:q!quit without saving
rreplace then typa a character ot be replaced with r then return to break up a line
Jjoin 2 lines
s substitute (sentence) typed text over a character, ESC when done
cwchange word
c change part of a line from the cursor to the end of the line
cc substitute new text for aline, ESC when done
hmove the cursor back one space
Hmove the cursor to the highest line on the screen
Lmove the cursor to the lowest line on the screen
Mposition the cursor at the midpoint on the screen
G last line in the file
0 (zero) Move the cursor to the beginning of the line it is on
view filename Open a file for viewing only
set number Turn on line numbers
set nonumber Turn off line numbers
Options
autoindent(ai ctrl-d to move to the left
showmatchmatch brackets and parenthesis
tabstop=4
wrapmargine(wm)when line is wrapped (80-value)
:2 copy 4Place a copy of line 2 after line 4.
:1,4 copy 7 (lines 1-4)
:nAccess the next file for editing
Personal tools