Thursday, October 17, 2013

Notes VI

 List of Commands for vi - An Unix Editor

Complete Documentation
Undo Command
Screen Commands
Cursor Positioning Commands
Search Commands
Text Insertion Commands
Text Deletion Commands
Changing Text
Search and Replace
Cutting and Pasting Text
File Commands



Complete Documentation
The vi editor is a common editor for unix systems in that it makes use of a regular keyboard with an escape key. On the DECstation, the escape key is the F11 key. It therefore works on all unix computers. Complete documentation is available by typing

man vi  at the unix prompt.


Undo Command
u                    undo the last command.

Screen Commands
CTL/l Reprints current screen.
CTL/Y Exposes one more line at top of screen.
CTL/E Exposes one more line at bottom of screen.
CTL/F Pages forward one screen.
CTL/B Pages back one screen.
CTL/D Pages down half screen.
CTL/U Pages up half screen.
H     Go to first line on screen
M     Go to middle line on screen
L     Go to last line on screen
nH    Go to line n beneath top of screen
nL    Go to line n above bottom of screen
nG    Go to line n
:n    Go to line n


Cursor Positioning Commands
j      Moves cursor down one line, same column.
k      Moves cursor up one line, same column.
h      Moves cursor back one character.
l      Moves cursor forward one character.
RET    Moves cursor to beginning of next line.

0      Moves cursor to beginning of current line.
^      Moves cursor to beginning of first non-blank character of current line.
$      Moves cursor to end of current line.
+      Moves to next line, first non blank character
-      Moves to previous line, first non blank character
SPACE  Moves cursor forward one character.
nG     Moves cursor to beginning of line n. Default is last line of file.
0      Moves the cursor to the first character of the line.
:n     Moves cursor to beginning of line n.
b      Moves the cursor backward to the beginning of this or previous word.
B      Moves the cursor backward to the beginning of this or previous word, ignoring symbols.
e      Moves cursor to end of this or next word.
w      Moves cursor to beginning of this or next word.
E      Moves cursor to end of this or next word, ignore any symbols.
W      Moves cursor to beginning of this or next word, ignore any symbols.
(      Moves to beginning of current or previous sentence
)      Moves to end of current or next sentence
{      Moves to beginning of current or previous paragraph
}      Moves to end of current or next paragraph

Search Commands
/pattern  Moves cursor forward to next occurrence of pattern.
?pattern  Moves cursor backward to next occurrence of pattern.
/, n      Move to next search
?, N      Move to previous search
.         Search wildcard - any single character
*         Search wildcard - zero or more characters
^         Search wildcard - beginning of line
$         Search wildcard - end of line
[...]     Search wildcard - any character in bracket, [xyz] means x or y or z
[..-..]   Search wildcard - any character in range, [a-z] means anything from a to z


Text Insertion Commands
a    Appends text after cursor. Terminated by escape key.
A    Appends text at the end of the line. Terminated the escape key.
i    Inserts text before cursor. Terminated by the escape key.
I    Inserts text at the beginning of the line. Terminated by the escape key.
o    Opens new line below the current line for text insertion. Terminated by the escape key.
O    Opens new line above the current line for text insertion. Terminated by the escape key.
DEL  Overwrites last character during text insertion.
ESC  Stops text insertion. The escape key on the DECstations is the F11 key.

Text Deletion Commands
x     Deletes current character.
X     Delete character before cursor.
6x    Delete next 6 characters
4dd   Delete the next 4 lines
dd    Deletes current line.
dw    Deletes the current word.
d)    Deletes the rest of the current sentence.
d}    Deletes the rest of the current paragraph.
D, d$ Deletes from cursor to end of line.
d0    Deletes from cursor to beginning of line
3dw   Deletes next 3 words
3dl   Delete next 3 letters
P     Puts back text from the previous delete.

Changing Text
cw          Changes characters of current word until stopped with escape key.
c$          Changes text up to the end of the line.
C, cc       Changes remaining text on current line until stopped by pressing the escape key.
c^          Change text to beginning of line
c)          Change text to beginning of sentence  
c}          Change text to beginning of paragraph
3cw         Change next 3 words
~           Changes case of current character.
xp          Transposes (swap) current and following characters.
J           Joins current line with next line.
s           Deletes the current character and goes into the insertion mode.
rx          Replaces current character with x.
R           Replaces the following characters until terminated with the escape key.


Search and Replace
:s/old/new          Replaces old with new
:s/old/new/g        Replaces old with new all occurrances
:s/old/new/c        Replaces old with new - need confirmation
:11,l2 s/old/new    Replaces old with new, within range of line l1 and l2





Copy(yank) and Paste Commands
yy      Copy line to buffer. Does not delete the line from its current position.
yw      Copy (to buffer) to the end of word
y0      Copy from the beginning of line
y$, Y   Copy to the end of line
y)      Copy to the end of sentence
y}      Copy to the end of paragraph
p       Places buffer after the current position of the cursor.
P       Places buffer before the current position of the cursor.


File Commands
vi filename     where filename is the name of the file to be edited.
vi -rfilename   recover file in case of crash
vi +/blah file  open file "file" at the point in the file containing text "blah"
:R file         Inserts the file filename where the cursor was before the ``:'' was typed.
:w file         Save current file as a new file with name "file"
:l1,l2w file    Save from line 11 to line l2 in file called "file"
:.,$w file      Save from current line "." to last line "$" of file
ZZ              Exits vi and saves changes.
:wq             Writes changes to current file and quits edit session.
:q!             Quits edit session (no changes made).
:e              reverts back to last saved mode.

No comments: