tags:

views:

7276

answers:

10

How do I duplicate a whole line in Vim in a similiar way to CTRL+D in IntelliJ IDEA/Resharper or Ctrl Alt Arrow in Eclipse?

A: 

Do this:

yy p

Eric Z Beard
+4  A: 

yy

will yank the current line without deleting it

dd

will delete the current line

p

will 'put' a line grabbed by either of the previous methods

pjz
A: 

1 gotcha: when you use "p" to put the line, it puts it after the line your cursor is on, so if you want to add the line after the line you're yanking, don't move the cursor down a line before putting the new line.

cori
+40  A: 
yy (copy the line)

or

dd (delete the line)

then

p (paste the copied or deleted text **after** the current line)

or

P (paste the copied or deleted text **before** the current line)
Mark Biek
Can also use capital Y to copy the whole line.
camflan
An excellent point. For some reason though, I find hitting y twice is faster for me than SHIFT-y
Mark Biek
+14  A: 

YP or Yp or yyp

Linulin
A: 

yyp - remember it with "yippee!"

Multiple lines with a number in between:

y7yp

theschmitzer
7yy is equivalent to y7y and is probably easier to remember how to do.
graywh
+5  A: 

If you want another way :-)

"ayy this will store the line in buffer a

"ap this will put the contents of buffer a at the cursor.

there are many variations on this.

"a5yy this will store the 5 lines in buffer a

see http://www.vim.org/htmldoc/help.html for more fun

Kwondri
+2  A: 

You can also try <C-x><C-l> which will repeat the last line from insert mode and brings you a completion window with all of the lines. It works almost like <C-p>

This is very useful, but to avoid having to press many keys I have mapped it to just CTRL-L, this is my map:inoremap ^L ^X^L
Jorge Gajon
A: 

Another option would be to go with:

nmap <C-d> mzyyp`z

gives you the advantage of preserving the cursor position.

ldigas
A: 

I like: Shift-V (to select the whole line immediately and let you select other lines if you want), y, p