2

I want to repeat a chunk of text in Vim.

I want to copy the following line:

truncate `Portal20`.`client_types` 

and repeat it x number of times.

Example: 5 times

truncate `Portal20`.`client_types` truncate `Portal20`.`client_types` truncate `Portal20`.`client_types` truncate `Portal20`.`client_types` truncate `Portal20`.`client_types` 

I have done some research, but unable to locate a good resource.

2
  • If you want to learn how to do things efficiently in Vim: vimgolf.com Commented Feb 14, 2013 at 7:36
  • If you happen to also have to write that line yourself, you could also use 5o[your line]<ESC>. Commented Feb 14, 2013 at 19:45

3 Answers 3

8

Move the cursor to the line you want to copy, then press

yy 

Then, press:

5p 

Another nice technique (that also works for copying multiple lines) is to move the cursor to the line to copy, and select the line (in linewise-visual mode) by pressing

Shift+v

Press y to copy the line (or use the direction keys to move up or down to select more lines before copying).

Then press 5p as mentioned above to paste the copied block 5 times.

More documentation on visual mode is available in the documentation at: http://vimdoc.sourceforge.net/htmldoc/visual.html

Sign up to request clarification or add additional context in comments.

Comments

4

In normal mode with your cursor anywhere on the line you wish to copy:

Y5p

(Par 3)

Explanation (keys are hyperlinks to the online :help):

  • Y : Yank the line
  • 5 : times
  • p : put the yanked text after the cursor

1 Comment

By default, Y yanks the whole line, not to the end of it.
3

Have you tried yy5p ? It copies the line your cursor is at, and paste it 5 times below it.

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.