Vim is the successor of the vi terminal text editor with a long list of powerful features. Short for “Vi IMproved,” Vim is sometimes pre-installed on popular, staple Linux distributions such as CentOS and Debian. For others including Linux Mint, you might instead have the original vi or vim.tiny, a slimmed down variant of Vim excluding dozens of advanced, yet less commonly used features.
In an earlier article, we compared Vim versus Emacs and how to port Vim key bindings into Emacs. Power users looking to move away from Nano in the command-line interface (CLI), or Secure Shell (SSH), may have found a resolution with Vim.
Below we’ll cover the basics of:
- How to Use Vim
- How to Configure Vim
- Vim Tutorials
How to Use Vim
SSH into your Linux server. To edit or create a file, type the following command:
Next, we’ll cover the multiple Vim modes: insert, replace, visual, command, and normal.
This is the default mode when you first open a file with Vim. In this mode, you can move the cursor with the arrow keys or Vim key bindings.
Move left: ⬅ or H
Move down: ⬇ or J
Move up: ⬆ or K
Move right: ➡ or L
Move to start of previous word: B
Move to start of previous word before a whitespace: Shift+ B
Move to end of word: E
Move to end of word before a whitespace: Shift + E
Move to start of next word: W
Move to start of next word after a whitespace: Shift + W
Move to the start of the current line: 0
Move to the end of the current line: $
Copy, cut, and paste:
Copy text: Y
Copy a line:
Cut text: D
Cut a line:
Paste text: P
Vim Insert Mode
This is the most common mode as it allows you to insert text in a document. To enter this mode:
Press I or Insert to insert text at the cursor location.
Press O to create a new line below the cursor location and insert text there.
While in Insert Mode, the bottom of the terminal will read
-- INSERT --.
Press Esc to return from to Normal mode.
This mode allows you to replace individual or multiple characters at once.
Press R to replace a single character in the file. There will be an
r in the lower-right corner until you replace a character.
Press Shift + R to replace multiple characters or lines within the file. Meanwhile, the bottom of the file will read
-- REPLACE --.
This mode selects text starting from the current cursor position. This may be a more accessible method for easily copying text for some users.
Press V to select individual characters starting from the current cursor position. At the bottom you’ll see
-- VISUAL --.
Press Shift + V to select full lines including the current cursor position. At the bottom you’ll see
-- VISUAL LINE --.
Commands start with
: and are executed with Enter. Just as with returning to Normal mode, you can exit out by pressing Esc.
Exit Vim without saving changes:
Save changes and exit Vim:
Save changes and exit Vim, enter one of the following:
Quit Vim without saving the file, enter
To force an action, add
! to the end of the command. For example,
Open a second document in the terminal with a vertical split:
How to Configure Vim
Sysadmins can make system-wide changes to Vim environments within the system vimrc files (/etc/vim/vimrc or /usr/share/vim/vimrc). Users can customize their personal Vim environment by creating a
~/.vimrc file. We’ll share some notable features you can uncomment or add in system or personal vimrc files respectively.
Enable syntax highlighting:
Show matching brackets while coding:
Enable mouse usage in all modes:
Want to learn more about Vim? Prefer hands-on training? Check out these resources below for interactive learning and advanced features.
Vimtutor works as an extension of
man vim with lessons to walk you through how to use Vim commands. Start the tutorial with the command
Vim Cheat Sheet
To learn more about using the VIM text editor, you can try the VIM Adventures educational game. The full version requires a paid subscription. However, you can play the free trial in your browser.
The Linux Command Line Book
Learn more about system administration from our Cloud Server Hosting.