vim: command not found

Vim, a contraction of Vi IMproved, is an extended version of the vi editor. Vim implements a text-based user interface to advanced text editing, and is favored by many system administrators and software engineers for its efficiency and ability to be extensively customized. Vim also includes useful features such as text completion, syntax highlighting, spell checking, and many more.

The vim command invokes the Vim editor. However, the vi command may also be used for this purpose because it automatically redirects the user to Vim. When entered without a file name as an argument, the vim command opens a welcome screen by default. Use the syntax vim {file name} to open a file. If the file does not exist, Vim creates a file by the name specified and opens the file for editing. Vim supports multiple files being opened simultaneously.

The vim editor has two modes of operation:

  • Normal mode
  • Insert mode

When you first open a file (or start a new file) for editing, the vim editor enters normal mode. In normal mode, the vim editor interprets keystrokes as commands.

In insert mode, vim inserts every key you type at the current cursor location in the buffer. To enter insert mode, press the i key. To get out of insert mode and go back into normal mode, press the Escape key on the keyboard.

In normal mode, you can move the cursor around the text area by using the arrow keys (as long as your terminal type is detected properly by vim). The vim commands include commands for moving the cursor:

  • h to move left one character
  • j to move down one line (the next line in the text)
  • k to move up one line (the previous line in the text)
  • l to move right one character

Moving around within large text files line by line can get tedious. Fortunately, vim provides a few commands to help speed things along:

  • PageDown (or Ctrl+F) to move forward one screen of data
  • PageUp (or Ctrl+B) to move backward one screen of data
  • G to move to the last line in the buffer
  • num G to move to the line number num in the buffer
  • gg to move to the first line in the buffer

The vim editor has a special feature within the normal mode called command line mode. The command line mode provides an interactive command line where you can enter additional commands to control the actions in vim. To get to command line mode, press the colon key in normal mode. The cursor moves to the message line, and a colon appears, waiting for you to enter a command. Within the command line mode are several commands for saving the buffer to the file and exiting vim:

  • q to quit if no changes have been made to the buffer data
  • q! to quit and discard any changes made to the buffer data
  • w filename to save the file under a different filename
  • wq to save the buffer data to the file and quit

If you encounter below error while running the vim command:

vim: command not found

you may try installing the vim package as per your choice of distribution:

Distribution Command
OS X brew install vim
Debian apt-get install vim
Ubuntu apt-get install vim
Alpine apk add vim
Arch Linux pacman -S vim
Kali Linux apt-get install vim
CentOS yum install vim-enhanced-2
Fedora dnf install vim-enhanced-2
Raspbian apt-get install vim

vim Command Examples

1. Open a file:

# vim path/to/file

2. Open a file at a specified line number:

# vim +line_number path/to/file

3. View Vim’s help manual:

:help[Enter]

4. Save and Quit:

:wq[Enter]

5. Undo the last operation:

u

6. Search for a pattern in the file (press `n`/`N` to go to next/previous match):

/search_pattern[Enter]

7. Perform a regular expression substitution in the whole file:

:%s/regular_expression/replacement/g[Enter]

8. Display the line numbers:

:set nu[Enter]
Related Post