Home / Only for Unix Dummies / VI Editor- Command Reference

VI Editor- Command Reference

“vi” is powerful editor which is available in Unix/Linux to edit the text files.Its an command oriented text editor. It has three modes. 1.Insert mode.2.command mode3.last line mode.Once you open a file using vi,it opens the file in command mode,which will allow you to move the cursor quickly within a file.Insert mode allows you to enter a new text and modify text in your file. Press “i”,”a” or “o” to get to insert mode. Press ‹Esc› to get back to command mode.In command mode,if you press “:” , you will reach last line mode from where you can exit from the file by saving or without saving.To force quit type “:!” and enter. 

The below commands are very useful in day to day administration.  

table.tableizer-table { border: 1px solid #CCC; font-family: ; font-size: 12px; } .tableizer-table td { padding: 4px; margin: 3px; border: 1px solid #ccc; } .tableizer-table th { background-color: #104E8B; color: #FFF; font-weight: bold; }

Inserting and Appending Text
a            Append text after the cursor
A         Appends text at the end of the line
i           Inserts text before the cursor
I           Inserts text at the beginning of the line
o          Opens a new line below the cursor
O         Opens a new line above the cursor
:r   Inserts text from another file into the current file
Key Sequence for the VI Editor
n, left arrow or backspace Left one characters
j or down arrow Down one line
k or up arrow Up one line
l, right arrow or spacebar Right one character
w           Forward one word
b           Back one word
e           To the end of the current word
$           To the end of the line
0 (zero)     To the beginning of the line
^           To the first non whitespace character on the line
Return        Down to the beginning of the next line
G           Goes to the last line of the file
1G           Goes to the first line of the file
:n           Goes to the line n
nG           Goes to the line n
Ctrl F       Pages forward one screen
Ctrl D       Scroll down one half screen
Ctrl B       Pages back one screen
Ctrl U       Scrolls up one half screen
Ctrl L       Refreshes the screen
Editing files using the VI editing commands
R                     Overwrites or replace characters to the right of the cursor
C                   Changes or overwrites characters to the end of the line
s       Substitute a string for a character at the cursor
x Deletes a character at the cursor
dw Deletes a word or part of the word to the right of the cursor
dd Dletes the line containing the cursor
D Deletes the line from the cursor to the right end of the line
:n,nd Deletes the line n through n
Using the Text Changing Commands
u Undoes the previous command
U Undoes all changes to the current line
. Repeats the previous command
Search and Replace Command
/string Searches forward for the string
?string Searches backward for the string
n Searches the next occurrence of the string
N Searches for the previous occurrence of the string
:%s/old/new/g Searches for the old string and replace it with the new string globally
Using the text copying and Text Pasting Commands
yy Yanks a copy of a line
p Puts yanked or deleted text under the line containing the cursor
P Puts yanked or deleted text before the line containing the cursor
:n,n co n Copies lines n through n and puts them after line n
:n,n m n Moves lines n through n to line n

Leave a Reply

Your email address will not be published. Required fields are marked *