Question

here is a sample, [] means cursor:

vim is a text editor
[]great

We will dd at this point :

vim is a[] text editor

Then i want to paste the previous line in the middle of current line:

vim is a great[] text editor
Was it helpful?

Solution

if just focusing on the example in your question, you could do:

kJD3bp

short explanation:

k: move back to above line
J: join the line you want to delete, and added a space
D: remove the text from the line you just joined
3b:go to the 3rd word's beginning backwards
p: paste you just deleted text (by D)

if you want a generic solution, you may need wrap the middle calculation (line length /2) in a exec cmd or map <expr>

OTHER TIPS

I don't think there is any very simple way to do this; you will have to copy the text excluding the newline, delete the newline, paste it in and add the additional space on your own. You can create a shortcut for copying a line, adding a space to the end of it, and deleting that line via:

A<Space><Esc>^y$dd

Then the text with the space will be in the 0th register. Move the cursor to where you want it and paste with "0P. Based on where your cursor is you can do this via:

A<Space><Esc>^y$dd4w"0P

do not use "dd" but "dw" to delete the word, and "p" (paste after cursor) or "P" (paste before cursor) it.

if you insist on "dd": you need to paste it using:

[i] [Enter] [Esc] [p] [k] [J] [J]

using vim, you can also record macros, to do the "pasting" above:

 just start to record ([q][a], to record in "a" register), 
 then [i] [Enter] [Esc] [p] [k] [J] [J]
 then finish recording with [q]. 
 and then use it with : [@] [a] (ie "execute registered macro "a")

Of course, "timtowtdi" (gosh!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top