5

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

Yogesh Arora
  • 2,216
  • 2
  • 25
  • 35
  • Does `xmodmap` print nothing? Any error code after running `xmodmap`? What OS (what distro)? – ZyX Apr 30 '10 at 15:10
  • 1
    `xmodmap -pke | grep 'Tab'` prints `keycode 22 = Tab KP_Tab`. I am using SunOS 5.10 – Yogesh Arora Apr 30 '10 at 15:17
  • `xev` is typically included in an X utils package. What the specific package name is will vary depending on your Linux distro, but it's `x11-utils` on Debian/Ubuntu and `xorg-x11-utils` on Fedora/RH. – jamessan Apr 30 '10 at 15:21
  • It'd also be useful to know which terminal you're using. Similarly, try this in xterm and see if it works there. – jamessan Apr 30 '10 at 15:28
  • I was meaning does `xmodmap -e ...` print something? And check whether `xmodmap -e 'keycode 22 = Tab T'` work. It must echo nothing and map `` to `T`. – ZyX Apr 30 '10 at 17:06
  • You can also try to map `` to some unused symbol, for example 0xffff (`xmodmap -e 'keycode 22 = Tab 0xffff'`). If I do this it produces `[3~` in my terminal, so if it works you will only have to set `t_kB` in your vimrc. – ZyX Apr 30 '10 at 17:11
  • for me `xmodmap` does not seem to work, i dont see any change after running `xmodmap -e 'keycode 22 = Tab T'` – Yogesh Arora Apr 30 '10 at 17:20
  • i ran it with verbose options and this is what i got. `xmodmap: unable to open file 'keycode 22 = Tab A'` for reading `xmodmap: 1 error encountered, aborting.`. So it seems i dont have permission to change the file which xmodmap is changing. Is it possible to define such a file in my home directory – Yogesh Arora Apr 30 '10 at 17:23
  • No, you just typed the command incorrectly. The string `'keycode 22 = Tab'` must come immediately after the `-e` flag. Otherwise, xmodmap treats the argument as a file that it is supposed to be reading. So the command you want to run is `xmodmap -verbose -e 'keycode 22 = Tab ISO_Left_Tab'` – jamessan Apr 30 '10 at 17:39
  • ok that was my mistake, but even when i run `xmodmap -verbose -e 'keycode 22 = Tab ISO_Left_Tab'` and then `xmodmap -pke | grep Tab` i get `keycode 22 = Tab KP_Tab` instead of `keycode 22 = Tab ISO_Left_Tab`. This means my `xmodmap -e` command has no effect – Yogesh Arora Apr 30 '10 at 18:02
  • Is there systrace (strace) available on your system? Try installing it and running `strace -o /tmp/strace.log xmodmap -e 'keycode 22 = Tab ISO_Left_Tab'`, then paste the contents of `/tmp/strace.log`. – ZyX May 01 '10 at 15:06
  • i cant run strace, i dont have access permission to /dev/log – Yogesh Arora May 03 '10 at 16:05

1 Answers1

3

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
  • 41,569
  • 8
  • 85
  • 85
  • even after doing this `Shift+Tab` behaves just like a `tab` – Yogesh Arora Apr 30 '10 at 15:23
  • 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 Apr 30 '10 at 15:26
  • Yes, that's what `` should be doing. You don't have to do it in Vim. From your shell, run `cat` and then press `` and you should see what your terminal generates for ``. – jamessan Apr 30 '10 at 15:30
  • What does `egrep 'XK_[a-zA-Z_]*Tab' /usr/include/X11/keysymdef.h` show? – jamessan Apr 30 '10 at 16:09
  • #define XK_Tab 0xFF09 #define XK_KP_Tab 0xFF89 #define XK_ISO_Left_Tab 0xFE20 #define XK_Tabovedot 0x12d7 – Yogesh Arora Apr 30 '10 at 16:10
  • 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 Apr 30 '10 at 17:41