2011-05-13 86 views
3

我想捕获修改vim缓冲区的所有事件,以便我可以记录它们并将它们发送到服务器。我想在插入模式下捕获逐字符事件,并且在文件更改时随时执行pdd等命令。vim:每次缓冲区更改时运行一些代码

+0

你想达到什么?也许[ttyrec](http://packages.ubuntu.com/lucid/ttyrec)可以帮助你 – sehe 2011-05-17 20:50:54

+0

你在找[keylogger](https://github.com/igrigorik/vimgolf/blob/master /lib/vimgolf/keylog.rb)?或者比这更多? – Johnsyweb 2011-05-17 21:09:15

+0

我想制作多人vim(想想Etherpad)。 – nornagon 2011-05-19 08:49:29

回答

0

一位朋友指出我在vim中命名为netbeans的模块。这看起来像我想要的。

2

通过我选择的事件列表去以下:

|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 

虽然我没有试过,我相信Insert*事件包括这样的命令为d elete,p ASTE,c焊割等你还应该在|中寻找'写作'事件autocmd-events |。

+0

如果可以重新映射默认vim命令(例如所谓的“dd”和“p”),我现在只是好奇;) – freitass 2011-05-17 20:27:06

+0

这将是可能的,但需要巨大的努力......并且可能不会和vimrc很好地玩。需要处理所有的变化,例如。 '2dd','vjjp','d3k'等。而且,当您在插入模式下输入文本时,只有当您进入或离开插入模式时,Insert *方法才会触发。 – nornagon 2011-05-19 08:58:51

2

在Vim 8中这很容易。只听这些来autocmd事件:

TextChanged 
TextChangedI