vim in practice (1)

Vim Practice

<leader>

Vim have a extra key to activate mappings, and call this “prefix” key the “leader”.

*Mapping keys is one of the places where Vim comments does’t work.

1
2
3
let mapleader=','
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>

Abbrevation

Vim has a feature called “abbreviations” that feel similar to mappings but are meant for use in insert, replace, and command modes.

1
2
3
iabbrev what what
when you type *what<space>*
were substituted with *what<space>*

Disable old keys

This effectively disables the escape key in insert mode by telling Vim to perform (no operation) instead.

1
inoremap <esc> <nop> "no operation

Autocommands

Autocommands are the way to tell Vim to run commands whenever certain events happen.

1
2
3
4
5
6
7
8
9
10
11
12
:autocmd BufNewFile * :write
^ ^ ^
| | |
| | The command to run.
| |
| A "pattern" to filter the event.
|
The "event" to watch for.

:autocmd BufWritePre,BufRead *.html :normal gg=G
:help autocmd-events

System clipboard

1
2
3
4
5
BundleInstall fakeclip
1. Normal mode
"+Y or "+yy (use system register<+> to copy)
2. Visual mode
"+Y