Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: Delete+Paste in one "command"?

I'm doing a lot of text manipulation between multiple files that requires a lot of yy, dd and ping. This may sound crazy but is there some shorter way of doing dd and p in one go? Maybe even with a plugin?

like image 863
meder omuraliev Avatar asked Dec 10 '09 23:12

meder omuraliev


People also ask

How do I delete multiple lines of code in Vim?

Deleting Multiple Lines in Vi and VimInstead of simply pressing dd, you can specify the number of lines you want to delete. For example, typing 3dd will delete the next three lines from the file. You can also use wildcard characters in the aforementioned command.

How do I delete a specific part of Vim?

Using the Shift + V Keys. We can select and delete specific texts using the Shift + V keys and then using the dd command.

How do I copy and paste an entire line in Vi editor?

Place the cursor on the line you wish to copy. Type yy to copy the line. Move the cursor to the place you wish to insert the copied line. Type p to insert the copied line after the current line on which the cursor is resting or type P to insert the copied line before the current line.


2 Answers

You can just make a map:

:map J ddp

and then J (or whatever you want) will do the combined operation.

Incidentally, I always map D to dd, since I delete entire lines much more often than to the end of the line. That makes it easy to use Dp to do your task.

like image 75
Peter Avatar answered Oct 05 '22 06:10

Peter


I typically just use:

Shift+v (selects the whole line)

and then

p (pastes over the selected line with your current register)

like image 43
mpobrien Avatar answered Oct 05 '22 08:10

mpobrien