Reputation: 3684
I know how to use the v
command in vim, but I need something which will delete an entire line and it should allow me to paste the same line somewhere else.
Upvotes: 272
Views: 201153
Reputation: 1018
Just three steps.
Upvotes: 7
Reputation: 8895
Delete current line and copy to clipboard:
d + d
Paste After The Cursor
p
Paste Before The Cursor
Shift + p
Select Whole Line (I use this ALL the time)
Shift + v
Then j or k to move down and up respectively
Essentially d + d is the equivalent of Shift + v then d
Upvotes: 54
Reputation: 94
esc
, and then Shift + v
.(This would have highlighted the line)
d
(The line is now deleted)
p
.In a nutshell,
Esc
-> Shift + v
-> d
-> p
Upvotes: 0
Reputation: 9419
The quickest way I found is through editing mode:
yy
to copy the line.dd
to delete the line.p
to paste the line.Upvotes: 13
Reputation: 1180
Pressing Shift+v would select that entire line and pressing d would delete it.
You can also use dd, which is does not require you to enter visual mode.
Upvotes: 102
Reputation: 18891
Let's say that you wanted to cut the line bbb
and paste it under the line ---
Before:
aaa
bbb
---
After:
aaa
---
bbb
bbb
---
Upvotes: 16
Reputation: 6727
There are several ways to cut a line, all controlled by the d
key in normal mode. If you are using visual mode (the v
key) you can just hit the d
key once you have highlighted the region you want to cut. Move to the location you would like to paste and hit the p
key to paste.
It's also worth mentioning that you can copy/cut/paste from registers. Suppose you aren't sure when or where you want to paste the text. You could save the text to up to 24 registers identified by an alphabetical letter. Just prepend your command with '
(single quote) and the register letter (a thru z). For instance you could use the visual mode (v
key) to select some text and then type 'ad
to cut the text and store it in register 'a'. Once you navigate to the location where you want to paste the text you would type 'ap
to paste the contents of register a.
Upvotes: 16
Reputation: 2325
Upvotes: 11
Reputation: 8565
dd
in command mode (after pressing escape) will cut the line, p
in command mode will paste.
Update:
For a bonus, d
and then a movement will cut the equivalent of that movement, so dw
will cut a word, d<down-arrow>
will cut this line and the line below, d50w
will cut 50 words.
yy
is copy line, and works like dd
.
D
cuts from cursor to end of line.
If you've used v
(visual mode), you should try V
(visual line mode) and <ctrl>v
(visual block mode).
Upvotes: 516
Reputation: 16202
Yep, use dd in command line. Also I recommend to print useful image with ViM hotkeys available at http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
Upvotes: 7