How to copy the current line content to the end of each line for the whole file ? For example:
From
hello
world
!
To
hello hello
world world
! !
:%s/^\(.*\)$/\1 \1
%
- whole files/^\(.*\)$
- match line from the beginning to end/\1 \1
- replace it with matched text two times.There may be a problem with formatting those lines in columns. Here is an example:
hello hello
hello hello
world world
! !
This can be solved with addition of trailing spaces, the the shorter lines, like this: (.
- denotes trailing space)
hello hello
hello hello
world world
!.... !....
As mentioned by @mattb in the comment, column formatting issue can be fixed with column
command (it has to be on your PATH though):
:%s/^\(.*\)$/\1 \1/ | %!column -t