Page 1 of 1

Using vi

Posted: Thu Jan 18, 2007 6:02 pm
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.

Posted: Thu Jan 18, 2007 11:27 pm
by phoenix
now someone should write "Using Emacs"

Posted: Sat Jan 20, 2007 1:16 pm
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

Posted: Wed Feb 07, 2007 2:11 pm
by sohaileo
use vimtutor command to practice vi editor effectively.

Regards,

Posted: Wed Feb 07, 2007 5:51 pm
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.

Posted: Mon Aug 13, 2007 4:29 am
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

Posted: Tue Jan 22, 2008 5:10 pm
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).