2

File Contains:

 aa bb cc dd 

I need:

 aa aa bb bb cc cc dd dd 

How can I do this??

1
  • Your best bet is to FORGET about "vim" and simply use "paste" from the command line or a shell script. IMHO... Commented Sep 2, 2013 at 8:37

7 Answers 7

6

You can do this with a regex:

%s/.*/& &/ 
Sign up to request clarification or add additional context in comments.

1 Comment

You don't have to group nor you need the begin of line ^ you can just :%s/.*/& &.
4

Perhaps there's a more clever way, but I would just enter visual block selection mode: ctrl+v, go to the last line: G, select all the way to the right: $, and yank: y.

Then you'll end up back at the first line. Press A to begin inserting at the end of the first line. Enter a space, leave insert mode and press p to paste in what you previously yanked.

3 Comments

It won't work if the length of text in each line is different.
set virtualedit=all and you can paste the block where ever you want without working about inserting extra white-space.
Wow! Interesting tip, @PeterRincker. Still need to decide if I like all this extra freedom :-)
1

If you are in a unix environment:

:'<,'>! awk '{print $0, $0}' 

Comments

1

Rectangular select the region to copy , yank it, then move point to the point where you want the text, then paste.

gg0 $<C-v>G<S-i> <esc> gg0 <C-v> eeGygg$p 

Comments

1

Now with ex commands!

:g/./y|pu|-j 

Long form:

:g/./yank|put|-1join 

This similar to doing yypkJ for every line (which you can do like :%norm yypkJ if you want).

For more help see:

:h :g :h :y :h :pu :h :j :h range :h :norm 

Comments

0

Go to the beginning of the line. Do yy in command mode, go to end of line do J. yy copies the current line to buffer, J joins the two lines.

Comments

0

I'd use a macro. Go to the top of the file, start recording with qq, then do whatever to duplicate the first line. Maybe YpkJ, or really anything that works to turn "aa" into "aa aa". Then stop recording with q again.

To apply to the rest of the buffer, use :2,$norm @q, or use visual mode to select all the lines until the end, and type :norm @q.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.