轉載自本人獨立博客: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)
重現步驟
- 在
iterm2
中使用cat
命令打印文件,然后用鼠標選中command + c
可以正常復制。 - 但是用
vim
打開文件,選中文字用command + c
復制,卻不能復制。 - 並且當鼠標點擊
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 去掉勾選
即可