开发者

How to capture shift-tab in vim

开发者 https://www.devze.com 2022-12-28 22:52 出处:网络
I want to use shift-tab for auto completion and shifting code blocks visually. I have been referring to Make_Shift-Tab_work . That link talks about mapping ^[[Z to shift-tab . But i don\'t get ^[[Z wh

I want to use shift-tab for auto completion and shifting code blocks visually. I have been referring to Make_Shift-Tab_work . That link talks about mapping ^[[Z to shift-tab . But i don't get ^[[Z when i press s开发者_高级运维hift-tab. i just get a normal tab in that case.

It then talks about using xmodmap -pke | grep 'Tab' to map tab keys. According to that the output should be

keycode 23 = Tab
or
keycode 23 = Tab ISO_Left_Tab

However i get

keycode  22 = Tab KP_Tab

if i use xmodmap -e 'keycode 22 = Tab ISO_Left_Tab' and after that xmodmap -pke | grep 'Tab', I still get

keycode  22 = Tab KP_Tab

This means running xmodmap -e 'keycode 22 = Tab ISO_Left_Tab' has no effect.

In the end the link mentions using xev to see what X recieves when i press shift-tab. But i dont have xev on my system.

Is there any other way i can capture shift-tab in vim


The link talks specifically about getting ^[[Z when you press Ctrl+vShift+Tab in insert mode. If you leave off the Ctrl+v, then Vim will behave just as if you pressed Tab.

The easiest way to make Vim recognize <S-Tab>, is to directly set the t_kB option to the escape sequence your terminal sends, instead of messing with maps.

As a quick test, try this in a running Vim:

:set t_kB=Ctrl+vEsc[Z
:imap <S-Tab> foo

Now when you press Shift+Tab in insert mode, foo should be inserted. If that worked, you can make the change permanent by adding the following to your vimrc.

exe 'set t_kB=' . nr2char(27) . '[Z'
0

精彩评论

暂无评论...
验证码 换一张
取 消