Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim yank/copy all multi-line patterns in file

I have a large file where I want to copy only portions of the file that match a regex (multiline) pattern. I found somewhere (probably StackOverflow) that I can do this:

:g/z=45117\.1[0-9]\{2}nm\_.\{-}end/y

This pattern found all the entries I was expecting, but the yank operation only yanked the first line of the first match found

What vim magic do I need to yank all lines of all matches of the multi-line pattern?

like image 494
jlconlin Avatar asked Nov 14 '25 14:11

jlconlin


1 Answers

Add an A with a space to the end of the command:

:g/z=45117\.1[0-9]\{2}nm\_.\{-}end/y A

It yanks the pattern into register a, so you might want to clear it before the command:

:let @a = ''
like image 186
Nima Hejazi Avatar answered Nov 17 '25 10:11

Nima Hejazi