Home > Command & Utility > vi Commands

vi Commands

October 31, 2008 Posted by KP

Condensed version for my own reference, only those commands I didn’t use but will make life easier.

j or <Return> move cursor down one line
k move cursor up one line
h or <Backspace> move cursor left one character
l or <Space> move cursor right one character
0(zero) move cursor to start of current line
$ move cursor to end of current line
w move cursor to beginning of next word
b move cursor back to beginning of preceding word

:0<Return> or 1G move cursor to first line in file
:n<Return> or nG move cursor to line n
:$<Return> or G move cursor to last line in file

Screen Manipulation
^d move down (forward) one half screen
^u move up (back) one half screen
^l redraws the screen

Insert Text
o open and put text in a new line below current line
O open and put text in a new line above current line

Changing Text
r replace single character under cursor (no needed)
R replace characters, starting with current cursor position, until hit
cw change the current word with new text, starting with the character under cursor, until hit
cNw change N words beginning with character under cursor, until hit;
C change (replace) the characters in the current line, until hit
cc change (replace) the entire current line, stopping when is hit
Ncc or cNc change (replace) the next N lines, starting with the current line, stopping when is hit

Deleting Text
X delete character to left of cursor
Nx delete N characters, starting with character under cursor
dNw delete N words beginning with character under cursor;
D or d$ delete the remainder of the line, starting with current cursor position
d0 delete to beginning of line
Ndd or dNd delete N lines, beginning with the current line;
:1,.d to beginning of file
:.,$d to end of file
:1,$d whole file

Cutting and Pasting Text
yy copy (yank, cut) the current line into the buffer
Nyy or yNy copy (yank, cut) the next N lines, including the current line, into the buffer
p put (paste) the line(s) in the buffer into the text after the current line

Determining Line Numbers
:.= returns line number of current line at bottom of screen
:= returns the total number of lines at bottom of screen
^g provides the current line number, along with the total number of lines.

Excerpted from Basic vi Commands with additions from vi command summary.

Bookmark and Share


Related Posts:

Filed Under: Command & Utility

Leave a Comment









*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word




Categories

Archives

Meta