开发者

vim: run some code every time a buffer changes

I want to trap all events that modify the vim buffer, so I can record them and send them to开发者_Go百科 a server. I want to trap character-by-character events while in insert mode, and also be notified when p or dd etc. commands are executed---any time the document changes.


In Vim 8 this is much easier. Just listen to these to autocmd events:

TextChanged
TextChangedI


Going through the list of events I have selected the following:

|BufFilePre|            before changing the name of the current buffer
|BufFilePost|           after changing the name of the current buffer

|FileChangedShell|      Vim notices that a file changed since editing started
|FileChangedShellPost|  After handling a file changed since editing started

|InsertEnter|           starting Insert mode
|InsertChange|          when typing <Insert> while in Insert or Replace mode
|InsertLeave|           when leaving Insert mode

|QuickFixCmdPre|        before a quickfix command is run
|QuickFixCmdPost|       after a quickfix command is run

Although I have not tried, I believe that the Insert* events include such commands as delete, paste, change etc. You should also look for the 'Writing' events in |autocmd-events|.


A friend pointed me at the terribly-named netbeans module within vim. This looks like what I want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜