Monday, March 19, 2012

UNIX TOOLs - Basic vi editor and some advance key commands

Basic vi editor and some advance key commands

In vi editor , three are contented 3 kinds of mode : 
  1.Insert Mode : to be able edit or insert more word contents by press i or a from Esc Mode.
  2.Esc Mode : to be able in using key commands as navigation, modification, change mode to ex mode etc... 
  3.Ex Mode : a kind of using ":" for more experts.

1.INSERT MODE:
 This mode you can use left side of your keyboard (Unix like this).
 Change to Esc Mode : pree esc button.

2.Esc Mode: 
 a.Navigation
   # Moving cursor
    h = left     j = down     k = up     l = right
   # Big moving cursor
    w = forward by each word
    b = backward by each word
    0 = move to the end of current line of cursor
    $ = move to the beginning of current line of cursor

    gg = move to the first line of text
    G =  move to the end line of text
    12G = move to line 12 of text
    ctrl+f = page down
    ctrl+b = page up
    ctrl+g = to see where am I ? what I am doing ?
 b.Modification
   # Deleting

    x = delete what cursor is standing on

    D = delete everything after cursor is standing on til end of current line
    dd = delete current line cursor standing on
    d4d = delete 4 lines from cursor standing on

   # Editing

    r = change only one _ which cursor is standing on then ESC MODE is being

    cw = change only one word which cursor is standing on but Will change to INSERT MODE

    O = insert text in the front of current line and change to INSERT MODE

    A = insert text at the end of current line and change to INSERT MODE
   # Copying & Pasting
    yy = copy to current line cursor standing on
    y5y = copy 5 lines from the cursor standing on
    p = past what you have copied before to the next line cursor standing on
   # Undo
    u = revert what you have done once . ( undo )
   # How to cut / move text
    ESC MODE : press v (VISUAL) then move your cursor with ( h,j,k,l ) to make a  
    selection then press c after pressed it will be changed to INSERT MODE then 
    return ECS MODE and move to where you want to place the text you have selected 
    before then press p.
c.Exit editing session

    ZQ = exit without saving

    ZZ = exit with saving
3.EX MODE:
  Enter EX MODE by being in ESC MODE then press : and following <command>
 a.Exit editing session
   :q   =  quit editing without saving
   :wq  =  save then quit
   :q!  = force to quit
   :w!  = force to save
   :wq! = save then force to quit
b.Saving to other file
   :w newfile.xx
c.Go to Line
   :0  = go to first line
   :$  = go to last line
   :123  = go to line 123
d.Bookmark
   :k a  = mark the current line as line a in bookmark
   :'a   = go to line a in bookmark
e.Line number display
   :set number  = display line number
   :set nu      = display line number
   :set nonumber  = hide line number
   :set nonu  = hide line number
f.Control code display
   :set list  = display code hidden
   :set nolist = hide code hidden
g.Search and replace
   :%s/Old/New/g  = search Old and replace New for all whole text
   :10,23s/Old/New/g  = search Old and replace New from Line 10 to 23
   :.s/Old/New/g  = search Old and replace New in current line cursor standing on
   :'a,'bs/Old/New/g = search Old and replace New from line a to line b (a,b in bookmark)
   :2,10s/^/   /g  = make space 3 spaces in front of line from line 2 to line 10
h.Block processing
   :3,4co10  = copy line 3 til line 4 to past in line 11 before line 10
   :1,5m11  = move line 1 til line 5 to past in line 12 before line 11
   :1,2w filename  = write text from line 1 til line 2 to save in a filename
   :2,3r filename  = read text from line 2 til line 3 and write on the current line
i.What dialect am I using ?
   :version
k.Split a file into pieces
   :split
   :split otherfile  = open new other file in the same window of current file opening
   :vsplit   =  more easy to see by side
   :vsplit otherfile 

No comments:

Post a Comment