VIM Text Editor (Basics)

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:

Before using Vim, be sure that you know how to navigate the command line structure in SSH so that you can get to the right files.

How to Use Vim

SSH into your Linux server. To edit or create a file, type the following command: 

vim filename
Empty text file in Vim

Next, we’ll cover the multiple Vim modes: insert, replace, visual, command, and normal.

Normal Mode

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

Navigate words:

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

Navigate lines:

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: yy

Cut text: D

Cut a line: dd

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.

Replace 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 --.

Visual Mode

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 --.

Command Mode

Commands start with : and are executed with Enter. Just as with returning to Normal mode, you can exit out by pressing Esc.

Save changes: :w

Exit Vim without saving changes: :q!

Save changes and exit Vim: :qw

Save changes and exit Vim, enter one of the following: :x or :wq

Quit Vim without saving the file, enter :q

To force an action, add ! to the end of the command. For example, :q! or :wq!.

Open a second document in the terminal with a vertical split:

:vsplit path-to-file

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: 

syntax on

Show matching brackets while coding:

set showmatch

Enable mouse usage in all modes: 

set mouse=a

Vim Tutorials

Want to learn more about Vim? Prefer hands-on training? Check out these resources below for interactive learning and advanced features.

Vimtutor

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 vimtutor.

Vim Cheat Sheet

Check out the rtorr Vim cheat sheet for when you’re on the go. It’s available in multiple languages and on GitHub. DuckDuckGo users can find it quickly by searching “vim cheat sheet.”

VIM Adventures

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

One of our technical support representatives recommended The Linux Command Line book for it’s Vim coverage. This is just one of many ways to learn Linux.

Upgrade to VPS Hosting for Peak Performance

Upgrade to InMotion VPS Hosting today for top-notch performance, security, and flexibility, and save up to $2,493 – a faster, stronger hosting solution is just a click away!

check markDedicated Resources check markNVMe SSD Storage check markHigh-Availability check markIronclad Security check markPremium Support

VPS Hosting Plans

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!