I want to know how to call a function after a normal or Ex command.
- bind a function to search command. When I input
xxxx, also call the function.
*to highlight occurrences, then also execute a function.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
In case of
* (or similar normal mode commands) you just remap it:
func! MyFunc() echom "Hello World" endfunc nnoremap * *:call MyFunc()<CR>
For the search
/xxxx you can redefine
<CR> mapping in commandline:
func! SearchCR() if getcmdtype() =~ "[/?]" echom "Run Something if CR was pressed in /search" endif endfunc cnoremap <CR> <cmd>call SearchCR()<CR><CR>
This would work only in recent vim (with support of a new
PS, there are no "hooks" in vim to attach to selected normal mode commands, although there are autocommands that could be used to run your code on some events.