incognito
incognito

Reputation: 199

Yank text between certain words or marks

Is there some vim-magic to yank between two strings?

As example:

#%%
some example
or

some other

#%%

I would like to yank everthing in between (#%%)? Like the "yi(" command.

Upvotes: 1

Views: 479

Answers (2)

D. Ben Knoble
D. Ben Knoble

Reputation: 4683

If you don’t care that :yank is linewise, you could do

:/#%%/+,/#%%/- yank

Since patterns count as addresses, we can write a range that selects the inner text, and then yank it.

Upvotes: 0

jeremysprofile
jeremysprofile

Reputation: 11445

y works with all motions, which includes /.

/#%% and then wyn would accomplish what you want, where

  • /#%%: search for the literal symbols #%%. As long as your cursor was above the section you want to yank, this will highlight the first instance.

  • wyn: move one word forward, to not include #%% in your yank (this assumes #%% is space separated from everything you want to yank). yn just means "yank all text until the next instance of the search".

Upvotes: 4

Related Questions