linux终端光标为竖杠,修改Ubuntu终端中,Vim插入模式下光标实现为竖线状

本文详细介绍了如何根据不同版本的Gnome-Terminal修改vimrc文件,以实现插入模式和正常模式下光标的形状切换。针对Gnome-Terminal 2.26、3.x及3.16及以上版本,提供了相应的脚本和配置代码,确保光标在不同模式下显示不同的形状。
摘要由CSDN通过智能技术生成

原文:Change cursor shape in different modes

不同终端版本修改代码不同。

使用如下命令查看Gnome-Terminal终端的版本:

aptitude show gnome-terminal

To change the shape of the cursor in different modes, you can add the following into your vimrc.

将不同版本终端对应的代码添加到vimrc文件中即可。

我的终端版本为3.18***,vimrc文件位于etc/vim/vimrc

For the Gnome-Terminal (version 2.26)Edit

This makes your cursor change in all open terminals. Upgrade your terminal and use the version above instead.

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

For the Gnome-Terminal (version 3.x)Edit

First make a script 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'"

Make it executable & put it in /usr/local/bin Next, add this to .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

If you use more than one profile in gnome-terminal, you might have to adapt this to your profiles.

For the Gnome-Terminal (version ≥3.16) Edit

This method has the advantage compared to the method above that it influences the given tab only, and not all the tabs that use the given profile. Add the following into .vimrc

if has("autocmd")

au VimEnter,InsertLeave * silent execute '!echo -ne "\e[2 q"' | redraw!

au InsertEnter,InsertChange *

\ if v:insertmode == 'i' |

\ silent execute '!echo -ne "\e[6 q"' | redraw! |

\ elseif v:insertmode == 'r' |

\ silent execute '!echo -ne "\e[4 q"' | redraw! |

\ endif

au VimLeave * silent execute '!echo -ne "\e[ q"' | redraw!

endif

Above snippet disables cursor blinking. If you want cursor blink, just decrement all the 3 numbers above 2,4,6 by one each.

if has("autocmd")

au VimEnter,InsertLeave * silent execute '!echo -ne "\e[1 q"' | redraw!

au InsertEnter,InsertChange *

\ if v:insertmode == 'i' |

\ silent execute '!echo -ne "\e[5 q"' | redraw! |

\ elseif v:insertmode == 'r' |

\ silent execute '!echo -ne "\e[3 q"' | redraw! |

\ endif

au VimLeave * silent execute '!echo -ne "\e[ q"' | redraw!

endif

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值