Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy matching text to register

Tags:

vim

editing

does anyone know if it is possible to concatenate matches resulting from a search into a single register? E.g, I have a file with following contents:

aaa :xxx 123
bb :y 8
ccccc :zzzzz 1923

Now what I want is to copy column starting with ':' somewhere else. Unfortunatelly I can't use visual block mode, because the first column hasn't fixed width. I thought that I could search for the second column (:\w+) and store the maches into a register.

like image 534
kyku Avatar asked Mar 07 '09 18:03

kyku


2 Answers

Another way:

:g/:/norm f:"Aye

Per :h quote_alpha, if you use an uppercase register name, it appends rather than replaces the contents of the register. If you run this and check the contents of register "a, you'll see

:xxx:y:zzzzz

(Possibly with linebreaks, depending on how you have cpoptions set.)

like image 178
Brian Carper Avatar answered Sep 20 '22 15:09

Brian Carper


You could make a macro:

qa (make a macro and store it in register a).

"Rye (yank to end of word and append it to register r - capital means append, lowercase overwrite.)

n (next match)

q (end recording)

If there are 10 matches, do 10@a Make sure register r is empty when you begin.

like image 42
Michiel de Mare Avatar answered Sep 20 '22 15:09

Michiel de Mare