MacVim doesn't recognise Ctrl-Tab

42 views
Skip to first unread message

Tim Allen

unread,
Sep 21, 2007, 11:11:14 PM9/21/07
to vim_mac
Back in the days when I was using Win32 on a regular basis, I added
the following to my ~/.vimrc to add some keybindings I was used to in
other applications:

nmap <C-Tab> ^Ww
nmap <CS-Tab> ^WW

This worked pretty well, in Win32 GVim and later in GTK+ GVim, but it
doesn't seem to work on MacVim. In fact, no mappings involving tab
with modifiers seem to do anything. For example, save the following to
~/tabtest.vim:

map <special> <Tab> :echo "Got Tab"<CR>
map <special> <C-Tab> :echo "Got Control-Tab"<CR>
map <special> <S-Tab> :echo "Got Shift-Tab"<CR>
map <special> <M-Tab> :echo "Got Alt-Tab"<CR>

...then run "mvim -u NONE -U NONE -S ~/tabtest.vim". All the mappings
show up properly in :map, and the mapping for <Tab> works, but no
amount of banging on the tab key with any combination of modifiers
seems to produce any messages at all.

björn

unread,
Sep 22, 2007, 3:44:03 PM9/22/07
to vim...@googlegroups.com

Hi Tim,

I have looked into the Tab problems now and managed to fix some of
them (rev 260). The following mappings now work

:imap <Tab> Tab
:imap <S-Tab> S-Tab
:imap <M-Tab> M-Tab
:imap <S-M-Tab> S-M-Tab

but these do _NOT_ work

:imap <D-Tab> D-Tab
:imap <C-Tab> C-Tab

These last two are reserved by Mac OS X: <D-Tab> switches
applications, <C-Tab> moves the focus between "key views". Now, it
should be possible to override the <C-Tab> behaviour, but I haven't
figured out a reasonable way to do so yet. (Note <C-Tab> events never
even reach the text view, instead Cocoa seems to hard wire <C-Tab> to
"select next key view".)

/Björn

Tim Allen

unread,
Sep 22, 2007, 9:58:08 PM9/22/07
to vim_mac
On Sep 23, 5:44 am, "björn" <bjorn.winck...@gmail.com> wrote:
> I have looked into the Tab problems now and managed to fix some of
> them (rev 260).

Thank you!

> but these do _NOT_ work
>
> :imap <D-Tab> D-Tab
> :imap <C-Tab> C-Tab
>
> These last two are reserved by Mac OS X: <D-Tab> switches
> applications, <C-Tab> moves the focus between "key views". Now, it
> should be possible to override the <C-Tab> behaviour, but I haven't
> figured out a reasonable way to do so yet. (Note <C-Tab> events never
> even reach the text view, instead Cocoa seems to hard wire <C-Tab> to
> "select next key view".)

Haw, just my luck. :) A quick google search didn't show me anything
particularly helpful about overriding this <C-Tab> behaviour (although
you might be able to snag the keyboard event by overriding sendEvent:
on your application or window objects), so I'll just have to stick
with the traditional old ^W keybindings. Thanks for looking into it,
though!

Tim Allen

unread,
Oct 12, 2007, 11:16:38 PM10/12/07
to vim_mac
On Sep 23, 5:44 am, "björn" <bjorn.winck...@gmail.com> wrote:
> :imap <D-Tab> D-Tab
> :imap <C-Tab> C-Tab
>
> These last two are reserved by Mac OS X: <D-Tab> switches
> applications, <C-Tab> moves the focus between "key views". Now, it
> should be possible to override the <C-Tab> behaviour, but I haven't
> figured out a reasonable way to do so yet. (Note <C-Tab> events never
> even reach the text view, instead Cocoa seems to hard wire <C-Tab> to
> "select next key view".)

I just came across the Firefox equivalent of this bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=374076

Apparently you can't get NSKeyDown events for Ctrl-Tab, but you can
get NSKeyUp events.

björn

unread,
Oct 13, 2007, 5:58:48 AM10/13/07
to vim...@googlegroups.com

Hmmm...would it be prudent to just ignore this for 10.4, since Apple
has fixed the problem with 10.5 (according to the above thread)?


/Björn

Tim Allen

unread,
Oct 13, 2007, 9:47:50 AM10/13/07
to vim_mac
On Oct 13, 7:58 pm, "björn" <bjorn.winck...@gmail.com> wrote:
> > I just came across the Firefox equivalent of this bug:
>
> >https://bugzilla.mozilla.org/show_bug.cgi?id=374076
>
> > Apparently you can't get NSKeyDown events for Ctrl-Tab, but you can
> > get NSKeyUp events.
>
> Hmmm...would it be prudent to just ignore this for 10.4, since Apple
> has fixed the problem with 10.5 (according to the above thread)?

Well, I suspect 10.4 is going to be with us for a while yet (there's
still people on 10.3 after all), but it probably wouldn't hurt to at
least add something to the MacVim documentation saying "Yes, mapping
<C-Tab> doesn't work in 10.4, it's a limitation in Cocoa removed in
10.5".

björn

unread,
Oct 13, 2007, 11:04:56 AM10/13/07
to vim...@googlegroups.com

I did some investigating and found that it works to intercept <C-Tab>
in -[MMApplication sendEvent:], but I am not sure if it breaks
something else (I doubt it, but please be on the alert). The latest
revision contains this hack (r315).


/Björn

Reply all
Reply to author
Forward
0 new messages