Vi - A Quick Start Guide

vi is a powerful text editor designed to increase your efficiency, even though the commands it uses are very different from Windows-based editors. Vi is an editor with "modes" of operation. The modes are :

Back to Top

Cursor Movement Commands

h - j - k - l

These commands move the cursor left - down - up - right in that order.

n|

Moves the cursor to the n'th character on the line. If the character position is invalid, vi beeps. Just "|" by itself moves the cursor to the begining of the line.

0

Moves the cursor to the begining of the line.

^

Moves the cursor to the first non blank character in the line.

$

Moves the cursor to the end of the line.

fx

(where x is any character) searches forward for the next occurance of that character from the cursor position, on the current line only.

Fx

Works the same as fx but in reverse direction.

[wW],[bB]

Move one word forward and backward respectively.

H

Moves the cursor to the top (highest) line on the screen.

M

Moves the cursor to the middle line on screen

L

Moves the cursor to the lowest line on screen

Ctrl-d

Scrolls down by half page.

Ctrl-u

Scrolls up by half page

Ctrl-f, Ctrl-b

Scroll forward and backward a page.

nG

Where "n" is a number.goes to that line number in the file. Example, 1G goes to the top of the file. 157G to the 157th line and so on.

Mx

Where "x" is any single letter, marks the current line with a marker called x. Later you can move back to that line with the command 'x. Note : To go to the exact cursor position of the mark, use ` instead of the forward single quote.

``

(This is a single quote typed twice, not a double quote) acts as a toggle and takes you to the position you were at before. So you can repeatedly switch between two positions in the file.

Back to Top

Text Modification Commands

x

Deletes the character under the cursor.

rn

(where "n" is any character) replaces the character under the cursor with the character n.

cw

(change word) puts you into input mode by replacing the word that the current cursor is on.

dw

(delete word) deletes the current word you are on.

dd

(delete line) deletes the current line you are on.

yy

yanks (copies) a line into the buffer.

p

pastes the yanked line at the position of the cursor.

Back to Top

Input Mode

i

Which means insert text before the cursor. This command puts you in Input Mode.

I

Same as above but it starts at the begining of the line.

a

Which means apend text after the cursor. This command puts you in Input Mode.

A

Same as above but starts appending at the end of the current line.

R

replace characters.Puts you in another kind of input mode (called replace mode) in which what ever you type overwrites whatever is under the cursor. This goes on till you type Esc.

o

Which means open mode. Opens a new line below the current line.

O

Opens a new line above the current line.

Back to Top

Last Line Mode Commands

:w

Saves the file in the same name that you opened it with.

:w filename

Similar to "save as" command.

:n,m w filename

This saves the contents of line numbers n to m to the given filename. Use $ instead of m to refer to the last line number without knowing what its value is.

:e filename

This is to start editing another file instead of the current one. Once you have used the e command, you can toggle back and forth between the two files by the command e#. If you have made a lot of changes (and not saved), and now want to discard all of them, type :e!.

:r filename

The read command, reads in the file and inserts its contents below the current line.

Back to Top

Vi Links

Vi Lovers HomePage

This has lots of tutorials and links to help you master vi editor with ease.

Vim

A more advanced clone of vi. It is VI IMproved.It has lots of plugins which makes this editor my favourate vi clone.

Back to Top


Yahoo Search
Results will open in a new window



Hosted by www.Geocities.ws

1