Using vi

General discussion about PLUC and Linux in Pakistan.
Major General
Posts: 1222
Joined: Sat Dec 31, 2005 12:29 am
Location: Lahore

Using vi

Postby kbukhari » Thu Jan 18, 2007 6:02 pm

The difference between vi and most other editors is it has two modes: command mode and insert mode. You start off in command mode, and usually press i to get into insert mode, where you can actually type. To get back to command mode, press escape. In some versions of vi it tells you at the bottom if you're in insert mode, otherwise you have to remember.

There's not much to say about insert mode - you just type. Here are the most common keystrokes I use in command mode:

Moving about
w forward a word
b back a word
$ end of line
0 beginning of line
G end of file
<num>G go to line num
0G beginning of file
h,j,k,l alternative cursor keys (left, down, up, right)

Cut & paste
dd cut the current line
yy copy the current line
dw delete a word
D cut from cursor until end of line
p paste after cursor
P paste before cursor

Getting into insert mode
i insert text before cursor
a append text after cursor
A append text at end of line
cw change a word
C change from cursor to end of line
s subsitute character at cursor

repeats last operation. very good with 'dd'
<num><cmd> do cmd repeated num times
r<chr> replace a character without going into insert mode
ZZ save and quit
:!<shell> runs a shell command

Points to note
If it all goes totally mad, you've probably got caps-lock on by mistake.
You can get out of the help with :q
Sometimes you paste into vi (in a x-term or putty window) and it misses part of the text. That's when you've done it in command mode - it starts doing your text as commands (which can wreak havoc) and drops into insert mode when it his an i, finally typing some of what you pasted.
Syed Kashif Ali Bukhari

Posts: 105
Joined: Wed Jan 18, 2006 4:02 pm
Location: Islamabad

Postby phoenix » Thu Jan 18, 2007 11:27 pm

Pakistan - Kashmir

Naib Subedar
Posts: 305
Joined: Wed Oct 15, 2003 2:44 am
Location: Okara

Postby kashif » Sat Jan 20, 2007 1:16 pm

Assalam 0 alaikum!!

Here is some extensions to kbukhari narrations



/ (forwared slash) in command mode then type word for searching and hit enter.if there are multiple searched words then it will move to next word by pressing n,

? Question mark also uses for searching, it searches upword.

When I used to use vi on SUSE two thing annoyed me .

1- Backspace does not delete character
2-It does not highlight keyword.

But after some probing I was able to do both these.

for first one

In vi editor under command mode press

:set backspace=2

Now backspace will rock

for 2nd one again

:set syn=on

Now it keyword will be highlighted . (^_^)

If you want to make these setting permanent then under user's home dir.
make a file.
like for root


and write both these key commands in it i.e

:set syn=on
:set backspace=2

If you are eager to find more option press
:set all

in vi.

Allah Hafiz

As-Salaatu was-Salaamu Alaika Ya Sayyidi Ya Rasool ALLAH


Posts: 54
Joined: Mon Dec 26, 2005 1:43 pm

Postby sohaileo » Wed Feb 07, 2007 2:11 pm

Sohail Riaz, RHCE
HPC Consultant
Email :,
Web :

Naib Subedar
Posts: 346
Joined: Sat Nov 30, 2002 12:22 pm
Location: Islamabad. GPS: LHR

Postby Kdaemon » Wed Feb 07, 2007 5:51 pm

Posts: 60
Joined: Fri Dec 27, 2002 10:36 pm

Postby Aadil » Mon Aug 13, 2007 4:29 am

Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore

Postby lambda » Tue Jan 22, 2008 5:10 pm

Watch out for the !
Isn't it amazing how so many people can type "" into their browsers but not ""?

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest