Linux Unix help !!

"Give respect to Time, One day at right Time, Time will respect You"

Sunday, November 28, 2010

Power of vi editor Linux

Power of vi Editor
=========
# vim /home/shirish/myscripts/scratcher.sh <-- colorfull look
# vi  /home/shirish/myscripts/scratcher.sh  <-- simple
Moving through the text is usually possible with the arrow keys. If not, try:

h -> move Left
l  -> move Right
k -> move up
j -> move down

shift+H : top of file  (or :1 similarly you can go to any line by line number(n) :n)
shift+G : end of file (or :$)

dd       --> delete current line
5+dd   -> delete 5 line from current line (similarly n line)
5+dw   -> delete 5 words from current word
x         -> delete single character from current position
cc        -->cut all current line  content & leave the editor in insert mode
C         --> delete all words from current position to end of line.
s         -->cur the current character and leave te curser in insert mode

yy       -->copy line
n+yy   --> copy n lines
pp       -->paste copied line etc..
n+pp   -->paste n times

Insert Mode:
1> i   or I (cpas i)
2> Insert button
3> a (+move curser to 1 position right)
4> A (+ move the curser at end of line)
5> o  (+ a blank line below current)
6> O (+ a blank line above current)

Command mode:  ESC button

:w   -> Save
ESC+z+z --> Save & exit
:wq  -> Save & Exit
:q    -> Exit
:q!   -> Exit without Save
:w file2 will save the text to file2.
:wq! overrides read-only permission
/find  -->Search string "find"  use "n" to search new location
? find --> same as above but search in opposite dir
:1, $s/shirish/shukla/g  -->replace shirish by shukla throught file

undo & redo:
esc+u --> undo
ctl+r   --> redo
esc .  --> repeate the previous change

Bookmark

step 1> Go to the required word (type ESC+ma) you can use any lowercase  a - z, A - Z, [  ect,..   note that a & A store diff bookmarks etc..
step  2>To go to bookmarked location (type ESC+ `+a  ) note ` is above TAB button, similarly you can give various bookmarkes
* You can go to yu last edited line by -->  ESC+`+ .

:marks   --> Will show  your bookmarks in current file.

Quick Summary of Vim Bookmark Commands

    * ma –> Creates a bookmark called a
    * `a   –> Jump to the exact location (line and column) of the bookmark a
    * ‘a   –> Jump to the beginning of the line of the bookmark a
    * :marks –> Display all the bookmarks
    * :marks a –> Display the details of the bookmark with name a
      `. –> Jump to the exact location (line and column) where the last change was performed
    * ‘. –> Jump to the beginning of the line where the last change was performed

Advanced:

K --> Go to the man page of the word currently under the curser.

No comments:

Post a Comment

Write Here .. your comments are always wellcome ..but no spam please !!

Followers

Pls LIKE my Story !!!