NAVIGATION
Home
Gallery
Java
Linux
Web
Scripts And Utilities
Mobile And Sms
Misc
Contact
pixelWIKI
Nabaz Tag




<<

Introduction To Vi

vi is default visual editor with *nix distributions, and as such is therefore shipped with all recent versions of Linux and Unix. This means that whenever you jump onto a *nix machine, you know that there is a very powerful text editor on there as standard.

Once you know vi, you can edit files really quickly, as it is extremely economical on keystrokes. Due to its different modes for inserting and issuing commands, it is much faster than most non-mode based editors. vi can do almost anything you want, as long as you know how to use it.

Unfortunately, as a result of it's power, vi is slow to learn. The more you use it, the quicker you get, and as with everything, the more you practise the better you get. If you use it regularly, you may well find that you end up with Windows Notepad files ending in :wq

Below is a very basic subset of the commands available. For more commands, check man vi on your favourite distro

VI Commands

Moving the Cursor 
   Beginning of current line		        0 or ^
   Beginning of first screen line	        H
   Beginning of last screen line	        L
   Beginning of middle screen line	        M
   Down one line			        j, {return}, +
   End of current line			        $
   Left one character			        h, {ctrl-h}
   Left to beggining of word		        b, B
   Right one character			        l, {space}
   Right to end of word			        e, E
   Right to beginning of word		        w, W
   Up one line				        k, -
   Beginning of next sentence		        )
   Beginning of previous sentence	        (


Special Pattern Characters
   Beginning of line				^
   End of line					$
   Any character except newline 		.
   Any number of the preceding character	*
   Any set of characters (except newline)	.*


Searching Through Text
   Backward for pattern				?pattern
   Forward for pattern				/pattern
   Repeat previous search			n
   Reverse direction of previous search		N

   Substitute pattern2 for all pattern1 found.	:beg,ends/patt1/patt2/g
   :%s/notfound/found/g Will change all occurences of notfound to found.


Creating Text 
   Append text after cursor		        a
   Append text after end of line	        A
   Insert text before cursor		        i
   Insert text at beginning of line	        I
   Open new line after current line	        o
   Open new line before current line	        O


Modifying Text 
   Change current word			        cw, cW
   Change current line (cursor to end)	        C
   Delete character (cursor forward)	        x
   Delete character (before cursor)	        X
   Delete word				        dw, dW
   Delete line				        dd
   Delete text to end of line		        D
   Join current line with next line	        J
   Put buffer text after/below cursor	        p
   Put buffer text before/above cursor	        P
   Repeat last modification command	        .
   Replace current character		        r
   Replace text to end of line		        R
   Substitute text for character	        s
   Undo your previous command		        u
   Transpose characters			        xp
   Yank (copy) word into buffer		        yw
   Yank (copy) current line into buffer	        Y
   Swap the case of current character           ~


Ending Your Editing Sessions
   Quit (no changes made)		        :q
   Quit and save changes		        ZZ, :wq
   Quit and discard changes		        :q!