1

I have searched through a list of all the autocmd's and can't find one which is fired when a built in VIM command is run.

How does one run some custom code after a person calls an existing vim command, e.g. :noh? (something like the Emacs advice function).

For those who will ask why not create a new command to call both... within a quickfix window I auto highlight some terms using match, and wish :noh to intuitively clearmatches() too. Hence I wish to run clearmatches() after :noh is run within a filetype of ftplugin/qf.vim.

  • 1
    I don't think there is a way to do what you want other than using a new command or keymapping. It would actually break many plugins if there was, since they would also run the custom logic. I personally map <C-l> to clear :nohl and some other things. – Martin Tournoij Apr 15 at 9:50
  • 1
    You might be interested in: vim.fandom.com/wiki/Replace_a_builtin_command_using_cabbrev – Zorzi Apr 15 at 9:52
  • 1
    How about the SafeState event? It's not exactly after an autocmd, but it's triggered when Vim is done processing and will wait for user input, it might be close enough to what you want and you can use it to detect whether highlighting was cleared and execute clearmatches() then. Does that work for you? – filbranden Apr 15 at 11:22

Your Answer

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

Browse other questions tagged or ask your own question.