Vim - Modes


Unlike most text editors, the ability to insert text into a document isn't the only mode. Instead vim has many modes that help with the forever goal of never touching a mouse again!

Insert

Insert mode allows you to add text to a file. To enter insertion mode, type i from normal mode.

Useful other ways to enter insert mode:

  • Shift + a: Start insert at end of line
  • Shift + i: Start insert at beginning of line
  • a: Insert after cursor
  • o: Add a new line below the current line and insert there
  • Shift + O: Add a new line above the current line and insert there

Normal

Normal mode is the default mode. Press Esc from any mode to enter this mode

Useful commands:

  • u: Undo
  • Ctrl + r: Redo

Replacement

Replacement mode is similar to pressing the Ins key on the keyboard. It allows you to replace characters under the curor with those that you type.

To enter, press Shift + R in Normal Mode.

Visual

Visual mode allows you to select text. To enter, press v.

Useful things to do in visual mode:

  • y: Copy selected text to vim's clipboard
  • d: Delete selected text and copy to vim's clipboard
  • c: Delete selected text and enter insert mode
  • < or >: Increase or decrease indentation of selected lines
  • :s/FIND/REPLACE/g: Find and replace text on selected LINES (including non-selected part)

There is also visual block mode.

Useful things to do in visual block mode:

  • Shift + i: Insert text on multiple lines. Type text then hit Esc.