Unable to map Ctrl+Shift+Z

16 views
Skip to first unread message

Marwan Al-Sabbagh

unread,
Nov 17, 2008, 7:04:14 AM11/17/08
to v...@vim.org
Hi,
I'm trying to map the keys CTRL+Z to undo, and CTRL+SHIFT+Z to
redo. I've tried the following mappings:

inoremap <C-Z> undo_test
inoremap <C-S-Z> redo_test

when I press CTRL+Z or CTRL+SHIFT+Z they produce the same result,
inserting the text redo_test. When I run imap to see the current
mappings I get:

<C-Z> * redo_test

vim seems to treat <C-Z> and <C-S-Z> as the same key being mapped.
this is further confirmed when I do the following:

In insert mode, pressed CTRL-V. pressed CTRL+Z, got
^Z

In insert mode, pressed CTRL-V. pressed CTRL+SHIFT+Z, got
^Z

this is however not the case with other keys like CTRL+SHIFT+Right
and CTRL+SHIFT+Right. In that case vim sees the difference and I get
two mappings.

In insert mode, pressed CTRL-V. pressed CTRL+Right, got
<C-Right>

In insert mode, pressed CTRL-V. pressed CTRL+SHIFT+Right, got
<C-S-Right>

I'm running the following:

gvim 7.1
Ubuntu Linux 8.04

any help is much appreciated.

cheers,
Marwan

Ben Schmidt

unread,
Nov 17, 2008, 7:38:40 AM11/17/08
to vim...@googlegroups.com
[...]

> vim seems to treat <C-Z> and <C-S-Z> as the same key being mapped.
> this is further confirmed when I do the following:
[...]

> this is however not the case with other keys like CTRL+SHIFT+Right
> and CTRL+SHIFT+Right. In that case vim sees the difference and I get
> two mappings.
[...]
> gvim 7.1

What you are seeing is normal. It's a limitation Vim has that's leftover
from terminals where there was no distinction between shifted and
unshifted control keys. Since then, some terminals are able to
distinguish between various modified cursor keys, and Vim has been
updated to recognise these, but it still hasn't been updated to in any
way distinguish shifted and unshifted 'letter' control keys.

Ben.

Bill McCarthy

unread,
Nov 17, 2008, 2:09:35 PM11/17/08
to Marwan Al-Sabbagh
On Mon 17-Nov-08 6:04am -0600, Marwan Al-Sabbagh wrote:

> I'm trying to map the keys CTRL+Z to undo, and CTRL+SHIFT+Z to
> redo. I've tried the following mappings:
>
> inoremap <C-Z> undo_test
> inoremap <C-S-Z> redo_test

As Ben pointed out, the Control key doesn't recognize case :-(
However the Meta/Alt key does on my Windows machine:

:map <m-z> :echo "Meta z"<CR>
:map <m-Z> :echo "Meta Z"<CR>

Works fine.

--
Best regards,
Bill


Tony Mechelynck

unread,
Nov 17, 2008, 9:59:38 PM11/17/08
to vim...@googlegroups.com

Just beware of using them in Insert mode if you use accented characters:
to Vim, Alt-z is ú "small u with acute" and Alt-Z (Alt-shift-z) is Ú
"capital U with acute". Similarly for other Alt-key combinations.

The safest keys to map (keys that don't have any meaning to Vim) are the
F keys, except F1 which means Help, and, on some systems, F10 which
means Menu. Also, to use them together with Shift, Ctrl and/or Alt, you
may have to check which combinations Vim can detect. (On my Linux system
with KDE, the window manager intercepts Ctrl-Fn and Alt-Fn to switch
virtual desktops, the kernel intercepts Ctrl-Alt-Fn to switch virtual
consoles, and no program ever sees any of them. Shift-Fn can be used
though.)


Best regards,
Tony.
--
What garlic is to salad, insanity is to art.

Reply all
Reply to author
Forward
0 new messages