Using vi

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

Using vi

Post by kbukhari »

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

Others.
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
+92-345-8444420
http://sysadminsline.com
http://kashifbukhari.com
phoenix
Havaldaar
Posts: 105
Joined: Wed Jan 18, 2006 4:02 pm
Location: Islamabad
Contact:

Post by phoenix »

now someone should write "Using Emacs"
__/__/__/__/__/__/__/__/__/__/__/__/
Pakistan - Kashmir
__/__/__/__/__/__/__/__/__/__/__/__/
kashif
Naib Subedar
Posts: 305
Joined: Wed Oct 15, 2003 2:44 am
Location: Okara

Post by kashif »

Assalam 0 alaikum!!

Here is some extensions to kbukhari narrations

Searching

press

/ (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

/root/.vimrc

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

**********************************************
sohaileo
Naik
Posts: 54
Joined: Mon Dec 26, 2005 1:43 pm
Contact:

Post by sohaileo »

use vimtutor command to practice vi editor effectively.

Regards,
Sohail Riaz, RHCE
HPC Consultant
Email : sohaileo@gmail.com, riazsx@aramco.com
Web : http://www.sohailriaz.com
Kdaemon
Naib Subedar
Posts: 346
Joined: Sat Nov 30, 2002 12:22 pm
Location: Islamabad. GPS: LHR

Post by Kdaemon »

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

Regards,
btw vimtutor is nice tool to learn about vim with practicle examples.
reg linux user #298274
Aadil
Naik
Posts: 60
Joined: Fri Dec 27, 2002 10:36 pm
Contact:

Post by Aadil »

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

http://rapidshare.com/files/48625437/Vi_Editor_Cheat_Sheet.pdf.html
http://www.megaupload.com/?d=6VXGDMHY
http://upload2.net/page/download/67El291ZUytg8XR/Vi+Editor+Cheat+Sheet.pdf.html
http://www.savefile.com/files/966052
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

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 "linuxpakistan.net" into their browsers but not "google.com"?
Post Reply