Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

vim, duplicate whole line to the end of each line?

How to copy the current line content to the end of each line for the whole file ?
For example:

From

hello 
world 
!

To

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

hello     hello 
world     world 
!         !

>Solution :

:%s/^\(.*\)$/\1 \1

  • % – whole file
  • s/^\(.*\)$ – match line from the beginning to end
  • /\1 \1 – replace it with matched text two times.

This won’t put them in a single column though if there aren’t trailing whitespaces, I’ve put here . as trailing whitespace:

# no trailing whitspaces
hello           hello
hello           hello
world           world
!           !

# with trailing whitespaces
hello           hello
hello           hello
world           world
!....           !....    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading