![]() |
![]() |
Newbie's Linux Manual | |
Vi Survival Guide | |
by Laurence Hunter | |
[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ] | |
* In Linux enter: unzip nlm.zip | |
Essential Learning | |
User-friendly it isn't, but it's guaranteed to feature on every distibution of Linux and Unix, it's the default editor for the popular e-mail client Mutt, and if you ever do a minimum install of Linux, it and Ed is all there is. Trust me, you'll opt for Vi over Ed. There are two ways to start Vi:
Vi has 3 modes:
Vi begins in Command Mode.
| |
Insert/Replace Mode | |
Type away as you would in any other text editor. The only noticeable difference is that that's all you can do, and you can't delete a line. | |
Command Mode | |
The following displays the most useful commands you can enter in Command Mode to perform a wide assortment of tasks. Note that all commands are case-sensitive. | |
Saving | |
:w | Write an already named file to disk. |
:w filename | Required to save an unnamed document. Also to save a document with a new filename. |
:w! filename | Required to overwrite an existing file (other than document's file). |
Quitting | |
:q | Quit Vi, but only if document has not been modified. |
:q! | Quit Vi without saving document. |
:wq | Save document and quit Vi. |
Opening | |
:e filename | Either open a file for editing, or begin a new, named document. |
Everything that follows, happens at the cursor. Current line means, "the line the cursor's on". Keys are indicated inside square brackets. n represents a number determined by you. | |
Moving | |
n[cursor key] | Move cursor that amount in that direction e.g. 19[Down] would move cursor down 19 lines.. |
[PageUp] | Move up 1 page. Precede with a number to move up that many pages. |
[PageDn] | Move down 1 page. Precede with a number to move down that many pages. |
gg | Move to start of document. |
G | Move to end of document. |
:n | Move to start of a specific line. |
b | Move to beginning of current word, or to previous punctuation mark. |
nb | Perform b, n times. |
e | Move to end of current word, or to next punctuation mark. |
ne | Perform e, n times. |
0 (zero) | Move to start of current line. |
$ | Move to end of current line. |
) | Move to start of next line. |
( | Move to start of previous line. |
Undo & Redo (Both infinite) | |
u | Undo. |
[Ctrl]r | Redo. |
Deleting | |
dd | Delete the current line. |
ndd | Delete the current line + the n-1 lines below. |
[Del] or xDelete current character. | |
Copying (Yanking) & Pasting | |
yy or Y | Yank (copy) current line. |
nyy or nY | Yank (copy) current line and n-1 lines below. |
p | Insert yanked text between current line and next line. |
np | Insert yanked text between current line and next line, n times. |
P | Insert yanked text between current line and previous line. |
nP | Insert yanked text between current line and previous line, n times. |
Searching | |
/text | Find the next instance of text from the cursor, where text is the string you're looking for. If nothing is found then Vi will wrap from the start of the document, back to the cursor. |
?text | The same as above but search direction is reversed. |
n | Find next occurence. |
N | Find previous occurence. |
Replacing | |
:s/old/new | Replace next instance of old, with new. (No document wrap occurs.) |
:%s/old/new/g | Replace next instance of old, with new, throughout entire document. |
rcharacter | Replace current character with new character. |
nrcharacter | Replace current character + the next n-1 characters with character. |
Miscellaneous | |
J | Join the line below, with the current line. |
:help | Display online help. |
[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ] | |
* In Linux enter: unzip nlm.zip | |
The Newbie's Linux Manual is reproduced on LinuxMall.com by permission. The Newbie's Linux Manual is written and maintained by Laurence Hunter. You can find much more of Laurence's work at his site: www.Linuxdot.org |
© 1999 Linuxdot.org | Manual's Copyright Terms