Useful Vi Editor Commands (Visual Editor)

Posted by at 11 February, at 11 : 35 AM Print

The vi editor also named as Visual Editor is one of the oldest screen-based editor and older version of vim editor used by many Unix/Linux users. It can be used from any unix based terminal interfacing. Since, the vi editor is not as a WYSIWYG, a user doesn’t have formatting capabilities such as creating paragraphs, changing fonts, line centering, etc…

Here, in this article, I have mentioned only those vi editor commands that are standard and most useful. It states, Starting vi, moving around with vi commands, editing files with vi editing commands, and colon “:” commands:

Opening a file using vi editor:

Simply enter the following command at the terminal command line to open single or multiple files:

vi myfileone myfiletwo

where myfileone and myfiletwo are the names of the files which you want to open.

Moving around with the vi editor commands:

Moving around is one of the challenging tasks for beginners in vi editor. In order to do so, place the vi editor in command mode simply by pressing the “Esc” key. Following are the commands that can move the cursor in vi editor.

Commands Actions
h or ← Moves the cursor to left
l or → Moves the cursor to right
j or Moves the cursor down
k or Moves the cursor up
^F or PageDown Moves screen one page down
^B or PageUp Moves screen one page up
^U Moves screen half a page up.
^D Moves screen half a page down
^E Moves the screen one line down
^Y Moves the screen one line up
+ Sends to the beginning of the next line
- Sends to the beginning of the previous line
0 (zero) Sends to the beginning of the current line
$ Sends to the end of the current line
} Sends to the next blank line
{ Sends to the previous blank line
[[ Sends to the beginning of the file
]] Sends to the end of the file
Switch you between beginning of file and current line
b Sends punctuation mark or one word back
B Sends one word back , including punctuation marks
e Sends to the end of the next word or punctuation mark
E Goes to the end of the next word, including punctuation marks
gg Goes to the top of the file
G Goes to the end of the file
^H Goes one character back, including newlines
H Goes to the top of the current page
^P Goes one line up
L Goes to the bottom of the current page
w Goes to the beginning of the next word or punctuation mark
W Goes to the beginning of the next word, including punctuation marks
^Z Suspends the vi; You can use the “fg” command to resume
ZZ Save the file and exit.

Editing files using vi editor commands:

To edit a file in vi editor, simply place the editor into a command mode. In order to edit a file in vi, place the editor into command mode.

back-space Removes the character before the cursor
del Removes the character mentioned under the cursor
i Inserts text under the cursor
I Inserts text under the cursor starting from the beginning of the current line
a Inserts text starting after current character
A Inserts text starting at the end of the line after the last character
cc Removes the whole line and moves into insert mode
cw Removes the current word and moves into insert mode.
C Deletes to the end of line and moves to insert mode.
Y Yank, copy current line to buffer
dd Removes the current line
dw Removes the current word
D Removes current line (but leave the newline)
J Joins the next line with the current line
o Inserts after the current line
O Inserts before the current line
p Pastes the lines in the buffer (from Y, dd, or x) after the current line
P Pastes the lines in the buffer before the current line
rc Overwrites with the character c, or replaces the current character
R Change to overwrite mode
s Removes the current character and moves into insert mode
S Removes the current line and moves into insert mode
u Undo the last activity
U Switch you between undoing and redoing the last edit
v Visual: starts the selection for a “d” (delete) or “Y” (yank). Simply move in the direction using movement keys after typing “v” to see the selection
V Visual line: selects the current line for deletion or Yank
x Removes the character under the cursor
X Removes the character after the cursor
~ Capitalize the current character
== Unindents the current line by typing the equal sign two times
. Repeats the last command
F1 Shows online help

Using colon “:” vi commands: 

:w Writes to the file; If file name is not given on the command line, it will complain
:w file-name Saves the file to specified filename
:q Quit. In vim editor, also exits from help.
:q! Quits without saving.
:wq Writes to the file and quit (same as “ZZ” command)

cPanel Web Hosting UK

Be Sociable, Share!

Mac Wilson

Mac Wilson is a technology writer and a Sales and Marketing Executive at eUKhost Ltd. He loves to write about latest technologies and trends just like cloud computing which are changing the way people do business.

To know more about our services and solutions, kindly visit eUKhost's Official Website.

Web Hosting Articles ,

Related Posts

Post Your Comment

Twitter Facebook Google+ LinkedIn