Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hightlight copied area on vim

Tags:

vim

yank

I would like to mimic a nice effect found in the game Vim Adventures: When a yank command is done, I would like the yanked area to be highlighted (let's say in red) for a second to show me that my selection was correct.

For example, yy would highlight the current line in red one second, then I would know what was selected.

like image 515
user2854544 Avatar asked Sep 26 '14 22:09

user2854544


1 Answers

For Neovim and Vim

There is a plugin named vim-highlightedyank for this, which works both for Vim and Neovim. Install it and it just works. You can also set the highlight duration by adding the following config:

" set highlight to 1000 ms
let g:highlightedyank_highlight_duration = 1000

Neovim only

If you are using nvim 0.5+, they have made this little feature builtin in this pull request.

No plugin is needed in this case. Just install nvim 0.5+ and add the following config to your init.vim:

augroup highlight_yank
    autocmd!
    au TextYankPost * silent! lua vim.highlight.on_yank({higroup="IncSearch", timeout=700})
augroup END

See Neovim's documentation on this feature for more.

like image 155
jdhao Avatar answered Oct 11 '22 08:10

jdhao