DannoHung
DannoHung

Reputation: 411

Is there a way to make yanks visual in vim?

When yanking in vim, there is no visual indication of the yank that you just made. Aside from inspecting the registers, does anyone know of a setting or plugin that will make vim highlight the region of the editor that was just yanked?

Tried googling, but if it's out there, I'm using the wrong phrase to search.

Upvotes: 4

Views: 447

Answers (3)

epsilonhalbe
epsilonhalbe

Reputation: 15959

I don't know if it works always but i tried this

vnoremap <silent> y y:execute '2match InterestingWord2 /<c-r>"/'<cr>
hi InterestingWord2 guibg=DarkOrange guifg=black ctermbg=202 ctermfg=black

which works for visual selection on one line - but not on multiple.

maybe the following work too - i've not tried them

nnoremap <silent> yy yy:execute '2match InterestingWord2 /<c-r>"/'<cr>
nnoremap <silent> y$ y$:execute '2match InterestingWord2 /<c-r>"/'<cr>
nnoremap <silent> Y Y:execute '2match InterestingWord2 /<c-r>"/'<cr>

Upvotes: 0

Rook
Rook

Reputation: 62548

How so?

Apart from yanking word or a line, when you generally know what you yanked, most of the yanks are done via visual or block mode, and in those you know what is yanked because it is selected prior to yanking.

But that aside, like you said, you can view the registers, or you can install a plugin like YankRing (or some of its more simple coutnerparts). It gives you a wonderful feature to quickly (pff, unless you used some multiple clipboard manager, this is a bit harder to explain) switch between yanked texts. You press, p for paste, and from there you choose by let's say Ctrl-p what you want to yank in place. It's an amazingly practical and easy to get used to feature.

Upvotes: 2

romainl
romainl

Reputation: 196691

You can probably use '[ and '] that mark the beginning and end of the last yanked text but what is your purpose, exactly? Do you want to verify if what you've actually yanked corresponds to what you wanted to yank? Please clarify your question.

What you can do, instead, is reverse the whole process:

  1. use visual mode or visual-line mode to select visually what you want to yank
  2. yank it

This way you know exactly what you are going to yank and you can re-select it with gv.

Upvotes: 3

Related Questions