0

I have a file that looks a bit like this

foo
! START
bar1
! END
foo
! START
bar2
! END
foo

Is there a way of yanking text that lives between the lines containing START and END patterns? I.e. to get

bar1 
bar2

I know that doing

g/START/+1y

would do it for this exact example, but I'm looking for a solution that copies all lines that are bound between some pattern or a start and end pattern, regardless of how many lines exist between them.

Help! :)

1 Answers1

3

You can use a global command

qqq
:g/! START/+1,/! END/-1 y Q

Explanation

qqq          -> clears the q register
:g           -> starts a global command
! START      -> search for 
+1           -> start a range at search match +1
/! END/-1    -> up until ! END -1
y Q          -> append into Q register
yolenoyer
  • 8,797
  • 2
  • 27
  • 61
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146