Monday, April 19, 2010

Reference to vi editor

Can check a somewhat huge reference for vi editor. Very much helps to DBA guys.

$ vi filename

Some Helpful vi Command-Line Startup Options:
Option ==> Action
vi ==> Starts editing session in memory.
vi ==> Starts session and opens the specified file.
vi * ==> Opens first file that matches the wildcard pattern. Use :n to navigate to the next matched file.
view ==> Opens file in read-only mode.
vi -R ==> Opens file in read-only mode.
vi -r ==> Recovers file and recent edits after abnormal abort from editing session (like a system crash).
vi +n ==> Opens file at specified line number n.
vi + ==> Opens file at the last line.
vi +/ ==> Opens file at first occurrence of specified string pattern.

Common Techniques to Enter vi Insert Mode:
Enter Insert Command ==> Action
i ==> Insert text in front of the cursor.
a ==> Insert text after the cursor.
I ==> Insert text at the beginning of the line.
A ==> Insert text at the end of the line.
o ==> Insert text below the current line.
O ==> Insert text above the current line.

Useful vi Exit Commands
Exit Command ==> Action
:wq ==> Save and exit.
ZZ ==> Save and exit.
:x ==> Save and exit.
:w ==> Save the current edits without exiting.
:w! ==> Override file protections and save.
:q ==> Exit the file.
:q! ==> Exit without saving.
:n ==> Edit next file.
:e! ==> Return to previously saved version.

Common Navigation Commands

Command ==> Action

j (or down arrow) ==> Move down a line.
k (or up arrow) ==> Move up a line.
h (or left arrow) ==> Move one character left.
l (or right arrow) ==> Move one character right.
Ctrl+f (or Page Down) ==> Scroll down one screen.
Ctrl+b (or Page Up) ==> Scroll up one screen.
1G ==> Go to first line in file.
G ==> Go to last line in file.
nG ==> Go to n line number.
H ==> Go to top of screen.
L ==> Go to bottom of screen.
w ==> Move one word forward.
b ==> Move one word backward.
0 ==> Go to start of line.
$ ==> Go to end of line.

Common Options for Copying, Deleting, and Pasting Text

Option ==> Action
yy ==> Yank (copy) the current line.
nyy ==> Yank (copy) n number of lines.
p ==> Put yanked line(s) below the cursor.
P ==> Put yanked line(s) above the cursor.
x ==> Delete the character that the cursor is on.
X ==> Delete the character to the left of the cursor.
dw ==> Delete the word the cursor is currently on.
dd ==> Delete current line of text.
ndd ==> Delete n lines of text
D ==> Delete to the end of the current line.

Common Options for Changing Text
Option ==> Action
r ==> Replace the character that the curser is on with the next character you type.
~ ==> Change the case of a character.
cc ==> Delete the current line and insert text.
C ==> Delete to the end of the line and insert text.
c$ ==> Delete to the end of the line and insert text.
cw ==> Delete to the end of the word and insert text.
R ==> Type over the characters in the current line.
s ==> Delete the current character and insert text.
S ==> Delete the current line and insert text.

Common Options for Text Searching

Option ==> Action
/ ==> Search forward for a string.
? ==> Search backward for a string.
n ==> Repeat the search forward.
N ==> Repeat the search backward.
f ==> Search forward for a character in the current line.
F ==> Search backward for a character in the current line.

:set number ==> Displaying Line Numbers
u ==> Undoing a Command

Thanks to GUYS behind "Linux Recipes for Oracle DBAs" for this summary.

No comments: