Linux Vi Editor

vi stands for visual editor and comes as one of default applications in every Linux/Unix system. The vi editor has two modes.

  • Command Mode: In command mode, actions are taken on the file. The vi editor starts in command mode. Here, the typed words will act as commands in vi editor. To pass a command, you need to be in command mode.
  • Insert Mode: In insert mode, entered text will be inserted into the file. The Esc key will take you to the command mode from insert mode.

If you are not sure which mode you are in, press Esc key twice and you’ll be in command mode.


Create a file with vi {filename}

vi test.txt


Save file

// save and quit

// save

// quit

// save as filename
:w fname

// save and quit

// quit and disregard work

// quit and save qork


How to delete on command mode

// delete current character

// Replace the current character

// Switch two characters

// Delete the current line

// Delete the current line from current character to the end of the line

// delete from the current line to the end of the file


Repeat and undo

// Undo the last command

// repeat the last command


Copy, Cut, and Paste

// Delete a line

// (yank yank) copy a line

// Paste after the current line

// Paste before the current line

// Delete the specified n number of lines

// Copy the specified n number of lines


Search string

// Forward search for given string

// Backward search for given string

// Forward search string at beginning of a line

// Forward search string at end of a line

// Go to next occurrence of searched string

// Search for the word he (and not for there, here, etc.)

// Search for place, plbce, and plcce


Replace all

:{startLine,endLine} s/{oldString}/{newString}/g

// Replace forward with backward from first line to the last line
:1,$ s/readable/changed/





Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!


Leave a Reply

Your email address will not be published. Required fields are marked *