VIM Modes and how to change the mode (2024)

Vim is the most popular and extremely powerful text editor. It possesses a lot of features that you would not expect to have in a text editor. Most of these features make it much easier for you to do a lot of work in a little time. The Vim editor is a modal text editor; it uses modes for different purposes like inserting text, running commands, and selecting text. Modes basically decide whether pressing any key on the keyboard will insert those characters or move the cursor through the document. Therefore, it is important to know what each mode is and how to change the modes.

This article will describe what Vim modes are and how to change them. Vim is a free and open-source text editor that comes installed by default with most of the operating systems.

Please note that all the commands and processes discussed in this article have been tested on the Ubuntu 20.04 LTS (Focal Fossa).

Vim Modes

In Vim, there are three modes of operation: Normal, Insert, and Visual.

Normal mode

Normal mode is the initial mode of the Vim editor. When you open a new file edit an existing one, it starts in normal mode by default. In normal mode, you cannot insert any character. Normal mode is also known as command mode because all the keystrokes you perform are interpreted as commands. For instance, if you press k, it will move the cursor position up one line instead of inserting the character “k”. Similarly, if you press yy, it will copy the current line instead of inserting “yy”. Also, in normal mode, the uppercase and lowercase letters are treated differently. For instance, pressing o create a new line for the text below the current cursor location, while pressing O creates a new line for text above the current cursor location

To access normal mode from other modes, press Esc key.

Insert mode

Insert mode is where you can insert your text in the file. This mode inserts every character you type at the current cursor location.

Visual mode

Visual mode allows you to select text so that you may perform certain operations (cut, copy, delete) on it.

Changing the modes

As already discussed, when you create or open a file in vim, it first opens in Normal mode.

In order to type any character, you will need to switch to the Insert mode. There are different commands to enter into Insert mode from Normal mode that are i, I, o, O, a, and A. The most commonly used command to enter in to insert mode is “i”. To shift back to normal mode, press Esc.

To switch to the visual mode from Normal mode, different commands are v, V, Shift + v, and Ctrl + v. The most commonly used command to enter in to insert mode is “v”.

To switch to the visual mode from Insert mode, first shift to Normal mode by pressing the Esc, then press v to get into the Visual mode.

Basic commands

Following are some basic commands that can be used for inserting and manipulating text in Vim:

File related commands

:wwrite the file to the disk
:qquit vi without saving the file
:wqwrite the file to disk and quit vi
:q!Ignore the warning and discard the change
:w filenameSave the file as filename

Moving the cursor

jmove the cursor down one line
kmove the cursor position up one line
lmove the cursor to the bottom of the screen
0move to the beginning of the line
$move to the end of the line

Inserting Text

Iinsert text at the beginning of the line
iinsert text before the current cursor location
ainsert text after the current cursor location
oCreate a new line for the text below the current cursor location
OCreate a new line for text above the current cursor location

Changing text

ccRemove the whole line and start Insert mode.
sRemove the character under the cursor and start Insert mode.
rReplace the character under the cursor

Copying pasting

yCopy the selected text to clipboard
yyCopy current line
Pinsert the text “before” the cursor,
pInsert the text at the point after the cursor

Deleting Text

Xdelete the character before the current location
xdelete the character under the current location
DCut to the end of line
ddCut current line

Undo/Redo

uundo last change
Ctrl_RRedo

The text editor should be optimized for editing, not just writing, and Vim is one of them. It has separate modes for editing, inserting, and selecting text. In this article, you have learned about vim Normal, Insert, and Visual mode and also how to switch between different modes. I hope you liked the article!

VIM Modes and how to change the mode (2024)
Top Articles
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 6820

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.