Re: An event listener function in scripts
- On 27/05/09 21:36, spam.spam.spam.spam@... wrote:
>Yes and no.
> I am writing à Vim script.
> I put the script into ~/.vim/plugin folder.
> The script run automatically at the startup of Vim.
> I would like to know if there is an event listener function.
> I want to use it in order to know when a Vim user is pushing a key, or change of
> line, ...
> Is it possible?
> Thank you.
Like John said, there are a number of predefined "autocommand events" in
Vim, but not at that fine a level (you can trigger an autocommand
whenever the cursor moves, but not whenever the user hits any key at
all; most autocommands are more "high-level" such as opening or saving a
file, changing windows, etc.; even starting or ending a Vim session).
See |autocmd-events| for a list, and |autocmd.txt| for how to use them.
If you really want to intercept _every_ keypress, you will have to set
up a loop testing the getchar() function, and possibly feeding
keypresses back into the typeahead buffer using feedkeys() if you want
the "default" action to be taken; but if you go that route, it is then
your responsibility to program your script "cleverly" in order to avoid
having Vim consuming all (or almost all) the CPU time because you're
constantly testing whether a key is available.
Statement presented by a human and accepted by a computer in
such a manner as to make the human feel as if he is in control.
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php