What is the Vim Editor in linux?

If you are working in the command line mode, you may need to become familiar with a text editor that will be operating in a Linux console. The vim editor is the original editor that Unix uses.

It makes use of the console graphics mode for the emulation of a text-editing window, which allows you to see different lines of the file, move around across the files, and edit, insert or replace a piece of text. The vim editor works well with the data that is in a memory buffer. You have to type vim and the name of the file that you have to edit to open the editor with the desired file.

How does VIM Editor work in Linux?

If the editor is started without a filename being supplied, it opens but with no file. The vim editor detects the session’s terminal type and uses full-screen mode so the console window can use the editor area. The initial window will show the file contents and a message line at the bottom of the window.

If the contents don’t take up the entire screen, a tilde is placed on the lines excluded from the file. The vim editor has two operational modes — normal and INSERT mode. When you open a file for editing, vim goes into normal mode, and certain keystrokes are interpreted as commands.

In the insert mode, each key typed at the cursor is inserted into a buffer. To get into insert mode, press the i key, and to get out of it and back to normal mode, press the ESC key.

VIM Editor commands

You can use the arrow keys in normal mode to move around the text so long as vim has detected the correct terminal type. The vim command includes those for cursor navigation, as you can see below:

  • The command h in vim Linux editor is used to move to the left by one character.
  • The command 1 in the vim Linux editor is used to move to the right by one character.
  • The command j in vim Linux editor is used to move down the cursor by one line.
  • The command k in vim Linux editor is used to move up the cursor by one line.
  • The command PageDown or Ctrl-f in vim Linux editor is used to move forward one screen of your data.
  • The command PageUp or Ctrl-b in vim Linux editor is used to move forward one screen of your data.
  • The command gg in the vim Linux editor is used to shift to the first line in the buffer.
  • The command G in vim Linux editor is used to move to the last line in the buffer.
  • The command num G in vim Linux editor is used to move to the line number in the buffer.

The vim editor carries a special feature in the normal mode that is known as the command line mode. The command line mode offers an interactive command line where you may enter additional commands to control different types of actions in the vim editor. To get to the command line mode in the vim editor, you have to press the colon key while you are in the normal mode. The cursor will move to the message line. Here you will see a colon popping up on the screen which indicates that you should now enter a command.

When you are in the command line mode, you may enter several commands to save the buffer to file and move out of the editor.

  • The command q in vim Linux editor is used to exit the system if you have made no changes to buffer data.
  • The command wq in vim Linux editor is used to save buffer data to file and then exit the editor.
  • The command q! in vim Linux editor is used to quit the editor and then discard the changes that are made to the data of buffer.
  • The command w filename in vim Linux editor is used to save your file with a different filename.

Related Posts

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.