Editing and Deleting Text
Insert Mode
Insert mode is the mode you usually think about in a text editor - when you press a key, the corresponding character is inserted.
To enter insert
mode from normal
mode:
- i - enter
insert
mode before the cursor position, on the same line. - I - enter
insert
mode at the beginning of the current line. - a - enter
insert
mode after the cursor position, on the same line. - A - enter
insert
mode at the end of the current line. - o - create a line after the current line, and enter
insert
mode. - O - create a line before the current line, and enter
insert
mode.
To leave insert
mode, and go back to normal
mode, you can use the following keys:
- Escape
- Control+c
- Control+[
Operators
Besides insert mode, there are other ways to manipulate text in normal
mode - that's where operators come in. Vim and the 'vi' family of editors,
like Onivim, provide a sort of text-editing-language, and operators are an important piece of this language.
Basic Operators
- dmotion - delete the text described by motion.
- cmotion - change the text described by motion.
A motion is a cursor movement, as described in Moving Around.
Examples:
- c$ - change the text from the cursor position to the end-of-theline.
- dd - delete the current line.
- d10j - delete the 10 lines below the cursor.
- dG - delete to the end of the file.
Other operators
- ymotion - yank text to a specified register.
- gumotion - convert text described by motion to lowercase.
- gUmotion - convert text described by motion to uppercase.
- >>motion - shift lines described by motion to the right.
- <<motion - shift lines described by motion to the left.
Repeat
The . "dot operator" is a very useful command - it repeats the last command.
For example, if dd was used to delete a line, pressing the . key would repeat the command, and delete another line.
Undo / Redo
It can be scary to experiment with the operators and motions, for fear of losing your work!
However, you can always undo your change:
- In
insert
mode, you can use Command+z (Control+z on other platforms) - In
normal
mode, u will undo the last change, while Control+r will redo it.
Further Reading
We've only scratched the surface of motions and operators available here - checkout the Vim documentation on motions and operators for more.