Vim

Vim is a very powerful command line text editor.

Clipboard

Clipboard

  • yy: Copy line to vim's clipboard
  • dd: Delete line and copy to vim's clipboard
  • p: Paste clipboard. If line is copied, text is pasted on next line, else text is pasted right after the cursor

Command Line

Allows you to enter commands. To enter type :. This is technically a mode, but I thought it important enough to be a full subject.

Useful things to do in command mode:

  • :w: Write. Save file.
  • :q: Quit
  • :wq: Write and then quit
  • :!q: Force quit. Lets you quit without saving.
  • .: Repeat last command
  • :s/FIND/REPLACE/g: Find an replace text on current line
  • :%s/FIND/REPLACE/g: Find an replace text in entire document

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.

Navigation (normal mode):

  • gg: Go to start of file
  • G: Go to last line in file
  • Ctrl + o: Go to old cursor position (history is kept)
  • Ctrl + i OR Tab: Go to newer cursor position
  • 0 or ^: Go to beginning of line
  • $: Go to end of line
  • w: Beginning of next word
  • e: End of current word
  • b: Beginning of current word
  • Enter: Beginning of next line
  • Number + hjkl: Jump that many lines/characters

Plugins

Spell Check

Useful spell check commands:

  • z + =: Spell check. Type number choice followed by enter.
  • ] + s: Go to next misspelled word
  • [ + s: Go to previous misspelled word
  • z + g: Add word to good word list
  • z + w: Add word to bad word list
  • z + u + g: Undo adding word to good word list
  • z + u + w: Undo adding word to bad word list

To activate spell check, add the following to your .vimrc file (en is for English):

set spelllang=en
set spell