Table of Contents

Syntax Highlighting

:syntax on

This can also be added to .vimrc

Yank or delete between parentheses

Motion select

These work for matching parenthesis (), square brackets [], curly brackets {}, angle brackets <>, etc…

y% - yank
d% - delete

For visual mode

v%y - highlight between parenthesis and yank
v%d - highlight between parenthesis and delete

Object select

With the cursor within a block

yab - yank the block including the enclosing parenthesis
dab - delete the block including the enclosing parenthesis
yib - yank the block excluding the enclosing parenthesis
dib - delete the block excluding the enclosing parenthesis

For visual mode

v2a) - visual select, 2 nesting levels, including the enclosing parenthesis
v1i) - visual select, 1 nesting level, excluding the enclosing parenthesis

Comment/Uncomment multiple lines

Comment

  1. Enter visual mode: v
  2. Select the lines to comment.
  3. Add the line comment characters to the beginning of each line:
:s/^/#    - shell scripts
:s/^/\/\/ - C, C++, C#, Java, JavaScript
:s/^/--   - SQL

Uncomment

  1. Enter visual mode: v
  2. Select the lines to comment.
  3. Remove the line comment characters to the beginning of each line:
:s/^#/    - shell scripts
:s/^\/\// - C, C++, C#, Java, JavaScript
:s/^--/   - SQL

Auto Indentation

:set autoindent
:set cindent

Add/Remove indentation

  1. Enter visual mode: v
  2. Select the lines to indent.
  3. > to increase indent one tab < to decrease indent one tab.
  4. n> to increase indent n tabs.
  5. n< to decrease indent n tabs.

Replace word with copied text

  1. Yank (or delete) the text into a buffer: yw - to yank a word.
  2. Move to the beginning of the word to replace.
  3. vwp - v for visual select, w for the word, p to paste.

Reload the current file from disk

Change Case