Thursday, May 05, 2005

HowTo UNIX VI EDITOR : Some tricks and tips

1>WATS the basic difference to go to the command mode using “o”,”O”,”i” or “a”?
U r in CM and if u use “I” to switch to IM then where the cursor was before the words .in case of “o” it will start appending in the line below the cursor where it was and in case of “a” it will start appending just after the cursor position.”O” will start appending in the line above the cursor where it was
2>How to move cursor inside VI?
· alt+k -will take up
· alt+j-will go down
· alt+h- left
· alt+l- right
· alt+w-advance by one word and
· alt+b backtracks by one word at a time
· and if u at the midst of a longgggg word then alt +e to go to the end of that longgggggg word( for IM and CM)
· alt+x to remove the char under the cursor….mode will change to CM……..( IM)
· CM:alt+0 start of the line
3>Is there any undo in vi?
Yes,while in IM and u made any mistake u can use alt+u for undoing. But it will undo the whole work. Not the last word.
4> As we use cntrl+f in MSWORD to find any particular word.is there something like that in vi?
Yes,just go to CM. And then /, keep on pressing “n” to see the next occurrences of that word.

i am here
where are you?
is the any options there
any guy will come
and then any boy will leave
~
~
~
~
:/any

5>And then if I want to replace a particular word by any particular word then….?
Hmm…then use this command from CM …..( this will change that ‘any” to “ANY”)
i am here
where are you?
is the ANY options there
ANY guy will come
and then ANY boy will leave
~
~
~
~
~
:%s/any/ANY


6>And if I want to comment out all lines in my shell script then….?
%s/^/#/g

Labels:

1 Comments:

Anonymous Anonymous said...

You can copy out line sections of a text file, say you have a text file of 10000 lines and you want to copy from line 1255 - 1673.

1) vi the file.
2) shift:1255,1673w!/tmp/xxx # will copy lines from 250 to 500 and write to /tmp/xxx

enj p.ho

12:04 PM  

Post a Comment

<< Home