Learn Devops tools online from the blog. Devops Institute Ahmedabad.

Vim is a text editor written by Bram Moolenaar and first released publicly in 1991. Based on the vi editor common to Unix-like systems, Vim is designed for use both from a command line interface and as a standalone application in a graphical user interface. Vim is free and open source software,The name "Vim" is an acronym for "Vi IMproved"[6] because Vim is an extended version of the vi editor, with many additional features designed to be helpful in editing program source code.


Vim also has a built-in help facility (using the :help command) that allows users to query and navigate through commands and features.

VIM An Advanced Text Editor:-
=> Newer Virsion of VI, the standard Unix text editor

=> gvim :         Graphical Version of vim


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

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

       : 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

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

NOTE ( try must / read must / do must )

if you have any query about vim    please try 'vimtutor' command in terminal not in file

Vishal Vyas

1 comment: