Using vi

General discussion about PLUC and Linux in Pakistan.

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
Major General
Posts: 1222
Joined: Sat Dec 31, 2005 12:29 am
Location: Lahore

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

now someone should write "Using Emacs"
Pakistan - Kashmir
Posts: 105
Joined: Wed Jan 18, 2006 4:02 pm
Yahoo Messenger: arslanone
Location: Islamabad

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

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

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

use vimtutor command to practice vi editor effectively.

Sohail Riaz, RHCE
HPC Consultant
Email :,
Web :
Posts: 54
Joined: Mon Dec 26, 2005 1:43 pm
Yahoo Messenger:

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

sohaileo wrote:use vimtutor command to practice vi editor effectively.


btw vimtutor is nice tool to learn about vim with practicle examples.
reg linux user #298274
Naib Subedar
Posts: 346
Joined: Sat Nov 30, 2002 12:22 pm
Location: Islamabad. GPS: LHR

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

Not to rain on someone's parade , but here's a neatly aligned and indented pdf-cheat-sheet of the Vi editor(4 mirrors, same file - 47 KB):

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

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

kashif wrote:Here is some extensions to kbukhari narrations
you're describing vim, not vi. if you want vi, install the nvi package (available in fedora or in ubuntu/debian).
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "" into their browsers but not ""?
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore

Return to “%s” General

Who is online

Users browsing this forum: No registered users and 1 guest