In Vim, you'll primarily work in two modes: Normal mode for executing commands and Insert mode for typing text. To switch from Insert mode back to Normal mode, simply press the Esc key.
There are several commands to enter Insert mode, each placing the cursor at a different starting position for your text entry.
Basic Insert Commands
The most fundamental way to start typing is with the i command.
i– insert text before the current cursor position.
This command switches you to Insert mode, allowing you to type directly into the file.
Vim Append vs Insert
A common point of comparison is vim append vs insert. While both enter Insert mode, their starting points differ relative to the cursor. Understanding the vim insert vs append distinction is key to efficient movement and editing.
a– append text after the current cursor position.I– Insert text at the beginning of the current line.A– Append text at the end of the current line.
Using a instead of i saves you a keystroke (moving the cursor one space to the right before inserting). Similarly, A is a powerful shortcut to immediately start typing at the end of a line. Mastering the vim append commands is a significant step in improving your editing speed.
How to Vim Add Line
When you need to add new lines of text, you don't have to manually press Enter at the end of a line. Vim provides dedicated commands to open lines and immediately enter Insert mode.
o– open a new line below the current line and enter Insert mode.O– Open a new line above the current line and enter Insert mode.
These commands are extremely useful when you need to quickly vim add line while coding or writing.
Tip: You can prefix these commands with a number to repeat them. For example, typing 3o in Normal mode will open three new blank lines below the current one and place you in Insert mode on the first of these new lines.