0

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?

8
  • Should execute when the user pressed any keys in any special mode or really everytime? – TornaxO7 Jan 26 at 6:52
  • It needs to be for any time a key is pressed in any of the modes (I guess the exception would be command mode/ex mode.) – Prismavoid Jan 26 at 12:27
  • What do you want to achieve with this function? – Jürgen Krämer Jan 26 at 13:31
  • 1
    Can you kindly mention the precise problem(s) you are trying to solve? Otherwise it might lead to the XY problem. – Mahbub Alam Jan 26 at 17:53
  • You can build a list of keys and remap them (like in this joke answer, not a complete list though), but I don't think there's any autocmd or easy way to do this. As others have mentioned, it would be helpful if you could describe what your goal is, because there may be another way to solve it. – Martin Tournoij Jan 26 at 20:04
0

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.

1
  • 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 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.