vim

暂时放弃 vim

使用 vim 也有四五年了,但是现在感觉 vim 还是造成了一些效率低下的情形。主要是对于各种功能支持不全,比如说

  1. 补全功能,总是不完全好用,而且标准库的文档也弹不出来,每个语言也不统一。
  2. 第三方插件支持不统一,比如说 tagbar 支持不了 TypeScript

2019-08 更新,vscode 总是把机器 hang 住,滚回 vim 了

一些 vim 小技巧

重新对齐文本到固定长度

gq<motion>

check if mapping is replaced

:verbose map <Key>

using map may cause infinite recursion!

force set syntax

# vim: set filetype=javascript

exit

使用 Ctrl-C 而不是esc
使用ZZ而不是:wq

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

:%s/pattern//gn

delete blank lines

:g/^$/d

run python from vim

:w !python

nerdtree的使用

使用i和s分别在split中打开文件

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

交换两列

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

:set fileencoding=utf8
:w myfilename

add utf-8 BOM

:set bomb # add BOMB

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<C-X><C-S>

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
http://vimcasts.org/episodes/spell-checking/

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
         |internal-wordlist|.


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
         |internal-wordlist|.

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

zuW
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

Ref:

[1] http://usevim.com/2013/01/18/tags/

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

http://vim.1045645.n5.nabble.com/Putting-all-ctags-matches-into-quickfix-td1182150.html

http://vim.1045645.n5.nabble.com/Open-tags-in-quickfix-window-td1188577.html