equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.85k stars 171 forks source link

Double indenting when pasting with shortcut #948

Closed luqasz closed 2 years ago

luqasz commented 2 years ago

HI

I've added some mappings to behave same as other apps on mac:

inoremap <silent><D-v> <C-R>+
nnoremap <silent><D-v> "+p
cnoremap <silent><D-v> <C-R>+
vnoremap <silent><D-c> "+y
vnoremap <silent><D-v> c<C-R>+

When selecting some text (from e.g. a browser) with indent e.g.

It is possible to move the cursor after an abbreviation:
   :iab if if ()<Left>

You can even do more complicated things.  For example, to consume the space
typed after an abbreviation:

going to insert mode and hitting CMD+V causes text to be:

It is possible to move the cursor after an abbreviation:
   :iab if if ()<Left>

   You can even do more complicated things.  For example, to consume the space
   typed after an abbreviation:

Any idea what's going on ? Maybe I am mapping my keys wrong.

jgehrig commented 2 years ago

@luqasz

No, your mapping looks fine to me. I have a similar mapping for imap <S-Insert> <C-R>+, which also reproduces this issue.

It looks like this is an issue with the <C-R>+ sequence in insert or visual mode.

I have no problems with "+p or "+y in normal mode.

Here is a simplified minimal repro case:

inoremap <silent><D-v> <C-R>+
  1. Copy the text above (If is possible...)
  2. Go to insert mode (i)
  3. Press Ctrl + V, notice the "You can even" is indented.

This reproduces in nvim too. I'd recommend filing a bug upstream in the Neovim repository. This also could be an issue even further upstream in Vim, but the Neovim folks should be able to help locate the issue.

luqasz commented 2 years ago

In terminal nvim and vim everything works fine. I suspect that it works because CMD+V is a terminal emulator shortcut. I don't have this shortcut defined in nvim / vim (running in terminal). Sample text pastes just fine.

I have no problems with "+p or "+y in normal mode.

Yep. Works for me also

Do you think it's still worth reporting this to https://github.com/neovim/neovim ?

luqasz commented 2 years ago

I think I know what might be the issue. help 'paste' says that nvim has to be switched into paste mode so it doesn't think that when hitting CMD+V in insert mode is actual typing. I have smartindent etc. on, which results in those unwanted indents.

Now the question is how to tell nvim-qt that it has to switch into paste mode. from help 'paste':

This option is obsolete; |bracketed-paste-mode| is built-in.
jgehrig commented 2 years ago

@luqasz Sorry for the slow response.

Yes, let's file a bug upstream in Neovim. I can reproduce the issue in nvim and nvim-qt, which is usually a good indicator the issue lies in Neovim (or Vim).

I'm not familiar with the paste option, but it seams to break the mapping on my machine (Konsole Terminal).

Worst case, if this is actually in fact neovim-qt bug, hopefully the Neovim folks can provide some guidance.

zeertzjq commented 2 years ago

This is because of 'autoindent'. Vim behaves the same with 'autoindent' set.

luqasz commented 2 years ago

OK. Thx for help. Is there any way to temporary for pasting purposes disable autoindent ?

zeertzjq commented 2 years ago

You can try <C-R><C-O>+ or <C-R><C-P>+.

See :h i_CTRL-R, :h i_CTRL-R_CTRL-O, :h i_CTRL-R_CTRL-P.

luqasz commented 2 years ago

@zeertzjq Works. Thx