Linux Mall - The Linux SuperStore!
Linux books, Linux CDs, Linux toys, you name it, they have it!

W W W . L I N U X D O T . O R G

Newbie's Linux Manual
Vi Survival Guide
] [ Download*] [ Previous] [ Next] Home] [ Contents] [ Download*] [ Previous] [ Next] Homepage| The Last 5 Days| The Daily Linux News| The Linux Bits| Newbie's Linux Manual
The Best Linux Sites| Linux Book Reviews| A Windows Vendetta?
Diary of a Linux Newbie| Diary of an Open Source Newbie
The Linux Forum| Just For Fun Amazon - The World's Biggest Bookstore!
4.7 million books, CDs, videos, and DVDs available to buy! Webmaster| Manual's Copyright Terms
[
* 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:

  1. vi
    Open Vi with a blank unnamed document.
  2. vi filename
    Either begin editing a blank named document or open the file for editing.

Vi has 3 modes:

  1. Command Mode: Where the majority of the trickery goes on.
  2. Insert Mode: Where the majority of the typing occurs.
  3. Replace Mode: Like Insert mode, only text is overwritten.

Vi begins in Command Mode.

  • Press i from Command Mode to enter Insert Mode.
  • Press Ctrl+r from Command Mode to enter Replace Mode.
  • In either of these modes, press Esc to return to 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 the one you're editing of course).

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.
x or [Del] Delete 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 Next occurence (in either direction).
N 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.
[
* In Linux enter: unzip nlm.zip
© MM Linuxdot.org |