Skip to content

Paste for windows - #35

Open
ptimothyp wants to merge 2 commits into
christoomey:masterfrom
ptimothyp:master
Open

Paste for windows#35
ptimothyp wants to merge 2 commits into
christoomey:masterfrom
ptimothyp:master

Conversation

@ptimothyp

Copy link
Copy Markdown

'paste' doesn't work in windows, the below settings work in windows.

let g:system_copy#copy_command='clip'
let g:system_copy#paste_command='powershell.exe -NoLogo -NoProfile -Noninteractive -Command "Get-Clipboard"'

'paste' doesn't work in windows, the below settings work in windows.

let g:system_copy#copy_command='clip'
let g:system_copy#paste_command='powershell.exe -NoLogo -NoProfile -Noninteractive -Command "Get-Clipboard"'
@christoomey

Copy link
Copy Markdown
Owner

Hi @ptimothyp, I'm surprised to see this. I'm not a windows user myself so I've just trusted what others have shared, but you're the first person (that I can remember) who has run into an issue, and my quick search points to paste being a valid command, so I'm wondering if the issue here is more specific to your setup. Most notably, it looks like you're in powershell, so I'm wondering if that is the source of the distinction? Also worth noting that the change you've made is only in the README, but the actual implementation is in the plugin file where it specifies the paste command.

Overall I'd want to understand better what's going on here before making a change. Any thoughts based on the above?

@ptimothyp ptimothyp changed the title Update README.md Paste for windows Feb 3, 2020
@ptimothyp

Copy link
Copy Markdown
Author

Hi @christoomey, thanks for your response. Thanks for pointing out that you can install a third party utility for paste. I was going along the lines of since, powershell is installed by default in most later versions of windows, why not just use the funtionality that comes along with the Operating system and use it as default... There is always the option to override it using the g:system_copy#paste_command command.

I've pushed an update, which uses the power-shell clipboard command as the default command. Leave it in you capable hands to make the decision. Thanks once again for this plugin, I find it very useful.. Thumbs-up to your awesome presentation which is what lead me to this plugin.

@NewComer00

NewComer00 commented Nov 21, 2022

Copy link
Copy Markdown
Contributor

Just to add that Windows might not use UTF-8 encoding by default.

On my Windows PC, the default regional setting is English (United States) and chcp command returns 437 in cmd.exe. Under this regional setting, I cannot copy & pasted Chinese and other special characters normally. If I copy some Chinese texts from a website, then paste them into Vim using cV (Get-Clipboard), the results are always something like ??????.

According to this discussion, I found two solutions:

  1. Add the command to change the chcp value to 65001 (UTF-8 encoding) in .vimrc.
    This solution affects the chcp value in the cmd shell launched by system() and :!, but will not affect the shell launched by :terminal.
    Only works in the non-GUI Vim in cmd or powershell.
if has('win32') && executable('powershell')
    " force cmd.exe to use utf-8 encoding
    call system('chcp 65001')
    let g:system_copy#paste_command='powershell.exe -NoLogo -NoProfile -Noninteractive -Command "Get-Clipboard"'
endif
  1. Change the default regional setting systemwide. According to this answer.
    Since the change is systemwide, it may bring some side effects. Take it carefully. Works in both non-GUI Vim and gVim.

As of (at least) Windows 10, version 1903, you have the option to set the system locale (language for non-Unicode programs) to UTF-8, but the feature is still in beta as of this writing.

To activate it:

Run intl.cpl (which opens the regional settings in Control Panel)
Follow the instructions in the screen shot below.
image
This sets both the system's active OEM and the ANSI code page to 65001, the UTF-8 code page, which therefore (a) makes all future console windows, which use the OEM code page, default to UTF-8 (as if chcp 65001 had been executed in a cmd.exe window) and (b) also makes legacy, non-Unicode GUI-subsystem applications, which (among others) use the ANSI code page, use UTF-8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants