views:

171

answers:

3

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?

+7  A: 

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.

Peter
I deleted my answer because Peter's is the much better answer. +1!
Carl Smotricz
nice tip. How did you markup the key presses? I don't see "key" or "kbd" in the help... Or can I just do <kbd>?</kbd> I may have just answered my own question! :)
zen
heh heh. yes, you use the <kbd> tags.
Peter
careful with mapping over the "J" key, because by default that joins lines together (which personally I find very useful)
mpobrien
Nice, time to wrap it in .vimrc :)
Jay Zeng
I personally have control-j/k :nnoremap <c-j> ddp ... :nnoremap <c-k> ddkP . for both up and down. J is really handy and I dont recommend remapping it either. <c-k> isn't mapped and <c-j> isnt particularily useful
michael
just for reference, I picked `J` as an example only, and meant to pick `K` anyway (I've remapped `K` for something else, since the default function isn't very useful on `K`; I couldn't remember whether I'd used `J` or `K`).
Peter
+3  A: 

I typically just use:

Shift+v (selects the whole line)

and then

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

mpobrien
+1  A: 

I just had a go at expanding peter's answer to include a visualline mapping so you can do multiple lines at once. I personally prefer ctrlj / k but you can do whatever you like. Enjoy.

nnoremap <c-j> ddp
nnoremap <c-k> ddkP
vnoremap <c-j> dp'[V']
vnoremap <c-k> dkP'[V']
michael