vim tricks


Author: yifei / Created: Jan. 18, 2018, 2:26 p.m. / Modified: Jan. 18, 2018, 10:31 p.m. / Edit

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

gd  will take you to the local declaration.
gD  will take you to the global declaration.
g*  search for the word under the cursor (like *, but g* on 'rain' will find words like 'rainbow').
g#  same as g* but in backward direction.
gg  goes to the first line in the buffer (or provide a count before the command for a specific line).
G   goes to the last line (or provide a count before the command for a specific line).

reformat json

:%!python -m json.tool

format html

:s/<[^>]*>/\r&\r/g :g/^$/d

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


评论区