简体   繁体   English

使用 macOS Terminal.app 进入插入模式时,如何在 Vim 中更改光标形状?

[英]How to change cursor shape in Vim when entering insert mode with macOS Terminal.app?

I want to change the cursor shape from an underscore to vertical when entering insert mode within VIM running in Terminal.app.在 Terminal.app 中运行的 VIM 中进入插入模式时,我想将光标形状从下划线更改为垂直。 (NOTE: I am aware that this is the default behavior under macvim.) (注意:我知道这是 macvim 下的默认行为。)

This reference: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes provides instructions on how to do this.此参考: http : //vim.wikia.com/wiki/Change_cursor_shape_in_different_modes提供了有关如何执行此操作的说明。 For example, the following works with iterm2:例如,以下适用于 iterm2:

let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"

Unfortunately, this does not work with Terminal.app (under Lion).不幸的是,这不适用于 Terminal.app(在 Lion 下)。

Are there any tricks for this with Terminal.app - or is this just not supported? Terminal.app 是否有任何技巧 - 或者这只是不受支持?

I'm absolutely certain I've seen an Applescript-based solution in the past but 5 minutes of google didn't bring anything.我绝对肯定我过去看过基于 Applescript 的解决方案,但 5 分钟的谷歌没有带来任何东西。 It was a little barbaric but it seemed to work… IIRC it changed the cursor shape preference on the fly and was triggered with an autocmd .这有点野蛮,但它似乎有效...... IIRC 它即时更改了光标形状首选项, autocmd触发。

Keep searching, it's somewhere.继续寻找,它在某个地方。

Are there any reason why you don't want to use iTerm?您是否有任何理由不想使用 iTerm?

I ran into this a similar problem myself, and found that this answer helped:我自己遇到了类似的问题,发现这个答案有帮助:

https://superuser.com/questions/712098/customize-vim-cursor-style-under-mac-os-x-terminal https://superuser.com/questions/712098/customize-vim-cursor-style-under-mac-os-x-terminal

When I started running vim inside tmux (still using terminal) the commands to change the cursor started working!当我开始在 tmux(仍在使用终端)中运行 vim 时,更改光标的命令开始工作!

Tmux is a really cool terminal manager that lets you have multiple terminal windows, tabs, split-screens, you name it, as well as save your sessions. Tmux 是一个非常酷的终端管理器,它可以让您拥有多个终端窗口、选项卡、分屏,您可以命名并保存会话。 Heres a nice tutorial I used to get it installed and useful:这是一个很好的教程,我用来安装它并且很有用:

http://fideloper.com/mac-vim-tmux http://fideloper.com/mac-vim-tmux

OP asked this question in August 2012. It's very unlikely that Terminal.app supported the ability to change the cursor shape to a vertical bar at that time, because Terminal.app as a general rule provides very few features that are not imitating xterm. OP 在 2012 年 8 月问了这个问题。当时 Terminal.app 不太可能支持将光标形状更改为垂直条的功能,因为 Terminal.app 作为一般规则提供了很少的功能,而不是模仿 xterm。 (The undocumented OSC 6 and 7 are the only exception to that rule which comes to mind). (未记录的 OSC 6 和 7 是该规则的唯一例外)。

xterm patch #282 about 6 weeks later introduced this feature as an extension to its emulation of DECSCUSR :大约 6 周后,xterm补丁 #282引入了此功能,作为对DECSCUSR模拟的DECSCUSR

extend DECSCUSR to provide a way to set the cursor to a vertical bar (patch by Paul Bolle).扩展 DECSCUSR 以提供一种将光标设置为垂直条的方法(Paul Bolle 的补丁)。

documented as follows:记录如下:

CSI Ps SP q
          Set cursor style (DECSCUSR), VT520.
            Ps = 0  ⇒  blinking block.
            Ps = 1  ⇒  blinking block (default).
            Ps = 2  ⇒  steady block.
            Ps = 3  ⇒  blinking underline.
            Ps = 4  ⇒  steady underline.
            Ps = 5  ⇒  blinking bar, xterm.
            Ps = 6  ⇒  steady bar, xterm.

As indicated in a similar question ( Customize vim cursor style under Mac OS X Terminal , July 2017) you can set vim's variables to use those escape sequences:如类似问题(2017 年 7 月在 Mac OS X 终端下自定义 vim 光标样式)所示,您可以设置 vim 的变量以使用这些转义序列:

let &t_SI="\033[6 q" " start insert mode (steady bar, xterm)
let &t_EI="\033[1 q" " end insert mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM