Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I yank the text matching a pattern?

Tags:

vim

I am trying to perform an action on a searched pattern but I can't figure out how to do that. The goal here is to be able to yank a pattern but so far I can only yank a whole line. Is there a trick that will make this command operate only on a matched pattern?

:/pattern.*/v
like image 629
Łukasz Avatar asked Jun 10 '16 13:06

Łukasz


1 Answers

If your Vim is recent enough (7.3.6xx), you can use gn in combination with :normal:

:/foo/normal ygn

To yank to a specific register:

:/foo/normal "aygn

See :help :normal and :help gn.

like image 72
romainl Avatar answered Nov 07 '22 22:11

romainl