Linux vim Text Editor Commands

Vim means Visual Interface Modal. Vim is a Text Editor.
There are three primary modes of vim editor.
  1. Command Mode: This mode is used for file navigation, cut and paste, and simple commands.
  2. Insert Mode: This mode is used for text exiting.
  3. Exit Mode: This mode is used to save, quit, and open files.

How to open file in Vim

The easiest way to open a file in Vim is to specify it as an argument on the command line. To open the file called /etc/hosts, we can execute following command.
Ex. vim /etc/hosts
After opening a file, vim will start in the command mode.

How to edit new file

To open file with named "linux". Use following command to create new file with name linux.

How to switch to insert mode

i is used to switch to insert mode.
In the following table, find some of the keys we can use from command mode to move your cursor.

Cursor left one position
Cursor right one position
Cursor down one line
Cursor up one line
Move to the beginning of the current line
Move to the end of the current line
Move to the first line of the document
Move to the last line of the document

How to saving files in insert mode

Saving files in Vim is done from ex mode. We can enter ex mode by pressing : (a colon) from within command mode. After you enter ex mode, the ruler will display a colon (:) and wait for a command to be typed.
Following is a list of commands to save and quit your current file from ex mode.
Save and quit the current file
Save the current file if there are unsaved changes, then quit.
Save the current file and remain in editor
:w <filename>
Save the current file under a different file name.
Quit the current file (only if there are no unsaved changes)
Quit the current file, ignoring any unsaved changes.

Most Reading