如何在vim中在不同模式下更改光标? [英] How to make cursor change in different modes in vim?

查看:36
本文介绍了如何在vim中在不同模式下更改光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 Vim 在不同模式下改变光标以满足这些条件:

How can I make Vim change cursor in different modes so that these conditions are satisfied:

  1. 不使用 gconftool 或此类工具.我只需要这影响 Vim 的一个实例,而不是整个终端.
  2. 这必须在 Gnome TerminalGVim 中工作.
  1. Without using gconftool or such tools. I need this affect only one instance of Vim, not the whole terminal.
  2. This must be working in Gnome Terminal and GVim.

PS:我尝试在 help gcr 中使用示例进行更改,但它仅适用于 GVim,而不适用于 Gnome 终端中的 Vim.

PS: I have tried changing with sample in help gcr, but it only works for GVim, and not Vim in Gnome terminal.

PPS:我已经测试了 http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes,但它改变了整个终端的光标.

PPS: I have tested http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes, but it changed the cursor for the whole terminal.

PPPS:优先使用gcr.

推荐答案

我之前也遇到过同样的问题并尝试了几个选项.

I've encountered the same problem before and tried a couple of options.

让我先总结一下:

选项 1:更改光标形状.
参考:http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes
结果:这对我不起作用

Option 1: Change cursor shape.
Ref: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes
Result: This won't work for me

选项 2:更改光标颜色.
参考:http://vim.wikia.com/wiki/Configuring_the_cursor
结果:这有效,但会在离开 vim 后更改终端光标.我不能接受.

Option 2: Change cursor colour.
Ref: http://vim.wikia.com/wiki/Configuring_the_cursor
Result: This works but will change terminal cursor after leaving vim. Not acceptable to me.

选项 3:更改光标线颜色
参考:如何更改 vim 光标插入/普通模式?

Option 3: Change cursor line colour
Ref: How do I change the vim cursor in Insert/normal mode?

最终结果:选项 3 最适合我,在主题中添加更多代码来定义 Cursor 颜色.

Final result: Option 3 works best for me, with a little more code to define Cursor colour in theme.

vimrc 中,添加以下内容:

In vimrc, add these:

autocmd InsertEnter * set cul
autocmd InsertLeave * set nocul

然后,在您的主题文件中,将Cursor设置为比背景暗一点.例如

Then, in your theme file, set Cursor to be a little darker than background. For example

hi Cursor ctermbg=black
hi Normal ctermbg=darkgray

添加这些设置后,当您进入视觉模式时,线条会变暗,以便您轻松识别.它在 Gvim 中的工作方式略有不同,但对我来说是完全可以接受的.此外,一旦你习惯了终端 vim,你就会完全忘记 Gvim.

After adding these settings, when you enter visual mode, the line will be darker so you can recognize it easily. It works a bit differently in Gvim but it's quite acceptable to me. Besides, you will forget Gvim totally once you get used to terminal vim.

这篇关于如何在vim中在不同模式下更改光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆