Monday, August 19

Vi Editor Commands in Unix / Linux

VI stands for visual interface, the mechanism of editor is use to modify the data of an existing file respect to the requirement.

       In IT World, there are some default editors in various platforms.

                        Eg:-     Dos           --  edit
                                    Windows   --  notepad
                                    Linux         --
                                                            CLI  : vi, vim, ex, nano

                                                            GUI  : gedit, emacs, pico, nedit

Vim :  This is one of the text base editor in linux, which is not only use to create a new file, at also we use to modify the data of existing file.

In vi editor , totally 3 modes are available

                                  1. Command Mode
                              2. Insert Mode
                              3. Execution Mode

vi is a command to open vi editor ,The default mode is command mode
1. Command Mode :
       This is a default mode of vi, which provide some following important operations, like copy-paste, cut-paste, and search the word name, etc...

2. Insert Mode :

       The function of this mode to write new data into the file and also to modify the data of file.

3.Extended Mode (Execution Mode) :
            This is a last mode vi, which is use to save the modification of files and also to quit from vi.

      To shift form command mode to insert mode :

                        i      --> It place cursor at left side of the cursor line

                        I      --> It place cursor at beginning of the current  line

                        a     --> It place cursor at right side of the cursor line

                        A     --> It place cursor at end of the current line

                        o     --> It inserts new line below of the cursor

                        O     --> It inserts new line above of the cursor.

       Command Mode Commands :

                        H     --> Beginning of the current page

                        M     --> Middle of the current page

                        L     --> End of the current page

                        $     --> End of the current line (end key)
                        ^     --> Beginning of the current line (home key)

                        x(nx)    -->  Delete current character (del key)   

                        ctrl + f    -->  Forward one page (page-down key)

                        ctrl  + b   --> backward one page (pgup key)

                        dd (ndd)  --> Delete the current line (delete n lines)

                        dw (ndw)  --> Delete current word  (delete n words)

                        yy (nyy)    --> Copy the entire line (copy n lines)

                        yw (nyw)  --> To copy a word (copy n words)

                        y$            --> It copies current position to end of the line

                        y^            --> It copies current position to beginning of the line.

                         p             --> paste below the cursor
                        5p(np)     --> paste 5 times
                        P            --> paste above the cursor
                        u            --> undo

                       ctrl + r   --> Redo

                       Shift+zz(ZZ)  --> save and quit
                       gg          --> Move to the beginning of the line

                       G           --> Move to the end of the line

                       77G       --> Go to the 77th line

                       /<find word>  --> Find the particular word

                       h           --> move to left

                       k           --> move to top

                       l            --> move to right     

                       j           --> move to down

      Execute Mode Options :

                        :w                       --> save without quit

                        :w  <filename>   --> save with given filename

                        :q                      --> quit without saving changes

                        :q!                     --> quit with forcefully

                        :wq                   --> save and quit

                        :wq!                  --> save and quit forcefully

                        :x                      --> save and exit

                        :set number (se nu)  --> set line number

                        :set nonumber (se nonu) --> To remove line numbers

                        :5d (nd)           --> delete 5th  line

                        :$d                  --> delete last line

                        :3,6 d              --> delete 3rd line to 6th line

                        :! <unix command>  --> execute unix command

                        :/string/          --> Top to bottom search

                        :?string?       --> bottom to top search

                        :6 (n)            --> place cursor at 6th   line

                        :$                --> place cursor at last line in the file

            Replace String :-

                        :1, $ s/oldstirng/newstring/gi

                        :1, $ s/^/mahesh/   --> It adds “mahesh” at beginning of each line

                        :1, $ s/$/;               --> It adds “;” at end of each line

No comments:

Post a Comment

:: Linux - Legends ::