regexvimreplacevim-registers

remove newlines from a register in vim?


I have a long list of different names of universities. I'm trying to build a synonym table by collating lines with certain unique keywords; that is, in the file, I'll identify that Harvard is the keyword here:

Harvard Business School|
Harvard College|
Harvard School of Divinity|

and paste them into another file as

Harvard Business School|Harvard College|Harvard School of Divinity|

I have been doing this by searching for the word under the cursor, yanking lines with that word into register, pasting the register into the other file, and using the join command "J" to join the lines together:

[ clear register 'a' ]    
0"ay0
[ move cursor to 'Harvard" and yank lines with keyword into register a ]
:g/\<<CTRL-R><CTRL-W>\>/y A
[ move to other screen and paste ]
"ap
[ join lines ]
JJJJJ

This works just fine, but I'd like it to be streamlined. Specifically, I would like to know how to remove newlines from a register so that I don't have to use JJJJ to manually join the lines in the last step. I'd like to search for all lines containing the word under the cursor, copy them into the 'a' register, remove newlines from the 'a' register, then paste the contents of the 'a' register.

Any ideas?

EDIT: I know:

What I need to know:


Solution

  • To do it directly with text in register a you could use this command:

    :let @a=substitute(strtrans(@a),'\^@',' ','g')
    

    Then you should get results you want when you paste register a back in.