Many times in vim I would like to delete a line completely, so I use dd. However, I then need to paste that line into some other position within a line, but this inserts a newline before pasting, therefore, making it very difficult for me to get the desired result. For example,

while( pasteInHere )
    cin >> n; // Delete this line completely with dd

when I do this with the above code I get:

while( pasteInHere )
cin >> n; // Delete this line completely with dd

which is very far from the result I want...how can I suppress this newline behaviour, or use another method that does it very efficiently? I don't think d$ is good because I not only have to go to beginning of line, but if I want to delete the empty line too I need to delete it in another register, I feel like there should be an easier way! Thanks.

  • 2
    possible duplicate of Can I delete an entire line, except the line break? Jul 14, 2015 at 20:37
  • 1
    it is not a duplicate, as I said I want a more efficient way then going to beginning of line, also I actually want to remove the complete line with the newline character....not just the contents of the line
    – fYre
    Jul 14, 2015 at 20:42
  • Oh, I do see what you mean now. It just wasn't very clear to me what you were trying to accomplish. Jul 14, 2015 at 20:48
  • 1
    0D delete line except line break. And than gJ to join lines. Now you can put the text without break line and no empty line.
    – Alex Kroll
    Jul 14, 2015 at 22:02

7 Answers 7


You can go anywhere in the line above the line you want to delete, then press JD and paste it with p at the desired point.

  • J joins the two lines and moves you at the start of the text you wanted to delete. This deletes a new-line character and the indentation of the line you want to move.
  • D deletes from the current cursor position to the end of the line but preserves the new-line character.

Hint: You can use :pu if you deleted with D or yanked with y$ and you want to paste with a new line.


You can achieve something that works quite well with an imap. Add the following to your vimrc:

inoremap <c-a> <c-r>1<esc>k$Jxi

This will create a mapping for CTRL-a that will paste the last deleted text (with dd or similar). If you prefer, you may of course use a different key for the mapping.


:h i_CTRL-R
:h quote1
:h J

Not really simpler, but slightly more efficient, and you can also create normal-mode maps for both sequence:

  • yanking: go to the line you want to move, then ^D"_dd
  • pasting: go to the word you want to replace, then viwp

Paste without new line

Put this in your .vimrc file:

" Paste yanked line without line breaks before/after cursor position
nnoremap gP i<CR><Esc>PkJxJx
nnoremap gp a<CR><Esc>PkJxJx


<span style="color:">danger</span>

Now you can type gp to insert #D51B3F after color: while my cursor is at : in Normal mode.

Yank without new line

Use flukus' answer:

" Delete current line without yanking the line breaks
nnoremap dil ^d$

as acronym of delete inner line. This also gets rid of leading indentation.


This comes up for me a bit too, never thought to optimize it before but this mapping works:

nmap dil ^d$

dil is "delete in line", similar to diw, di", etc.


You can select the text you want to copy by pressing v and then take it into buffer by pressing y and then paste it anywhere by p. It don't inserts any new line.

  • True, but this still leaves a blank line.
    – muru
    Jul 21, 2015 at 7:08

Pasting deleted line, without new-line:

Althought It took me quite a while, thankfully I evetually found out how (PS. i'm new to VIM)

  • For VI\VIM and .vimrc, use:
nnoremap dil dd:let @+=matchlist(strtrans(@+),'[ ]*\zs.*\ze\^@')[0]<CR>
  • For NVIM and init.lua (like me), use:
vim.keymap.set('n', 'dil', "dd:let @+=matchlist(strtrans(@+),'[ ]*\\zs.*\\ze\\^@')[0]<CR>")


enter image description here

Regex explained

  • Regex [ ]*\zs.*\ze\^@:
    • [ ]*\zs look (behind) for potential spaces
    • .* and then match anything, only if
    • \ze\^@ at the end there is a ^@


  • This relies on @+ which is a clipboard register and is only written by dd based on the 'clipboard' settings. Instead, you might want to use @" or v:register
    – D. Ben Knoble
    Jun 13, 2022 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.