WSL2环境下VIM的clipboard解决方案

WSL环境下VIM的剪切板无法与Windows共享

这是一个由来已久的问题,今天看到StackOverflow上一个堪称惊艳的解决方案,即便是VIM版本不支持clipboard特性(vim --version | grep clipboard查看是否支持),依然可以将VIM中的文本共享到Windows的剪贴板上。

使用clip.exe完美解决

Answer is, do a vim visual selection then do the command:

:'<,'>w !clip.exe

This pipes the current selection out to the shell command clip.exe, which utilizes WSL’s ability to execute Windows executables (even with a pipeline). Text piped to clip.exe goes to the Windows clipboard.

Also, this command saves the whole file to the clipboard (not the requirement):

:w !clip.exe

解释一下,clip.exe是windows平台上system32目录下的一个可执行程序。我们知道WSL可以使得Linux子系统访问到Windows的path路径(这也是WSL,相比传统虚拟机方式的优势),因此可以直接在VIM的命令模式下将选区内容(’<,’>w)以管道的方式传递给clip.exe程序,最终写入到windows的剪切板上。而且这种方式,可以直接将文件整个内容复制到剪切板,简直强无敌!

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值