microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.28k stars 8.27k forks source link

ViM mousing only partially works, works different across different platforms #10321

Open erichiller opened 3 years ago

erichiller commented 3 years ago

Windows Terminal version (or Windows build number)

1.9.1445.0

Other Software

Software Version
Windows Terminal 1.9.1445.0
PowerShell 7.1.1
ViM (Windows) 8.2 patches 1-2920
ViM (Git) 8.2 patches 1-2859
ViM (WSL) 8.1 patches 1-875
ViM (Remote) 8.1 patches 1-2269
OpenSSH 8.5p1

This is the newest ViM from the vim for windows github

Steps to reproduce

Install WT (Windows Terminal), ViM, Git, WSL for testing (see combinations tested below) Create vimrc-test file with the contents: set mouse=a

Run command with vim -u vimrc-test textfile where textfile is some file that is long enough to have room to scroll.

Expected Behavior

Clicking, Selecting, Scrolling to work across all Windows Terminal combinations (except for cmd.exe, I don't expect that)

Actual Behavior

Is scrolling supposed to work at this point? I've tested a number of options, and my findings are currently:

# Console Selection Click Scrolling Note
1 WT + WSL (Debian)
2 WT + PowerShell + Windows ViM
3 WT + PowerShell + Git ViM
4 WT + PowerShell + Remote ViM
5 ~WT + PowerShell + Windows ViM~ ~✔~ ~✔~ ~❌~ this is a duplicate of the above
6 WT + cmd + Windows ViM
7 WT + cmd + Git ViM
8 pwsh + PowerShell + Git ViM
9 pwsh + PowerShell + Remote Vim

By remote ViM I mean using ViM over an ssh connection to a linux machine.

Referencing #376

DHowett commented 3 years ago

I'm surprised at a bunch of these, actually. This is my understanding of how it should work, given some constraints:

EXPECTED

Console Selection Click Scrolling Note
[1] WT + WSL (Debian) Terminal v0.9, this was #545
[2] WT + PowerShell + Windows ViM Surprised scrolling doesn't work after 8.2 p 2913
[3] WT + PowerShell + Git ViM Patch 2913 is required
[4] WT + PowerShell + Remote ViM Patch 2913 is required
[5] WT + PowerShell + Windows ViM Duplicate of 2?
[6] WT + cmd + Windows ViM This should be identical to 2
[7] WT + cmd + Git ViM This should be identical to 3
[8] pwsh + PowerShell + Git ViM Longstanding mouse support in conhost :smile:
[9] pwsh + PowerShell + Remote Vim As in 8

I'll work on figuring out what's actually going on here...

Are you using ssh from within WSL or from Windows (ssh.exe)?

skyline75489 commented 3 years ago

I can confirm that with 8.2 patches 1-2932 I can only see selection & click works, but not scrolling.

Link to patch 2913 https://github.com/vim/vim/commit/6ef5ab59043681a51e8ca2ab0a1e4ff8f0f4bb47

erichiller commented 3 years ago

@DHowett The ssh I'm using is from git @ C:\Program Files\Git\usr\bin\ssh.exe
You are correct on Number 5, I numbered mine and crossed 5 out as duplicate for ease of reading.

Also, I am not sure what happened with my test before using cmd, (Number 6) but it does behave the same as Number 2. Meaning, Selection & Clicking work, but not Scrolling. I updated my initial table to reflect the changes.

DHowett commented 3 years ago

ALRIGHT! I think I've cracked it. Here's my updated table...

Console Selection Click Scrolling Note
[1] WT + WSL (Debian) Terminal v0.9, this was #545
[2] WT + PowerShell + Windows ViM Surprised scrolling doesn't work after 8.2 p 2913, see note 2
[3] WT + PowerShell + Git ViM Patch 2913 is required
[4] WT + PowerShell + Remote ViM Patch 2913 is required
[5] WT + PowerShell + Windows ViM Duplicate of 2?
[6] ~WT + cmd + Windows ViM~ ~✔~ ~✔~ ~❌~ ~This should be identical to 2~
[7] WT + cmd + Git ViM This should be identical to 3
[8] pwsh + PowerShell + Git ViM Longstanding mouse support in conhost :smile:, see note 2
[9] pwsh + PowerShell + Remote Vim As in 8, see note 3

Notes

  1. When Vim detects that it is running on Windows, it uses Windows mouse events and Windows console events. Running in Cygwin/MSYS2 can add another layer of complexity here, as the existence of mouse events depends on $TERM and the Cygwin runtime version (only 3.1+ support "let the windows console control how input is generated")

  2. I can find no mention of scrolling in vim's Windows code (the "MOUSE_WHEELED" event flag). I also can't get it to scroll outside of Terminal (!)

  3. Depends on what you're remoting to! If Linux, you're hitting the well-tested Linux remoting code. If you're using a Cygwin SSH client, see note 1 (!)

jclark42796 commented 3 years ago

On Win10, having a similar issue where mouse scroll up works but mouse scroll down does not. Using putty to ssh to a Linux 2 server to edit with vim 8.1 (included patches 1-1602). Same putty client with vim 8.0 (patches 1-503, 1365) does not have this issue.

silverqx commented 3 years ago

I want to ask, should scrolling work for pure vim on windows in windows terminal? For me, it does not.

WinTerm - 1.11.2421 Vim - 8.2.3452

It only works if I ssh to my Gentoo virtual machine and run vim there (from the WinTerm or from the cmd terminal) and it also works when I start vim from MSYS2 mingw64.

Left-click works for me in all the above-described environments.

I have tried different settings, --clean param, and also tried to disable QuickEdit Mode. Scrolling does not work also in the cmd and PowerShell terminals.

silverqx commented 3 years ago

Now I have tried neovim and scrolling is working like expected, it looks like a bug in the vim itself.

xaljer commented 2 years ago

I use Neovim over an ssh connection to a linux machine, scrolling and clicking are not work.

xaljer commented 2 years ago

@DHowett hi, what do you mean by "Patch 2913 is required"?

DHowett commented 2 years ago

@DHowett hi, what do you mean by "Patch 2913 is required"?

If you are using Vim 8.1 or 8.2, you need to have a patch version greater than or equal to 2913.

xaljer commented 2 years ago

https://github.com/neovim/neovim/pull/14328 It looks like neovim already have this patch? I use neovim over SSH, mouse does not work.

DHowett commented 2 years ago

I am not sure about the mapping of neovim versions to vim versions. My advice applies only vim. The neovim maintainers will need to accept a similar patch.

xaljer commented 2 years ago

I use neovim over SSH in https://github.com/Eugeny/tabby, mouse actions work fine. So I think it's not neovim's issue.

DHowett commented 2 years ago

I use neovim over SSH in https://github.com/Eugeny/tabby, mouse actions work fine. So I think it's not neovim's issue.

Please file a separate issue! This one is specific to traditional vim :)

zewpo commented 2 years ago

This is caused by the Vim compiled for windows consoles, the source code does not have mouse scroll handling in windows consoles. I had a go, and it was simple to add it, so I have just developed a pull request for vim. https://github.com/vim/vim/pull/11374

DHowett commented 1 year ago

This is caused by the Vim compiled for windows consoles, the source code does not have mouse scroll handling in windows consoles. I had a go, and it was simple to add it, so I have just developed a pull request for vim. vim/vim#11374

watching with rapt attention!

Thanks for doing this!

zewpo commented 1 year ago

Can help me by testing the new windows console mouse scroll event handling now in Vim 9, from at least Patch 9.0.0812. I did a few submissions and patches, I've only been manually testing it myself so far. Feedback is very welcome.

silverqx commented 1 year ago

Omg, many thx @zewpo, we can finally scroll in vim on Windows 🙌🤙, I had tried to create a similar patch like this, and I created a scrolling handler in src/os_win32.c and was able to scroll the vim screen buffer up/down but in a hacky way, it was too much for me and I failed because I didn't know how to scroll the vim buffer correctly, exactly I didn't know how or what I should write to the vim stream buffer to scroll correctly.

But your PR works perfectly and I'm so grateful for this 🙏I have installed vim 9.0.801 and it just scrolls up/down without problems.

BDisp commented 1 year ago

I'm also facing this issue where the mouse only partially work by open a WSL 2 distro in the Windows Terminal. I'm not using VIM but the https://github.com/gui-cs/Terminal.Gui. On a full screen only the left half of the columns responds to mouse events and right don't. Before the mouse wasn't working on Windows (with PowerShell or CMD) and worked well with WSL 2. Now the mouse works well on Windows on all columns and the WSL 2 only works on the left half side of a full screen. Is there any intention to fix this, please?

DHowett commented 1 year ago

@BDisp thanks for reporting! Just a couple notes:

  1. This issue is specific to vim; if you're having another issue with a non-vim application it would be best to track it in a separate issue.
  2. The problem you are seeing is a well-known limitation of "X11" mouse reporting, where the X and Y coordinates are limited to about 93 (or 97? Roughly half of a screen on most displays.). Terminal.Gui should be requesting the much newer and much more flexible "SGR" mouse reporting, which has no practical limit on coordinate values. You will need to make a feature request to Terminal.Gui.

I'm going to mark this comment and the preceding one as "off topic" since they aren't specific to Vim.

Thanks!

ben-foxmoore commented 1 year ago

I have the same issue as @BDisp but specifically in ViM.

I'm using Microsoft Terminal with WSL2 (ArchLinux) and ViM 9.0. Text selection/interaction and scrolling is only working on the left half of the terminal (in my case, it seems to work for the first 95 characters). This issue is only present inside of ViM - when at the prompt, I can select text and scroll regardless of where the cursor/mouse is.

@DHowett You mentioned "SGR" reporting in your comment - I noticed that ViM lists this in the included features when using :version:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Oct 22 2022 19:58:44)
Included patches: 1-813
Compiled by Arch Linux
Huge version without GUI.  Features included (+) or not (-):
+acl               -clientserver      +diff              +folding           +langmap           +mouse_dec         +num64             +reltime           +syntax            +title             +wildmenu
+arabic            -clipboard         +digraphs          -footer            +libcall           +mouse_gpm         +packages          +rightleft         +tag_binary        -toolbar           +windows
+autocmd           +cmdline_compl     -dnd               +fork()            +linebreak         -mouse_jsbterm     +path_extra        +ruby/dyn          -tag_old_static    +user_commands     +writebackup
+autochdir         +cmdline_hist      -ebcdic            +gettext           +lispindent        +mouse_netterm     +perl/dyn          +scrollbind        -tag_any_white     +vartabs           -X11
-autoservername    +cmdline_info      +emacs_tags        -hangul_input      +listcmds          +mouse_sgr         +persistent_undo   +signs             +tcl/dyn           +vertsplit         -xfontset
-balloon_eval      +comments          +eval              +iconv             +localmap          -mouse_sysmouse    +popupwin          +smartindent       +termguicolors     +vim9script        -xim
+balloon_eval_term +conceal           +ex_extra          +insert_expand     +lua/dyn           +mouse_urxvt       +postscript        -sodium            +terminal          +viminfo           -xpm
-browse            +cryptv            +extra_search      +ipv6              +menu              +mouse_xterm       +printer           -sound             +terminfo          +virtualedit       -xsmp
++builtin_terms    +cscope            -farsi             +job               +mksession         +multi_byte        +profile           +spell             +termresponse      +visual            -xterm_clipboard
+byte_offset       +cursorbind        +file_in_path      +jumplist          +modify_fname      +multi_lang        -python            +startuptime       +textobjects       +visualextra       -xterm_save
+channel           +cursorshape       +find_in_path      +keymap            +mouse             -mzscheme          +python3/dyn       +statusline        +textprop          +vreplace
+cindent           +dialog_con        +float             +lambda            -mouseshape        +netbeans_intg     +quickfix          -sun_workshop      +timers            +wildignore
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -g -ffile-prefix-map=/build/vim/src=/usr/src/debug -flto=auto -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.36/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto=auto -L/usr/local/lib -o vim -lm -ltinfo -lelf -lacl -lattr -lgpm -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.36/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto -fstack-protector-strong -L/usr/local/lib -L/usr/lib/perl5/5.36/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm

Is there any way I can test if this mode is being requested and used properly by ViM?

DHowett commented 1 year ago

Is there any way I can test if this mode is being requested and used properly by ViM?

Honestly, I'm not sure how to tell whether it's using it properly... but I think that we can figure out whether it's requesting it with :set ttymouse (or :set ttym). If it reports anything other than ttymouse=sgr, it's not requesting it.

Whether it does that automatically is probably based on a number of things like $TERM and the terminfo. In any case, it can be overridden with :set ttym=sgr!

ben-foxmoore commented 1 year ago

Aha! ViM isn't requesting it:

:set ttym
ttymouse=xterm

Forcing it using :set ttym=sgr completely fixes the problem - thanks for that! I'll try to investigate why ViM isn't requesting it by default (in my setup/configuration).