0

I am having issues with pasting text from the clipboard into Vim (v7.4) on an HPC cluster using Centos, which I have logged into using MTPuTTY. I still get the same error when I'm logging in via MobaXterm.

This is the result of pasting into e.g. sublime text:

enter image description here

Which is what's correctly on the clipboard.

However, when I try paste into Vim, using shift+insert, the output is truncated and contains some previous information that I had on the clipboard (i.e. the -Ou | \ part:

enter image description here

I have made sure I'm in insert mode. The issue seems to sporadically appear after using Vim for a while and the only thing that solves it is logging out of the HPC and logging back in again. I have absolutely no idea what's causing this.

I only have :color desert in my ~/.vimrc.

4
  • Have you tried to use p (paste) instead of shift + insert?
    – TornaxO7
    May 5, 2022 at 16:54
  • 2
    You are probably pasting with vim in normal mode (even though you mentioned that you made sure you're in insert mode). In normal mode, p pastes from the clipboard, yth yanks nothing, and o... opens a new line with the content that follows
    – husB
    May 6, 2022 at 14:44
  • @husB it is definitely always in insert mode. Unless there is a big and it says it's in isnert mode when it isn't.
    – user438383
    May 11, 2022 at 10:34
  • 1
    I saw you bumping the question again with a bounty.. Since you mention pasting from the clipboard, instead of shift+insert in insert mode, you could also paste directly from the clipboard, natively in vim. In normal mode, what about "+p or "*p?
    – husB
    Dec 20, 2022 at 7:15

2 Answers 2

0

You may try this:

function! PasteFormat(x)
    let l=@+
    let l=len(split(l,"\n"))-1
    return a:x."V".string(l).'j='
endfunction

nnoremap <expr> ]p @+ =~ ".*\n$" ?  PasteFormat("p") : ((@+ =~ ".*\n.*$") ? PasteFormat("o<ESC>p"): "o<C-R>+<ESC>")
nnoremap <expr> ]P @+ =~ ".*\n$" ?  PasteFormat("P") : ((@+ =~ ".*\n.*$") ? PasteFormat("O<ESC>p"): "O<C-R>+<ESC>")


You may also might want to filter out more special chars that cause the cursor to move.

I haven't tested it (you may write this as text).

0

Have you tried the command

:set paste

before pasting in insert mode?

Your Answer

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

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