vimscript 基础教程


Author: yifei / Created: July 26, 2017, 7:34 a.m. / Modified: July 26, 2017, 5:35 p.m. / Edit

<esc>
<c-c>
<c-[>

autocommands

 autocmd BufNewFile * :write
         ^          ^ ^
         |          | |
         |          | The command to run.
         |          |
         |          A "pattern" to filter the event.
         |
         The "event" to watch for.

A common idiom in Vim scripting is to pair the BufRead and BufNewFile events together to run a command whenever you open a certain kind of file, regardless of whether it happens to exist already or not.

examples:

autocmd BufWritePre,BufRead *.html :normal gg=G reindent html files

autocmd BufNewFile,BufRead *.html setlocal nowrap set html files to nowrap

:autocmd FileType javascript nnoremap <buffer> <localleader>c I//<esc> :autocmd FileType python nnoremap <buffer> <localleader>c I#<esc> map <leader>c to comment out the line


有任何问题可以发邮件到 kongyifei (at) gmail.com 讨论