views:

303

answers:

1

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 shift-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

+1  A: 

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'
jamessan
even after doing this `Shift+Tab` behaves just like a `tab`
Yogesh Arora
actually i am not sure what escape sequence my terminal is sending when i press `shift-tab`. Is there a way i can check that
Yogesh Arora
Yes, that's what `<C-v><S-Tab>` should be doing. You don't have to do it in Vim. From your shell, run `cat` and then press `<C-v><S-Tab>` and you should see what your terminal generates for `<S-Tab>`.
jamessan
Using `cat` `<S-Tab>` behaves similarly as `<tab>`.
Yogesh Arora
What does `egrep 'XK_[a-zA-Z_]*Tab' /usr/include/X11/keysymdef.h` show?
jamessan
#define XK_Tab 0xFF09#define XK_KP_Tab 0xFF89#define XK_ISO_Left_Tab 0xFE20#define XK_Tabovedot 0x12d7
Yogesh Arora
Those all look fine. You have `ISO_Left_Tab` available, so you should be able to set that as the shifted version of Tab.
jamessan