Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
erichiller opened this issue Jun 3, 2021 · 23 comments
Assignees
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conpty For console issues specifically related to conpty Product-Terminal The new Windows Terminal.
Milestone

Comments

@erichiller
Copy link

erichiller commented Jun 3, 2021

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

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jun 3, 2021
@DHowett
Copy link
Member

DHowett commented Jun 3, 2021

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 😄
[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)?

@DHowett DHowett added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 3, 2021
@skyline75489
Copy link
Collaborator

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

Link to patch 2913 vim/vim@6ef5ab5

@erichiller
Copy link
Author

@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.

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jun 4, 2021
@DHowett
Copy link
Member

DHowett commented Jun 4, 2021

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 😄, 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
Copy link

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
Copy link

silverqx commented Sep 25, 2021

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
Copy link

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

@xaljer
Copy link

xaljer commented Oct 20, 2021

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

@xaljer
Copy link

xaljer commented Dec 18, 2021

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

@DHowett
Copy link
Member

DHowett commented Dec 18, 2021

@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
Copy link

xaljer commented Dec 18, 2021

neovim/neovim#14328
It looks like neovim already have this patch? I use neovim over SSH, mouse does not work.

@DHowett
Copy link
Member

DHowett commented Dec 18, 2021

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
Copy link

xaljer commented Dec 19, 2021

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
Copy link
Member

DHowett commented Dec 19, 2021

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 :)

@zadjii-msft zadjii-msft added Product-Conpty For console issues specifically related to conpty Area-Input Related to input processing (key presses, mouse, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Product-Terminal The new Windows Terminal. Priority-1 A description (P1) and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Attention The core contributors need to come back around and look at this ASAP. labels May 16, 2022
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 16, 2022
@zadjii-msft zadjii-msft added this to the 22H2 milestone May 16, 2022
@zewpo
Copy link

zewpo commented Oct 15, 2022

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

@DHowett
Copy link
Member

DHowett commented Oct 17, 2022

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
Copy link

zewpo commented Oct 21, 2022

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
Copy link

silverqx commented Oct 23, 2022

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

This comment was marked as off-topic.

@DHowett

This comment was marked as off-topic.

@ben-foxmoore
Copy link

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
Copy link
Member

DHowett commented Nov 22, 2022

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
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conpty For console issues specifically related to conpty Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

10 participants