0

On windows, using neovim, with clipboard=unnamedplus , when I paste from the system clipboard using p or :put , it will always paste in a newline , even if the content of the clipboard has no newline. (This issue happens in windows terminal and powershell or when using neovide as a gui app)

If I copy the content of my clipboard to notepad , it will just paste everything on the same line , so clearly there isn't a newline character inside my clipboard, but in nvim , it creates a new line and then pastes the content of the clipboard on that new line.

If I disable clipboard=unnamedplus , I get the behaviour I want when pasting something I yanked from inside neovim, but when I try pasting something from the system clipboard using "+p , it still gets pasted on a newline , even if there are no new line characters in my clipboard.

What am I missing? What I want is for pasting from the system clipboard to behave the same as if it was yanked from inside vim.

I've seen this question which is somewhat similar Inline paste from System Clipboard and the suggestion is to use a different mapping that trims the clipboard but I don't want a new mapping I just want to press p and not have some new line added to the clipboard that doesn't exist otherwise. If it's not possible I'd like to at least understand why neovim adds a new line here.

1 Answer 1

0

I have some updates at the end, this is very inconsistent in vim

It is due to the way you copied in Windows.

Open notepad, and type this:


123
12345
12345123456789

000
00000
000000000

Then keep the cursor on line 1, press shift+, until you get to line 5. Copy the text. It will be moved to Vim in line type, which we can see with :reg like this:

Type Name Content
  l  "*   ^J123^J12345^J12345123456789^J^J

The l indicates line type, and with p, P, or :put, Vim will paste with newlines. Rather, Vim will move to a newline and then paste.

Now, back to notepad. Put the cursor on line 6, press shift+, until you get to end of line 8. Copy the text. It will be moved to Vim in character type, which we can see with :reg like this:

Type Name Content
  c  "*   000^J00000^J000000000

The c indicates character type, and with p, P, or :put, Vim will paste without newlines. Rather, Vim will paste on the current line with the cursor.

With using mouse to select in notepad, I think, the type is character when last newline is not selected. When newline is selected, the type is line. It also varies within Vim, when the clipboard content is unchanged though the type is changed. It is inconsistent there.

Every time I check and recheck, I get different result in Vim, which seems to be inconsistent. Currently, I think, Vim uses the last character in the system clipboard to decide whether the type is line or character. If selecting single line or multiple lines with keyboard, with no terminal newline, then Vim makes it type c. If selecting single line or multiple lines with keyboard, with a terminal newline, then Vim makes it type l. Based on that, Vim will either paste on current line or paste on new line. This inconsistency issue will not occur when yanking within Vim, where Vim is aware about yanking characters or lines. When using system clipboard, there is no easy way to consistently make it type l or type c.

5
  • The Best work-around ( always works ! ) is this : while in insert mode , move the cursor to the Point where you want to paste , then type ctrl-r , then shift-8 , vim will paste your text right there , with no extra newlines , no matter whether that is type c or type l.
    – Prem
    Aug 4, 2023 at 12:19
  • Thank you for the answer, but unfortunately ctrl-r + shift-8 still pastes with new lines. The :reg command is useful to know, I was not aware of it. I've tried multiple ways of copying from windows and no matter what I do, including the way you mentioned I still get line types in my register. I also have this issue when yanking directly from vim when using clipboard=unamedplus but I don't have this issue when I disable this option. What I can only assume is that windows is doing something to the clipboard and vim isn't handling it correctly.
    – icesentry
    Aug 5, 2023 at 0:57
  • So, I've done a bit more investigation. When using vim pasting works perfectly between windows and vim. The issue only happens to me when using neovim even with a clean config. At this point it might be a bug in neovim and not just me doing something wrong.
    – icesentry
    Aug 5, 2023 at 1:13
  • (A) When you did ctrl-r + * & got the newline , was the text already ending in newline ? (B) If YES : It is Working Correctly : you got the text which was copied , including the newline. (C) If NO : It is a Definite Bug in vim or neovim : I too got that inconsistency. (D) Basic Core is that vim has no way to know whether that is l or c , hence it might be using vague heuristics !
    – Prem
    Aug 5, 2023 at 5:04
  • I managed to track down the issue. It was a bug in neovim that has now been fixed. It works like I would expect when using the latest pre-release of neovim 0.10 Here's the link to the PR that appears to have fixed my issue github.com/neovim/neovim/pull/22566
    – icesentry
    Aug 5, 2023 at 19:55

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.