I want to run a function every time the user presses any key. I have already looked through the autocommand documentation and there does not seem to be one for this. Is there any function I do not know of that will detect any keypress?
Asked
Active
Viewed 840 times
1
1 Answers
1
There is not a direct way in vim to hook all key presses. If you are open to source modifications, one idea would be to edit the source code of the gtk version of vim.
However, there are a number of events which you can hook into; e.g.,
au CursorMoved,CursorMovedI,TextChanged,TextChangedP,CmdlineEnter,CmdlineLeave,CmdlineChanged * call cmd()
You can come up with key presses that don't raise one of these autocmds, but it would be rare in a normal editing session.
Mass
- 14,080
- 1
- 22
- 47
-
While these cover most actions, a big part of what I need to detect is folding/unfolding text, which you cannot do with autocommands. – Prismavoid Jan 27 '21 at 22:44
ConcealUpdatedautocmd, which gets triggered when "concealed" text updates the screen: folds open/close, but also concealed text gets displayed/hidden, and maybe some other scenarios. It might be worth raising this issue on the Vim issue tracker; I don't think it's that much work to implement. – Martin Tournoij Jan 27 '21 at 23:00