How to use vi text editor in Linux terminal

vi is visual terminal based text editor for linux. vi can open, create and  modify. To run command you have to enter it in status line below text of file. To exit from command mode and enter in text input mode press I. Pressing Escape will make you exit from input mode. Here we have top 20 commands used frequently in vi text editor.

Top 20 command of vi text editor

  • Open file with vi text editor – To open a file in vi text editor in current folder type vi filename
    In case file exists in different location type path to file followed by file name.
    vi /path to file/filename.
  • Modify file with vi text editor – To start writing in open file press
    I
    it will start editing mode.
  • Exit open file in vi text editor – To exit from editing mode press
    Escape
  • To create a line below cursor press
    o
    Create a line above cursor press
    Shift + o
  • To copy a line press
    yy
    To copy a word press
    yw
    To copy multiple lines type
    Number of lines yy , example  5 yy
  • To paste copied text in next line press
    p
    To Paste copied text above line press
    Shift + p
  • To delete a line press
    dd
    To delete a word press
    dw
  • To undo last change press
    u
  • And to redo last action press
    Control + r
  • To go to end of file press
    Shift +g
  • To go to Start of File press
    gg
  • Show line number
    se nu
  • Hide line numbers
    se nonu
  • Save and exit
    :wq
    This command is to be run after exiting editing mode by pressing escape key
  • Force save and exit
    :wq!
    This command is to be run after exiting editing mode by pressing escape key

These are frequently used commands. For more commands of vi do leave a comment.