vim关闭鼠标可视模式

364 阅读1分钟

vim关闭鼠标可视模式

本篇文章将介绍vim如何关闭鼠标可视模式。

如果你不习惯vim鼠标可视模式的话,不妨尝试来禁用它,首先需要确认vim的版本号。使用vim --version即可查询。

# vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, 编译于 May 04 2023 10:24:44)
包含补丁: 1-1378, 1499
修改者 team+vim@tracker.debian.org

可以看到该vim版本为9.0,需要编辑vim默认配置文件,即:/usr/share/vim/vim90/defaults.vim,注意,9.0版本的vimvim90,如果是其他版本的,直接替换路径即可。

使用mouse作为关键字,找到如下配置,9.0版本,大概位置在77行到88行之间。

# sed -n '77,88p' /usr/share/vim/vim90/defaults.vim
" In many terminal emulators the mouse works just fine.  By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
" Only xterm can grab the mouse events when using the shift key, for other
" terminals use ":", select text and press Esc.
if has('mouse')
  if &term =~ 'xterm'
    set mouse=a
  else
    set mouse=nvi
  endif
endif

#

然后只需要将这些配置给注释掉即可,注意,注释掉的语法是" ,注释后,配置如下:

# sed -n '77,88p' /usr/share/vim/vim90/defaults.vim
" In many terminal emulators the mouse works just fine.  By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
" Only xterm can grab the mouse events when using the shift key, for other
" terminals use ":", select text and press Esc.
"if has('mouse')
"  if &term =~ 'xterm'
"    set mouse=a
"  else
"    set mouse=nvi
"  endif
"endif

#

都屏蔽后,再次打开文件,则不会默认进入到鼠标可视模式了。

转载:wangli2025.github.io/2024/12/09/…