一些 vim 小技巧

### 重新对齐文本到固定长度


### check if mapping is replaced

`:verbose map `

using map may cause infinite recursion!

### force set syntax

`# vim: set filetype=javascript`

### exit

使用 Ctrl-C 而不是esc

### window management

use ctrl-w r to swap pane

### folding

`{selection}zf` or `zf{motion}` for manual folding

### history

Ctrl-O to go back to files
Ctrl-I to go to new files


### delete blank lines


### run python from vim

:w !python

### nerdtree的使用


不要使用chardet来检测过长的网页,可以检测前一千个字符 chardet.detect(text[:1000])

### 交换两列

:%!awk ‘{print $2, $1}’

:set fileencoding=utf8
:w myfilename

### add utf-8 BOM
:set bomb # add BOMB

vim 中的拼写检查

# basic usage

`:set spell` to open, `:set nospell` to disable, `:set spell!` to toggle.

`]s` and `[s` to go to next and previous spell error. `z=` to see suggestions, but it’s not good. use `:nnoremap \s ea`

Use `set spell` to check spellings in vim, if you find word marked wrongly, simple press `zg` to add it the dictionary and `zw` to remove it from the dictionary, they can be revoked with `zug` and `zuw`.
Use `]s` to go forward in the highlighted errors and `[s` to go backwards.
Use `z=` to bring up suggestions

[1] Vim cast on spell check

zg Add word under the cursor as a good word to the first
name in 'spellfile'. A count may precede the command
to indicate the entry in 'spellfile' to be used. A
count of two uses the second entry.

In Visual mode the selected characters are added as a
word (including white space!).
When the cursor is on text that is marked as badly
spelled then the marked text is used.
Otherwise the word under the cursor, separated by
non-word characters, is used.

If the word is explicitly marked as bad word in
another spell file the result is unpredictable.

zG Like "zg" but add the word to the internal word list

zw Like "zg" but mark the word as a wrong (bad) word.
If the word already appears in 'spellfile' it is
turned into a comment line. See |spellfile-cleanup|
for getting rid of those.

zW Like "zw" but add the word to the internal word list

zug Undo |zw| and |zg|, remove the word from the entry in
'spellfile'. Count used as with |zg|.

zuG Undo |zW| and |zG|, remove the word from the internal
word list. Count used as with |zg|.

vim 中生成和使用 tags

To use go to definition and other advanced IDE feature, we need to generate tag files for vim to figure out where to find the functions or variables.

To generate a tag file

ctags -R

By default, the generate tag file will be located at ./tags directory, we need to let vim know where to find it by:

:set tags+=tags

To search for a symbol in vim, use

:tag [symbol-name]
:tag /[search-name]

To go to the definition, we need `Ctrl-]`, to go back, press `Ctrl-t`

:tn next tag
:tp prev tag
:ts all tags



vim tags matchlist is not very user friendly. I should write my own that shows the list in quick fix window