macvim icon indicating copy to clipboard operation
macvim copied to clipboard

shift-space produces escape sequence in terminal

Open smolin opened this issue 3 years ago • 5 comments

Steps to reproduce

  1. start macvim gui
  2. enter :term<enter> to start terminal mode
  3. enter od -c<enter> to start octal dump
  4. enter -space followed by followed by -D to end input
  5. observe output
% od -c
^[[32;2u
0000000 033   [   3   2   ;   2   u  \n
0000010

Expected behaviour

 I expect shift-space to produce a space character, 020

% od -t x1
 
0000000 20 0a
0000002

Version of Vim

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 24 2021 14:13:28) Included patches: 1-3455

Environment

OS: MacOS 10.15.7 and 12.0.1 terminal: MacVim 8.2.3455 TERM: xterm shell: GNU bash, version 5.1.12(1)-release (x86_64-apple-darwin21.1.0)

FWIW I tried a vanilla env without .bashrc .bash_profile and .vimrc with same result

Logs and stack traces

No response

smolin avatar Dec 17 '21 22:12 smolin

@smolin thank you. for an issue

Could you please to try this in Vim in terminal (with no GUI) and vanilla vim, like /usr/bin/vim?

eirnym avatar Dec 18 '21 01:12 eirnym

@eirnym Thanks for getting back to me. I tested just now with /usr/bin/vim and /Applications/MacVim.app/Contents/MacOS/Vim and both result in the expected behavior - results in char 020 AKA

Thanks! I love MacVim by the way, otherwise it's the bee's knees.

smolin avatar Dec 27 '21 16:12 smolin

See also https://github.com/vim/vim/issues/6040.

@smolin - this issue is fascinating and it definitely nerd sniped me. It's easily reproducible but I don't have enough arcane knowledge about terminal emulators to be totally sure that it's a bug in MacVim or even in Vim for that matter.

With iTerm 2 it's possible to make the issue happen or not happen at will with just /usr/bin/vim. By default, Shift+Space in a :term terminal results in a space being inserted. However, with Report modifiers using CSI u enabled, Shift+Space in a bash prompt in a :term terminal gives a ^[[32;2u. It also results in a ^[[32;2u in the regular shell with no vim involved at all.

The Fish shell (which doesn't use readline) supports CSI u as well; see this example of binding Shift-Space. Running that bind at a fish prompt inside a :term terminal results in a regular space character being inserted.

The Bash shell does not currently support CSI u as a result of its use of readline. From the second email on this thread from 18 April 2022 on the bug-readline list, support for CSI u isn't currently a priority:

I think I'll wait until more terminal emulators support this.

Vim appears to be sending reasonable CSI u codes to its subprocesses, though I can't find any explicit mention of CSI u support in https://github.com/vim/vim discussions.

From https://github.com/vim/vim/issues/6040#issuecomment-827176487:

As a workaround you can remap Shift-Space:

tnoremap <S-space> <space>

This mapping will break apps that expect to receive Shift-Space!

For example, the Shift+Space mapping that works in vim inside a vim terminal won't work.

Hope this helps clarify things even if it doesn't fix the issue. This might go away entirely as more applications start supporting CSI u.

mplough avatar Jun 05 '22 22:06 mplough

As it's Vim core issue, it's better to discuss it there and when comment here when it's resolved

eirnym avatar Jun 05 '22 23:06 eirnym

Thank you @mplough for linking the base issue

eirnym avatar Jun 05 '22 23:06 eirnym