I want a mapping that does it. Apparently, it is not that simple. Because first, it might decide to keep it commented when I press o. And it behaves differently if it was copied by yy, insists adding additional <CR>. My best effort so far is this:

function! MPf()
    let @+ =substitute(@+,"\<NL>$","",'')
    exec "norm x\"+]P"

nnoremap mp o <esc>:s/[^ \t]//ge<CR>:call MPf()<CR>

I add a space so that won't cancel indentation. I delete every comment like char in a new line.

But some combination of doing y/yy and when on indented line/unindent line originally still cause troubles. And somehow I don't get rid of the additional \0.

  • Simply ]p does this.
    – Matt
    Commented Nov 2, 2019 at 14:03
  • No, it doesn't. It only does it if it was copied by yy. Although you are right that I could identify this situation and apply ]p only if it happens.
    – eyal karni
    Commented Nov 2, 2019 at 14:04

1 Answer 1


The command ]p does almost what you want, except it is not guaranteed to be linewise.

In tpope/vim-unimpaired plugin it's already remapped to work linewise only, so if you use it (which I suggest anyway), you get it for free.

Otherwise, you can implement the same trick yourself:

nnoremap <silent>]p :call <SID>putline("]p")<CR>

function s:putline(how)
    let l:type = getregtype(v:register)
    call setreg(getreg(v:register), "V")
    execute 'normal! "' . v:register . a:how
    call setreg(getreg(v:register), l:type)

See plugin's source code for a more complete version.

  • It doesn't work linewise.
    – eyal karni
    Commented Feb 15, 2023 at 19:21

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.