nornagon
nornagon

Reputation: 15811

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

Upvotes: 4

Views: 2684

Answers (3)

XPlatformer
XPlatformer

Reputation: 1218

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

TextChanged
TextChangedI

Upvotes: 6

nornagon
nornagon

Reputation: 15811

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

Upvotes: 0

freitass
freitass

Reputation: 6694

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

Upvotes: 3

Related Questions