1

In init.vim I have the following setting to ensure the text is yanked to the system clipboard:

set clipboard^=unnamed,unnamedplus

In Neovim, I select the lines with visual line mode (V) and copy them with y:

a
b
c

In a webpage textarea, do Cmd+V / Ctrl+V, what's being pasted is:

a
b
c
  👈 an extra new line

I don't want the extra line when pasting. How to achieve that?

2 Answers 2

4

If you use the line mode selection (V) the yank (y) operation will yank the carriage return at the end of the line.

If you don't want the carriage return at end of the last line you have to use the normal selection mode (v)

  • On the first line use 0 to go to the start of the line
  • On the last line use g_ (instead of $) to go to the end of the line
2
  • Oh god, you can't imagine how long this issue has bugged me, thank you!
    – Wenfang Du
    Commented Mar 12, 2023 at 11:11
  • Thanks for the feedback :-) You are welcome ;-) Commented Mar 12, 2023 at 11:27
3

Inspired by Vivian's answer, I rewrote the visual line mode with:

map V 0v$
map Vk $v0k

Which doesn't have the extra line caused by the original visual line mode.

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.