gpt4 book ai didi

vim - 如何在 Gnome 终端的不同模式下更改 VIM 光标形状

转载 作者:行者123 更新时间:2023-12-04 02:26:34 25 4
gpt4 key购买 nike

我想根据我当前所处的模式更改 VIM 的(不是 gVIM 的)光标。我想:

  • 普通和可视模式 = 块光标
  • 插入和命令模式 = I 光束光标

  • 我尝试将以下代码添加到 .vimrc但它没有用。
    if has("autocmd")
    au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
    au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
    au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
    endif

    我从 http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes 得到了那一点代码但它说它适用于 Gnome-Terminal(2.26 版),而我有 Gnome-Terminal(3.60 版)。不确定这是否是它不起作用的原因。

    关于如何做到这一点的任何想法?

    最佳答案

    我有 gnome-terminal 3.10.2,我通过以下步骤让它工作:

    创建一个名为 gnome-terminal-cursor-shape.sh 的脚本:

    #!/bin/sh
    DEFAULTPROF=`dconf read /org/gnome/terminal/legacy/profiles:/default`
    DEFAULTPROF=`echo "$DEFAULTPROF" | sed -e "s/^'/:/" -e "s/'$//"`
    dconf write /org/gnome/terminal/legacy/profiles:/$DEFAULTPROF/cursor-shape "'$1'"

    并使用 ibeam、block 或 underline 调用它以更改光标形状。

    将脚本放在/usr/bin 或/usr/local/bin 中,并将以下几行添加到您的 .vimrc 中:
    if has("autocmd")
    au InsertEnter *
    \ if v:insertmode == 'i' |
    \ silent execute "!gnome-terminal-cursor-shape.sh ibeam" |
    \ elseif v:insertmode == 'r' |
    \ silent execute "!gnome-terminal-cursor-shape.sh underline" |
    \ endif
    au InsertLeave * silent execute "!gnome-terminal-cursor-shape.sh block"
    au VimLeave * silent execute "!gnome-terminal-cursor-shape.sh block"
    endif

    关于vim - 如何在 Gnome 终端的不同模式下更改 VIM 光标形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14266346/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com