解决vim选中文字不能复制的问题

转载自本人独立博客:https://liushiming.cn/2020/01/18/vim-copy-issue-in-iterm2/

概述

最近发现在iterm2中打开vim,用鼠标选中文字,并用command + c复制选中的文字,但粘贴出来是空的。查了一圈终于在iterm2的官方gitlab issue库里发现了解决办法。将Enable mouse reporting这个设置去掉即可。

版本信息

操作系统
Mac os 10.15.2

iterm2
iterm2 3.3.6
iterm2 3.3.7

vim
Vi IMproved 8.1 (2018 May 18, compiled Dec 26 2018 02:33:06)

重现步骤

  1. iterm2中使用cat命令打印文件,然后用鼠标选中command + c可以正常复制。
  2. 但是用vim打开文件,选中文字用command + c复制,却不能复制。
  3. 并且当鼠标点击vim中的文字后,vim会自动变为visual模式。

解决方案

iterm2 > Preferences > Profiles > Terminal > Enable mouse reporting 去掉勾选

mouse reporting

mouse reporting的作用是在vim编辑时识别鼠标,可以支持鼠标滚轮查看文件内容(需要在.vimrc中加入设置支持鼠标set mouse=a)。关闭了mouse reporting后就不支持鼠标滚轮了。

那要使用鼠标滚轮怎么办?

可在iterm2 > preferences > advance > 搜索mouse > scroll whell down 那里写\j > scroll whell up那里写\k,作用就是发送j/k键到vim实现滚动效果。

更多信息

Mac自带的terminal也会有这个问题,在View > Allow Mouse Reporting 去掉勾选即可

猜你喜欢

转载自www.cnblogs.com/huahuayu/p/12235240.html