One vimmer (not me) saw this question and just wrote a plugin for that. Note that this is not a simple solution and probably not for those who prefer to keep vim minimum, but it works like a charm. Also note that this was not meant to be a serious work, thus you can't necessarily seek for a steady support.
plugins to install
Use your preferred way to install these plugins.
Settings
Let's say you want to use Meta+y to "yank and highlight". Write the following settings in your .vimrc
.
noremap <expr> <Plug>(yank-highlight) operator#sequence#map("y", "\<Plug>(operator-highlight)")
nmap <A-y> <Plug>(yank-highlight)
vmap <A-y> <Plug>(yank-highlight)
Change <A-y>
to whatever keymap (just y
might not work) you'd like to use : <Leader>y
can be nice, for example.
The highlight can automatically be cleared. Write the following:
let g:operator#highlight#clear_time=2.0
This will clear that highlight in about 2 secs. The interval also depends on :set updatetime?
, which defaults to 4000
(ms), so if this doesn't seem to clear the highlighting, try setting updatetime
to a smaller value.