duff18
duff18

Reputation: 752

In vim yank only text between brackets, not entire line

Let's say that I have some text like the one below, and I just want to yank the characters between and including brackets to register "a":

ss = 'Hello World'
a = ['a','b','c']
# this is a comment
b = ['c','d','e']

The best I came up with is (also taking into account this is done within a visual selection):

:'<,'> g/\[.*\]/y A

however this will yank the entire lines.

Upvotes: 0

Views: 429

Answers (1)

Hayden
Hayden

Reputation: 327

You can use the around syntax. ya[ yanks around including the brackets, and yi[ would yank the insides of it.

Refer to :h text-objects

Upvotes: 4

Related Questions