Ch 01 VI

VI runs in 3 modes:

1 Insert mode (Press I To Select this Mode)

2 Command Mode (By default file open with this Mode)

3 Execute Mode (To save file or Quit file using wq/q/q!/wq!)

 

1 Insert Mode

Press I to enter in this mode Use Arrow Key for Direction or

 

            K for Up

H for Left             L for right

            J for Down

 

2 Command Mode

Command Mode is the default mode

X                          Cut the Character

@CW                    Cut Specify No of character

YW                       Copy the word

@YW                    Copy @ no of words

To know about column Press Ctrl + G

* @ Means Numbers

CW                       Cut The Word

@CW                    Cut @ no Of word

CC                        Cut the Line

@CC                     Cut The @ No Of Line

DW                       Delete the Word

@DW                    Delete the @ No Of word

DD                        Delete Single Line

@DD                     Delete @ No Of Line

YY                         Copy the Line

Y$                         Copy word From Cursor up to end of line

@YY                      Copy @ No Of Lines

C$                         Cut word from the cursor up to end of line.

U                           Undo The last Change.

Ctrl+R                   Redo The last undo.

D/D$                     Delete the word from the cursor up to the

                             End of line.

:1

[[        Use this 3 options to scroll the first line of the file.

gg

p         Paste the Line /Word /Character below he cursor (Small p)

P         paste the Line /Word /Character above the cursor. (Caps P)

:$

:         3 option for scroll to last line of file.

]]

 

Press Esc

/word             find particular word in files

A                    go to next word

N                    go in opposite direction of search.

:@                  go to the @ No Of line

 

Press Esc

:w<File>          This is for save as

0 (Zero)            Insert Blank line above the cursor & change to insert mode.

O                      Below the cursor Insert blank line.

:R<file>            Insert the file content in the current file after the cursor.

 

3 Execute Mode

Esc

:

:q quit the Vi Editor

:q!         force fully quit Vi Editor

:wq         save & quit from vi editor

:wq!        Force fully save & quit

:se nu      set no to all line

 

Find & Replace

 

:1,$ s/old/new/g (Replace The character new in spite of old )

  1 1st Line

         $ Last Line

         S Search

         G Global (whole file)

 

:1,.s/old/new/g          Current Cursor Position

@,.s/old/new/g           Character or word between the line

:/ (search word)          Find particulars

:se nu                        Set number to line

:se nonu                     Reset to normal

Sort<file>

Sort –r <file>

Sort –n <file> Numerical

Sort –nr<file>

Head <file> (default top 10 lines)

Tail <file> (default bottom 10 lines)

Head –n 20 <file> (top 20 line)

Tail –n 30 <file> (bottom 30 line)

\spl split the screen in two three horizontal

\vspl split the screen in two three vertical