VIM editor commands and examples – Linux

Spread the love




















VIM An Advanced Text Editor:-


=> Newer Virsion of VI, the standard Unix text editor


=> gvim :         Graphical Version of vim




ADVANTAGES OF VIM :-


SPEED            : Do more with fewer keystrokes
Simplicity        : No dependence on mouse/GUI
Availability      : Included with most Unix-like OSes


DISADVANTAGES :-
Difficulty         : Stteper learning curve than simpler editors


Three Main Mode :-
Command Mode     : Move cursor, cut/paste text, change mode
Insert Mode            : Modify text
Ex Mode                 : Save, quit, etc


Esc‘ key is used to exits current mode.


EscEsc‘ always returns to command mode.




=> vim abc.txt        : can edit the text file if existing or not
=> vim /etc/passwd
=> vim /tmp/file




INSERT MODE :-


       : begins insert end of line
    : Append to end of line
     : Insert at beginning of line
     (small)    o    insert new a line (below of current line)
     (caps)    O    insert new line ( above of current line )




EX MODE with ( : ) :-


    :w       : writes (saves) the file to disk
    :wq     : writes and quits
    :q!      : quits, even if changes are lost ( do not save )




COMMAND MODE ( Default Mode ) :-


    Right Arrow         ( -> )     moves right one character
    5, Right Arrow     ( 5 ->) moves right five (5) character


    h    move cursor to left
    j     move cursor to down
    k    move cursor to up
        move cursor to right


    w    move cursor by word ( forward )
      move cursor by word ( backward )   
    (     move cursor by sentense ( forward )
    )     move cursor by sentense ( backward )


    /xyz    search the ‘xyz’ into the file  (n,N) use for next,prev






This command will run in file — {vi /xyz (filename)}
   
    :%s/macho/dud/gi    search & replace all macho to dud (gi- globely)
    :1,5s/sam/sandy/      search & replace from line-1 to line-5


    :5        move cursor to line no. 5
    :G       move cursor to the end of document
    dd       to delete current line
    4dd     to delete four line
    yy       to copy the line
    5yy     to copy five line
    p/P      paste the copied line or text 
     u         undo 
     ctrl r    redo

See also  Linux File and Directory Permissions Guide

    :set number    set the line number in file
    :set nonu    remove the line number in file










Thanks,
Vishal Vyas

Linuxguru

0 thoughts on “VIM editor commands and examples – Linux”

Leave a Comment

PHP Code Snippets Powered By : XYZScripts.com