Windows PowerShell remote ssh vim copy to clipboard not works #21790

Closed
opened 2026-01-31 07:54:59 +00:00 by claunia · 12 comments
Owner

Originally created by @soonsolidchentuo on GitHub (May 31, 2024).

Description of the new feature/enhancement

Login to Ubuntu through SSH in Powershell and edit files using Vim.

However, when I use "+y, I cannot copy the content to the Windows clipboard. Thank you.

Proposed technical implementation details (optional)

I hope it can copy content like putty. Thanks.

Originally created by @soonsolidchentuo on GitHub (May 31, 2024). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement Login to Ubuntu through SSH in Powershell and edit files using Vim. However, when I use `"+y`, I cannot copy the content to the Windows clipboard. Thank you. <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) <!-- A clear and concise description of what you want to happen. --> I hope it can copy content like putty. Thanks.
claunia added the Needs-TriageIssue-BugNeeds-Tag-FixNeeds-Attention labels 2026-01-31 07:54:59 +00:00
Author
Owner

@zadjii-msft commented on GitHub (May 31, 2024):

Huh. I was pretty sure we added support for OSC 52 in #5823 (a couple years back now).

Can you capture a script trace of trying to copy in vim this way/? That should tell us how exactly they're settings the keyboard.

@zadjii-msft commented on GitHub (May 31, 2024): Huh. I was pretty sure we added support for `OSC 52` in #5823 (a couple years back now). Can you capture a [`script` trace](https://github.com/microsoft/terminal/wiki/Troubleshooting-Tips#script) of trying to copy in `vim` this way/? That should tell us how exactly they're settings the keyboard.
Author
Owner

@plutonium-239 commented on GitHub (Jun 4, 2024):

I also face the same issue using the micro editor over ssh (which supports osc52). I will try to get a trace.

@plutonium-239 commented on GitHub (Jun 4, 2024): I also face the same issue using the micro editor over ssh (which supports osc52). I will try to get a trace.
Author
Owner

@soonsolidchentuo commented on GitHub (Jun 4, 2024):

Sorry I can't upload the trace file. So I update to my repository. trace file

The step:

  1. I open a power shell command
  2. ssh to server-android
  3. open a file by vim
  4. try using the v + "+y (ok)
  5. exit the vim
  6. try to use the shift + ins (failed)
  7. try to use the right mouse button ( failed)
@soonsolidchentuo commented on GitHub (Jun 4, 2024): Sorry I can't upload the trace file. So I update to my repository. [trace file](https://github.com/xunshichentuo/Soundex/blob/main/terminal-trace.etl) The step: 1. I open a power shell command 2. ssh to server-android 3. open a file by vim 4. try using the `v` + `"+y` (ok) 5. exit the vim 6. try to use the `shift + ins` (failed) 7. try to use the right mouse button ( failed)
Author
Owner

@zadjii-msft commented on GitHub (Jun 5, 2024):

Which ssh are you using? ssh.exe that ships with Windows? ssh from a WSL distro? Or some other ssh? And which version of ssh?

Did you make sure to configure vim to actually copy to the clipboard using OSC 52 (using something like https://github.com/fcpg/vim-osc52)/?

@zadjii-msft commented on GitHub (Jun 5, 2024): Which `ssh` are you using? `ssh.exe` that ships with Windows? `ssh` from a WSL distro? Or some other `ssh`? And which version of `ssh`? Did you make sure to configure `vim` to actually copy to the clipboard using OSC 52 (using something like https://github.com/fcpg/vim-osc52)/?
Author
Owner

@soonsolidchentuo commented on GitHub (Jun 6, 2024):

I tried to add a plugin named vim-osc52
It works by the command :Oscyank

PS C:\WINDOWS\system32> ssh -V
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2

I'm using the jonathonf/vim

sudo add-apt-repository ppa:jonathonf/vim 

sudo apt-get update  
sudo apt install vim 


vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37)
Included patches: 1-749
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3           +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          -ruby              +wildignore
+cursorbind        -lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            -X11
+digraphs          +mouse             -sound             -xfontset
-dnd               -mouseshape        +spell             -xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        +mouse_gpm         +statusline        -xsmp
+eval              -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "$VIM/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 -Wdate-time -g -O2 -fdebug-prefix-map=/build/vim-WrLx0u/vim-9.0.0749=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lselinux -lsodium -lrt -lacl -lattr -lgpm -ldl -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lm
@soonsolidchentuo commented on GitHub (Jun 6, 2024): I tried to add a plugin named [vim-osc52](https://github.com/fcpg/vim-osc52) It works by the command `:Oscyank` ```powershell PS C:\WINDOWS\system32> ssh -V OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 ``` I'm using the jonathonf/vim ```shell sudo add-apt-repository ppa:jonathonf/vim sudo apt-get update sudo apt install vim vim --version VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37) Included patches: 1-749 Modified by team+vim@tracker.debian.org Compiled by team+vim@tracker.debian.org Huge version without GUI. Features included (+) or not (-): +acl +file_in_path +mouse_urxvt -tag_any_white +arabic +find_in_path +mouse_xterm -tcl +autocmd +float +multi_byte +termguicolors +autochdir +folding +multi_lang +terminal -autoservername -footer -mzscheme +terminfo -balloon_eval +fork() +netbeans_intg +termresponse +balloon_eval_term +gettext +num64 +textobjects -browse -hangul_input +packages +textprop ++builtin_terms +iconv +path_extra +timers +byte_offset +insert_expand -perl +title +channel +ipv6 +persistent_undo -toolbar +cindent +job +popupwin +user_commands -clientserver +jumplist +postscript +vartabs -clipboard +keymap +printer +vertsplit +cmdline_compl +lambda +profile +vim9script +cmdline_hist +langmap -python +viminfo +cmdline_info +libcall +python3 +virtualedit +comments +linebreak +quickfix +visual +conceal +lispindent +reltime +visualextra +cryptv +listcmds +rightleft +vreplace +cscope +localmap -ruby +wildignore +cursorbind -lua +scrollbind +wildmenu +cursorshape +menu +signs +windows +dialog_con +mksession +smartindent +writebackup +diff +modify_fname +sodium -X11 +digraphs +mouse -sound -xfontset -dnd -mouseshape +spell -xim -ebcdic +mouse_dec +startuptime -xpm +emacs_tags +mouse_gpm +statusline -xsmp +eval -mouse_jsbterm -sun_workshop -xterm_clipboard +ex_extra +mouse_netterm +syntax -xterm_save +extra_search +mouse_sgr +tag_binary -farsi -mouse_sysmouse -tag_old_static system vimrc file: "$VIM/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 -Wdate-time -g -O2 -fdebug-prefix-map=/build/vim-WrLx0u/vim-9.0.0749=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lselinux -lsodium -lrt -lacl -lattr -lgpm -ldl -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lm ```
Author
Owner

@plutonium-239 commented on GitHub (Jun 6, 2024):

I'm using OpenSSH's ssh.exe

> ssh -V
OpenSSH_for_Windows_9.1p1, LibreSSL 3.6.1

Also, micro has inbuilt support for OSC52 (just a config flag clipboard: terminal which I have set).

@plutonium-239 commented on GitHub (Jun 6, 2024): I'm using OpenSSH's `ssh.exe` ```bash > ssh -V OpenSSH_for_Windows_9.1p1, LibreSSL 3.6.1 ``` Also, `micro` has inbuilt support for OSC52 (just a config flag `clipboard: terminal` which I have set).
Author
Owner

@carlos-zamora commented on GitHub (Jun 12, 2024):

Hmm... Could you use debug tap and share the output /? Thanks

@carlos-zamora commented on GitHub (Jun 12, 2024): Hmm... Could you use [debug tap](https://github.com/microsoft/terminal/wiki/Troubleshooting-Tips#enabling-the-debug-tap) and share the output /? Thanks
Author
Owner

@plutonium-239 commented on GitHub (Jun 12, 2024):

This is the relevant output I get from debug tap on selecting and copying:

16;42;0;1;48;1_␛[16;42;0;1;48;1_␛[16;42;0;1;48;1_␛[16;42;0;1;48;1_␛[38;72;0;1;304;1_␛[?25l␛[31m␛[36;1H␣36␣␛[m␛[7m␣␛[32m␛[27m␍␊
␣37␣␛[m␛[7mmodel␣=␣Sequential(...)␛[37m␛[44m␛[27m␛[50;13H6␛[1C1)␣|␣ft:markdown␣|␣unix␣|␣utf-8␣␛[38;72;0;0;304;1_␛[16;42;0;0;32;1_␛[17;29;0;1;40;1_␛[67;46;3;1;40;1_␛[m␍␊
Cop␛[1Ced␣selection␛[67;46;3;0;40;1_␛[17;29;0;0;32;1_␛[O

The words "Copied Selection" appear in the editor's UI, so that is also included in this

image

Attempt # 2:

␛[16;42;0;1;48;1_␛[40;80;0;1;304;1_␛[?25l␛[m␛[32m␍␣32␣␛[m␛[7m␛[9CExample␣␛[31m␛[27m␍␊
␣33␣␛[37m␛[44m␛[50;13H3␛[2C)␣|␣ft:markdown␣|␣unix␣|␣utf-8␣␛[40;80;0;0;304;1_␛[40;80;0;1;304;1_␛[m␛[32m␛[33;1H␣33␣␛[m␛[7m␣␛[31m␛[27m␍␊
␣34␣␛[m␛[7m```python␛[37m␛[44m␛[27m␛[50;13H4␛[2C0)␣|␣ft:markdown␣|␣unix␣|␣utf-8␛[40;80;0;0;304;1_␛[m␛[16;42;0;0;32;1_␛[17;29;0;1;40;1_␛[67;46;3;1;40;1_␛[67;46;3;0;40;1_␛[17;29;0;0;32;1_␛[O

image

@plutonium-239 commented on GitHub (Jun 12, 2024): This is the relevant output I get from debug tap on selecting and copying: ``` 16;42;0;1;48;1_␛[16;42;0;1;48;1_␛[16;42;0;1;48;1_␛[16;42;0;1;48;1_␛[38;72;0;1;304;1_␛[?25l␛[31m␛[36;1H␣36␣␛[m␛[7m␣␛[32m␛[27m␍␊ ␣37␣␛[m␛[7mmodel␣=␣Sequential(...)␛[37m␛[44m␛[27m␛[50;13H6␛[1C1)␣|␣ft:markdown␣|␣unix␣|␣utf-8␣␛[38;72;0;0;304;1_␛[16;42;0;0;32;1_␛[17;29;0;1;40;1_␛[67;46;3;1;40;1_␛[m␍␊ Cop␛[1Ced␣selection␛[67;46;3;0;40;1_␛[17;29;0;0;32;1_␛[O ``` _The words "Copied Selection" appear in the editor's UI, so that is also included in this_ ![image](https://github.com/microsoft/terminal/assets/29684689/fed7f549-fe0b-443a-80fc-8c2cbdd418c8) Attempt # 2: ``` ␛[16;42;0;1;48;1_␛[40;80;0;1;304;1_␛[?25l␛[m␛[32m␍␣32␣␛[m␛[7m␛[9CExample␣␛[31m␛[27m␍␊ ␣33␣␛[37m␛[44m␛[50;13H3␛[2C)␣|␣ft:markdown␣|␣unix␣|␣utf-8␣␛[40;80;0;0;304;1_␛[40;80;0;1;304;1_␛[m␛[32m␛[33;1H␣33␣␛[m␛[7m␣␛[31m␛[27m␍␊ ␣34␣␛[m␛[7m```python␛[37m␛[44m␛[27m␛[50;13H4␛[2C0)␣|␣ft:markdown␣|␣unix␣|␣utf-8␛[40;80;0;0;304;1_␛[m␛[16;42;0;0;32;1_␛[17;29;0;1;40;1_␛[67;46;3;1;40;1_␛[67;46;3;0;40;1_␛[17;29;0;0;32;1_␛[O ``` ![image](https://github.com/microsoft/terminal/assets/29684689/4791dab9-7dae-428b-a3f7-2aab26778113)
Author
Owner

@DHowett commented on GitHub (Jun 12, 2024):

Thanks! It looks like OSC 52 is not making it up to the terminal emulator at all (you'd expect to see ␛]52; somewhere in there!) I would recommend checking on how to configure vim + oscyank or micro to actually send OSC 52.

@DHowett commented on GitHub (Jun 12, 2024): Thanks! It looks like OSC 52 is not making it up to the terminal emulator at all (you'd expect to see `␛]52;` somewhere in there!) I would recommend checking on how to configure vim + oscyank or `micro` to actually send OSC 52.
Author
Owner

@plutonium-239 commented on GitHub (Jun 12, 2024):

how to configure vim + oscyank or micro to actually send OSC 52.

This is handled by setting "clipboard": "terminal" in micro's config, and this works on other terminal emulators (but I've only seen it work on a friend's machine - i.e. works on putty but does not on wt)
But your comment makes sense as well, maybe my ssh server + tmux combination is not sending OSC52s as expected.
Although, I've read that there are different forms of prefixes for control sequences, which are set in tmux terminal overrides (such as Ms=\\E]52;c;%p2%s\\7, could that be a problem?

@plutonium-239 commented on GitHub (Jun 12, 2024): > how to configure vim + oscyank or `micro` to actually send OSC 52. This is handled by setting `"clipboard": "terminal"` in `micro`'s config, and this works on other terminal emulators (but I've only seen it work on a friend's machine - i.e. works on putty but does not on wt) But your comment makes sense as well, maybe my ssh server + tmux combination is not sending OSC52s as expected. Although, I've read that there are different forms of prefixes for control sequences, which are set in tmux terminal overrides (such as `Ms=\\E]52;c;%p2%s\\7`, could that be a problem?
Author
Owner

@soonsolidchentuo commented on GitHub (Jun 13, 2024):

My solution is this:

  1. using "+y to copy the content.
  2. using :Osyank to copy to windows
@soonsolidchentuo commented on GitHub (Jun 13, 2024): My solution is this: 1. using `"+y` to copy the content. 2. using `:Osyank` to copy to windows
Author
Owner

@plutonium-239 commented on GitHub (Jun 15, 2024):

I finally found a solution! Copilot helped :)
Since I'm using tmux (v3.0a), that was not passing through the OSC52 escape sequences (as speculated above). The solution was to add a terminal override in my ~/.tmux.conf as follows:

set -as terminal-overrides ",xterm-256color:Tc:Ms=\\E]52;%p1%s;%p2%s\\007"

Note: change xterm-256color to whatever $TERM is outside of tmux, and the Tc just enables truecolor. (I figured it's good to mention here).

Now I can freely copy from micro without having to use the mouse to invoke wt's selection!

@plutonium-239 commented on GitHub (Jun 15, 2024): I finally found a solution! Copilot helped :) Since I'm using `tmux` (v3.0a), that was not passing through the OSC52 escape sequences (as speculated above). The solution was to add a terminal override in my `~/.tmux.conf` as follows: ``` set -as terminal-overrides ",xterm-256color:Tc:Ms=\\E]52;%p1%s;%p2%s\\007" ``` Note: change `xterm-256color` to whatever `$TERM` is outside of tmux, and the `Tc` just enables truecolor. (I figured it's good to mention here). Now I can freely copy from `micro` without having to use the mouse to invoke wt's selection!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21790