Insert mode is the mode you usually think about in a text editor - when you press a key, the corresponding character is inserted.
insert mode from
- i - enter
insertmode before the cursor position, on the same line.
- I - enter
insertmode at the beginning of the current line.
- a - enter
insertmode after the cursor position, on the same line.
- A - enter
insertmode at the end of the current line.
- o - create a line after the current line, and enter
- O - create a line before the current line, and enter
insert mode, and go back to
normal mode, you can use the following keys:
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.
- 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.
- 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.
- 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.
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:
insertmode, you can use Command+z (Control+z on other platforms)
normalmode, u will undo the last change, while Control+r will redo it.
We've only scratched the surface of motions and operators available here - checkout the Vim documentation on motions and operators for more.