4

I observed a difference in behavior between Vim and Neovim: When pasting a :-prefixed command in normal mode, Vim will enter command mode whereas Neovim will enter insert mode. More precisely:

  • Given the selection buffer contents :echo "foo" (e. g. printf ':echo "foo"' |xsel),
  • and Vim/Neovim running in a terminal and currently in normal mode,
  • then when pasting the selection buffer with middle click or <S-Insert>
  • Vim will enter command mode and paste the contents there,
  • Neovim will enter insert mode at the current cursor position and paste the contents there.

(FWIW I have set mouse= in both, but as stated above the behavior is the same using the keyboard. Both Vim and Neovim are in nopaste state.)

I strongly prefer the Vim behavior as there’s more convenient ways of pasting into the buffer. Is there a way to make Neovim behave the same as Vim when pasting?

2
  • 1
    Good question. I'm trying to find which function in vim is called when something is pasted from the outside (with gdb). It's hard cause the paste-related functions in vim and nvim aren't named the same. vim has bracketed_paste (which isn't the one responsible for pasting from the outside, btw); nvim has handle_bracketed_paste.
    – 3N4N
    Sep 13, 2022 at 9:04
  • In theory, NeoVim's behavior is safer. On macOS + Vim, echo ':echo "foo"' | pbcopy, vim, Cmd-V leaves me with the command and a blank line in the buffer and in Normal mode. (This sounds closer to your NeoVim behavior, and may or may not have been affected by bracketed paste.)
    – D. Ben Knoble
    Sep 13, 2022 at 12:22

1 Answer 1

4

Instead of using Shift-Insert to insert the marked text, use Vim registers. So first copy your line using a yank command like 0y$ and then use :CTRL-R0 to paste it into the command line.

Note: depending on how you yanked it, you may need to remove the trailing Linefeed. This happens e.g. when using yy to yank a complete line.

See :h c_CTRL-R

2
  • That’s an option when your hands are already at the keyboard but as I wrote I’m using the mouse selection as well so your suggestion introduces one more annyoing back-and-forth between mouse and keyboard. In contrast, middle-click paste works consistently pretty much everywhere except Nvim.
    – phg
    Sep 15, 2022 at 9:17
  • Well, first of all, <Shift-Insert> is received by the terminal, so vim/nvim does not know this is a paste action. So you need to disable bracketed paste mode. I don't know how to do this in nvim, for Vim you can set the terminal option t_BE to empty. I don't know nvim enough. And then finally if there is no other way, try to change the way you are yanking and pasting to achieve your goal. Sep 16, 2022 at 10:22

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.