How to install and use Vim text editor on CentOS7 | TOSHOST LTD

How to install and use Vim text editor on CentOS7


The most powerful text editor accessible from the command line is vim editor. With most UNIX systems and Apple OS X, it is included as "vi".

You can get basic ideas about “Vim” by reading this blog.

Now we will see what can be done with "Vim" and how to do.

  • Installation
  • Opening Vim
  • Modal Editing
  • Navigation
  • Editing
  • Managing Documents


To install the "Vim", execute the following command and see the image below.


sudo yum install vim


Press the enter button to install "Vim".

From here, press Y to update or download "Vim".

Opening Vim

To open any file in the command line, press the Enter button with "vi" before the filename and then open your file.

If you want to create a new file via vim, then use the following command.

vim newfile


To write something in the new file, press "cc". When finished, press the "Esc" button. To save the file: Press ":x".

Modal Editing

The main difference between vim and other text editors is that vim is a "modal" editor. Most other editors have only one mode. Vim works with many modes.

Normal Mode

In Normal Mode, if you want to edit, copy and paste any text after pausing, press the "Esc" button and you can pause.

Model Editing has insert mode, visual mode, and command mode outside of the normal mode.


We use arrow keys from the keyboard to move right, left, top, and down while editing or editing any text on the computer. But in Vim you have to press some word to work.

Now we will see, how to move left, right, up, and down on Vim when we edit or create a new file.

  • h- press for move left side
  • j- press for the move down
  • k- press for the move up
  • l- press for the move right


Commonly used commands for text editing in Vim.

Removing Text

  • x - Delete characters in cursor position
  • d - Press d to delete the direction you specified after executing the command. For example, "dl" deletes a letter to the right.
  • dd – For delete a line.
  • D - Delete from the current location at the end of the line.

Copying and Pasting

  • y - Copy.
  • yy - Copy the whole line.
  • Y - Copy to the end of the line.
  • p - Paste the copy below the current line to the last line.
  • P - Paste the copy in the last line above the current line.

Managing Documents

Vim mainly manages the document through the command. In order to manage a document in the vim, all the commands have to be used ":" this symbol before the command.

  • :q - Leave the Vim. If the changes are not saved, it will be lost.
  • :q! - Leave the Vim. Discard unsaved changes.
  • :w - Save Changes. If you want to save a different location, add a space and a file name, or it specifies a saved location for your first time.
  • :e - Edit the next file
  • :bn - Edit the file next to the file that is open.
  • :bp - Edit the previous file that vim has open.