VIM

Modes

Insert mode

To enter from command mode:

Normal mode

Hit <Esc> to enter this mode.

Grammar

{operator}{count}{object}
object = {motion, text object}

Operators

Single char operators (can’t modify with count)

Misc

Motions

Grammar

{count=N}{motion}
      ↑
← h j k l →
    ↓

Word motions

A word is alphanumeric. A WORD is a word and punctuation .({}),.

Horizontal motions

Vertical motions

Find character motions

Find pattern motions

Text object

Adjectives

Nouns

Some operators (ydc) can be doubled (e.g. yy) to make them operate on a whole line.

Visual mode

Once the selection has been made, you can:

Advanced

Marks

A mark (i.e. bookmark)

:marks display marks set

Registers

"{register}{operator}{count}{object}

:registers (alias :reg) prints contents of all registers :reg a prints contents of register a

To write to system register automatically, add this to your vimrc: clipboard+=unnamedplus

ctrl + R {register} in Insert/Command mode will put contents at cursor.

Program commands

Plugins

TODO

: Enter command mode R Enter replace mode v Enter visual mode (highlighting) V Enter visual line mode (highlighting lines) esc Return to normal mode from insert or replace mode esc+esc Return to normal mode from command or visual mode

:[range]s/foo/bar/[flags] Replace foo with bar in range according to flags. (if range is empty, then current line)

Ranges

Flags

map <F5> :x <CR> :! nim -c -r %
:nmap for normal mode mappings
:vmap for visual mode mappings
:imap for insert mode mappings
" Example
nnoremap Y y$


`:set bg=dark/light` to change theme
`:echo $MYVIMRC`

# line wrap
:set textwidth=n (or :set tw=n)

:iabbrev forr for(int i=n; i>=0; --i){}
:iab

:sort
:sor! # reverse

# view buffer
:buffers
# to close a buffer
:bd

# run external programs
# prefix with !, % is path
!python %

References