djx99me
djx99me

Reputation: 115

Struggling with clipboard pasting in Vim

I am using Neovim 0.5 running on the Windows 10 command line terminal.

When I copy a value from a cell in Microsoft Excel or Libreoffice Calc e.g. "WORD", it is displayed in the "+ register as "WORD^J". The problem is that when I paste this value into Neovim using "+p or "+P, the inserted text always jumps to the line above where my cursor is.

I think that the ^J character/symbol is some kind of new line symbol that spread-sheets or Windows programs use for some reason but I can't be sure as there seems to be little info out there about it based off my time spent Googling.

I just want the text to be pasted clean at the exact point where the cursor is. I have tried adding the following to my vimrc (and various other lines of code) but can't succeed in stripping out the unwanted "^J" symbol. This substitution works for regular letters but not for "^J".

Does anyone know what this symbol is and how I can strip it from the "+ register before being pasted into vim?

Once I remove the symbol, I can update the mapping below to simply paste in the new contents of the "+ register.

nnoremap <C-v> :let @+ = substitute(@+, '^J', '', 'g') 

Thanks.

Upvotes: 0

Views: 695

Answers (1)

isAif
isAif

Reputation: 2354

You are right ^J symbol is for new line.

You can use the following to solve your issue:

:noremap <C-v> :let @+ = substitute(@+, "\n", "", "g")<CR>"+p

This modifies the + register to remove new line symbol and paste it.

Upvotes: 2

Related Questions