Quantcast

unable to map ctrl-1

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

unable to map ctrl-1

misterw

Gvim 72 on XP won't let me map certain ctrl key combinations.
Specifically it won't map any of CTRL 1 through to 10. If I type

CTRL-V CTRL-1

I get nothing. Only 2 and 6 actually print anything. Other
applications make use of these keys, and vim itself uses CTRL-6. Is
there something that can be done to make this work?

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: unable to map ctrl-1

John Beckett-2

MisterW wrote:
> Gvim 72 on XP won't let me map certain ctrl key combinations.
> Specifically it won't map any of CTRL 1 through to 10. If I
> type
>
> CTRL-V CTRL-1
>
> I get nothing. Only 2 and 6 actually print anything. Other
> applications make use of these keys, and vim itself uses
> CTRL-6. Is there something that can be done to make this work?

No. The problem is that Vim is designed to be portable; it works
on many operating systems and tries to minimise the amount of
special code used for dealing with a particular OS.

It's not Ctrl-6, it is Ctrl-^ which is part of the venerable
ASCII system. There is a lot more than you want to know at
http://en.wikipedia.org/wiki/ASCII

If you search for "^^" on that page (Ctrl-^) you will see the
list of valid Ctrl keys.

I know this news is a bit shocking, but I've found that as I
learned more of the Vim way of doing things, my desire to map
commands to weird character combinations has declined.

John


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: unable to map ctrl-1

George V. Reilly

On Tue, Mar 31, 2009 at 7:52 PM, John Beckett <[hidden email]> wrote:

>
> MisterW wrote:
> > Gvim 72 on XP won't let me map certain ctrl key combinations.
> > Specifically it won't map any of CTRL 1 through to 10. If I
> > type
> >
> > CTRL-V CTRL-1
> >
> > I get nothing. Only 2 and 6 actually print anything. Other
> > applications make use of these keys, and vim itself uses
> > CTRL-6. Is there something that can be done to make this work?
>
> No. The problem is that Vim is designed to be portable; it works
> on many operating systems and tries to minimise the amount of
> special code used for dealing with a particular OS.
>
> It's not Ctrl-6, it is Ctrl-^ which is part of the venerable
> ASCII system. There is a lot more than you want to know at
> http://en.wikipedia.org/wiki/ASCII


If you look at process_message() in gui_w48.c (Windows Gvim) and
decode_key_event() in os_win32.c (Win32 console Vim), you'll find some
special-case handling:
    /* Ctrl-6 is Ctrl-^ */
    /* Ctrl-2 is Ctrl-@ */
    /* Ctrl-- is Ctrl-_ */

I added the remapping hack for console Vim nearly 15 years ago, mostly
because I couldn't stand typing Ctrl-Shift-6 to toggle between
buffers.

The other Ctrl-<numeral> combinations are discarded, presumably
because they have no ASCII equivalent.
--
/George V. Reilly  [hidden email]
http://www.georgevreilly.com/blog  http://blogs.cozi.com/tech

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: unable to map ctrl-1

misterw
In reply to this post by John Beckett-2

> No. The problem is that Vim is designed to be portable; it works
> on many operating systems and tries to minimise the amount of
> special code used for dealing with a particular OS.

Why then does vim.exe running in a cmd window allow me to map <C-1>
when gvim won't?

> I know this news is a bit shocking, but I've found that as I
> learned more of the Vim way of doing things, my desire to map
> commands to weird character combinations has declined.

Are you saying you don't make much use of mappings?

I'm a long time vim user and I find there's an ever increasing list of
things I want to map. I don't consider control 1-10 a wierd char
combination, It's a fairly common idiom for switching between tabs and
the like.

Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: unable to map ctrl-1

John Beckett-2
In reply to this post by George V. Reilly

George V. Reilly wrote:

> If you look at process_message() in gui_w48.c (Windows Gvim)
> and decode_key_event() in os_win32.c (Win32 console Vim),
> you'll find some special-case handling:
>     /* Ctrl-6 is Ctrl-^ */
>     /* Ctrl-2 is Ctrl-@ */
>     /* Ctrl-- is Ctrl-_ */
>
> I added the remapping hack for console Vim nearly 15 years
> ago, mostly because I couldn't stand typing Ctrl-Shift-6 to
> toggle between buffers.
>
> The other Ctrl-<numeral> combinations are discarded,
> presumably because they have no ASCII equivalent.

Thanks for the interesting info. That is another corner of the
source that I haven't seen before.

John


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: unable to map ctrl-1

John Beckett-2
In reply to this post by misterw

MisterW wrote:
> Why then does vim.exe running in a cmd window allow me to map
> <C-1> when gvim won't?

George Reilly has just explained that Ctrl-6, Ctrl-2, Ctrl-- are
special-cased in Windows (which I didn't know). Perhaps there is
also some special casing for Ctrl-1 ... sorry, I don't know.

>> I know this news is a bit shocking, but I've found that as I
>> learned more of the Vim way of doing things, my desire to map
>> commands to weird character combinations has declined.
>
> Are you saying you don't make much use of mappings?
>
> I'm a long time vim user and I find there's an ever
> increasing list of things I want to map. I don't consider
> control 1-10 a wierd char combination, It's a fairly common
> idiom for switching between tabs and the like.

Sorry for the POV "weird" comment. It is true that I don't make
much use of key mappings (I certainly have some, but not for
buffer switching). Sometimes when I'm working on a particular
project I will put uppercase marks in files I want to quickly
return to. Or I might have a set of special mappings just for
the project (and I might use the keypad with stuff like <k1>).

I'm sure you don't need this tip, but FWIW there is a tip that
maps:
    ,l       : list buffers
    ,b ,f ,g : go back/forward/last-used
    ,1 ,2 ,3 : go to buffer 1/2/3 etc
http://vim.wikia.com/wiki/Easier_buffer_switching

That is the sort of thing I would do given I can't use Ctrl-2
etc.

John


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: unable to map ctrl-1

misterw

On Apr 1, 3:14 pm, "John Beckett" <[hidden email]> wrote:
> MisterW wrote:
> > Why then does vim.exe running in a cmd window allow me to map
> > <C-1> when gvim won't?
>
> George Reilly has just explained that Ctrl-6, Ctrl-2, Ctrl-- are
> special-cased in Windows (which I didn't know). Perhaps there is
> also some special casing for Ctrl-1 ... sorry, I don't know.

Doing some testing I have been unable to find a key that I cannot map
ctrl to on vim.exe in a command prompt.
ctrl 1-10 work as do = - ` / .

Can anyone explain why gvim.exe differs?

I'll have a look thru the source when I get a chance.

Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: unable to map ctrl-1

Tony Mechelynck
In reply to this post by John Beckett-2

On 01/04/09 04:52, John Beckett wrote:

>
> MisterW wrote:
>> Gvim 72 on XP won't let me map certain ctrl key combinations.
>> Specifically it won't map any of CTRL 1 through to 10. If I
>> type
>>
>> CTRL-V CTRL-1
>>
>> I get nothing. Only 2 and 6 actually print anything. Other
>> applications make use of these keys, and vim itself uses
>> CTRL-6. Is there something that can be done to make this work?
>
> No. The problem is that Vim is designed to be portable; it works
> on many operating systems and tries to minimise the amount of
> special code used for dealing with a particular OS.
>
> It's not Ctrl-6, it is Ctrl-^ which is part of the venerable
> ASCII system. There is a lot more than you want to know at
> http://en.wikipedia.org/wiki/ASCII
>
> If you search for "^^" on that page (Ctrl-^) you will see the
> list of valid Ctrl keys.
>
> I know this news is a bit shocking, but I've found that as I
> learned more of the Vim way of doing things, my desire to map
> commands to weird character combinations has declined.
>
> John

Indeed.

Instead of Ctrl-1, which is not portable, not ASCII, and unknown to
Vim's "cooked" input mode, you may want to map one of the following
nearby keys instead (based on my Belgian keyboard):

² (the key just left of the "one" key)
³ (the same, with Shift)
<S-F1> (Shift-F1)
Note: F1 without Shift is an alias for ":help" in Vim so you might not
want to use that as the {lhs} of a mapping. Otherwise most Fn and
Shift-Fn keys are "safe" to use a {lhs}es in Vim. Other "safe" keys for
Normal mode but usually not Insert mode, are any keys producing
upper-ASCII codes -- these will depend on your national keyboard: à, ç,
ù, é, è, µ and £ on my Belgian keyboard, probably ø and Ø in Danish or
Norwegian, ł in Polish, ß and possibly umlauted vowels in German, á é í
ó ú in Spanish, etc.

The first two example mappings above use upper-ASCII characters, namely
(on my keyboard) 0xB2 and 0xB3; Shift-F1 is accessible to application
programs on every OS where I've worked. (Ctrl-F1 isn't accessible to
gvim, or to any other X11 GUI, in my present openSUSE system, where the
KDE winmanager preempts it for "switch to virtual desktop #1.)


The only "printable keys" whose Ctrl counterparts are defined in (7-bit)
ASCII and therefore usable by Vim are the following:

- 0x40 to 0x5F including all Latin uppercase: the Ctrl combo maps to the
result of bitwise AND with 0x1F;
- Latin lowercase, which are aliases for the corresponding uppercase;
- the question mark 0x3F, whose Ctrl counterpart is DEL 0x7F.

If some of them are not on your keyboard, you can use something like the
following (which I use because I'm not sure if and where the Ctrl-] key,
a very useful key for help and tag navigatyion in Vim, exists on my
keyboard):

        :noremap <F9> <C-]>


Best regards,
Tony.
--
A student, in hopes of understanding the Lambda-nature, came to
Greenblatt.  As they spoke a Multics system hacker walked by.  "Is it
true," asked the student, "that PL-1 has many of the same data types as
Lisp?"  Almost before the student had finished his question, Greenblatt
shouted, "FOO!", and hit the student with a stick.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: unable to map ctrl-1

Tony Mechelynck
In reply to this post by John Beckett-2

On 01/04/09 06:14, John Beckett wrote:

>
> MisterW wrote:
>> Why then does vim.exe running in a cmd window allow me to map
>> <C-1>  when gvim won't?
>
> George Reilly has just explained that Ctrl-6, Ctrl-2, Ctrl-- are
> special-cased in Windows (which I didn't know). Perhaps there is
> also some special casing for Ctrl-1 ... sorry, I don't know.
>
>>> I know this news is a bit shocking, but I've found that as I
>>> learned more of the Vim way of doing things, my desire to map
>>> commands to weird character combinations has declined.
>>
>> Are you saying you don't make much use of mappings?
>>
>> I'm a long time vim user and I find there's an ever
>> increasing list of things I want to map. I don't consider
>> control 1-10 a wierd char combination, It's a fairly common
>> idiom for switching between tabs and the like.
>
> Sorry for the POV "weird" comment. It is true that I don't make
> much use of key mappings (I certainly have some, but not for
> buffer switching). Sometimes when I'm working on a particular
> project I will put uppercase marks in files I want to quickly
> return to. Or I might have a set of special mappings just for
> the project (and I might use the keypad with stuff like<k1>).
>
> I'm sure you don't need this tip, but FWIW there is a tip that
> maps:
>      ,l       : list buffers
>      ,b ,f ,g : go back/forward/last-used
>      ,1 ,2 ,3 : go to buffer 1/2/3 etc
> http://vim.wikia.com/wiki/Easier_buffer_switching
>
> That is the sort of thing I would do given I can't use Ctrl-2
> etc.
>
> John

The following are actual examples copied from my vimrc:

        map <F9> <C-]>
        " using F9, a 'safe' mapping, because my keyboard doesn't
        " gracefully handle Ctrl-]. Nowadays I know that it's
        " Ctrl-AltGr-$ but that's not practical.

        inoremap <Space> <Space><Left><Right>
        " redefining a standard key, here to create an undo point

        if version < 700
                cnoreabbrev h bot h
        else
                cnoreabbrev <expr> h
                \ ((getcmdtype() == ':' && getcmdpos() <= 2)?
                \ 'bot h' : 'h')
        endif
        map <F1> :bot help<CR>
        " redefines again, to open the help at bottom

        map µ :&&<CR>
        " mapping an upper-ASCII key
        " this one redoes the latest :substitute

        map <F2> :cnext<CR>
        map <S-F2> :cprev<CR>
        " two 'related' F keys, for quickfix navigation

        map <F11> <C-W>w
        map <S-F11> <C-W>W
        imap <F11> <C-O><C-W>w
        imap <S-F11> <C-O><C-W>W
        " 'related' F keys, for split-windows navigation
        " in both Insert/Replace and Normal/Visual

As you can see, I limit myself to {lhs}es chosen among F and Shift-F
keys, Normal-mode-upper-ASCII, and intentional redefines, so there will
be no unexpected clash with either existing Vim commands or keys
snatched by some OS before Vim gets them.

The use of µ may seem "weird" but it is an upper-ASCII key, therefore
not used by Vim in Normal mode, and passed by every OS to the app as a
"printable" key (once my national keyboard is configured, of course).


Best regards,
Tony.
--
Anything is good if it's made of chocolate.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: unable to map ctrl-1

Tony Mechelynck
In reply to this post by misterw

On 01/04/09 06:50, MisterW wrote:

>
> On Apr 1, 3:14 pm, "John Beckett"<[hidden email]>  wrote:
>> MisterW wrote:
>>> Why then does vim.exe running in a cmd window allow me to map
>>> <C-1>  when gvim won't?
>>
>> George Reilly has just explained that Ctrl-6, Ctrl-2, Ctrl-- are
>> special-cased in Windows (which I didn't know). Perhaps there is
>> also some special casing for Ctrl-1 ... sorry, I don't know.
>
> Doing some testing I have been unable to find a key that I cannot map
> ctrl to on vim.exe in a command prompt.
> ctrl 1-10 work as do = - ` / .
>
> Can anyone explain why gvim.exe differs?
>
> I'll have a look thru the source when I get a chance.
>
> Matt

gvim interfaces differetly with the keyboard.

On Windows, I'm not sure what the difference is, but I guess Windows
delivers different bytecodes for "console" programs running in the "Dos
Box", usually (in "Western" countries) in cp437 or cp850, and for "GUI"
programs which have their own windows, and may run in, for instance,
Unicode or cp1252.

On X11, gvim interfaces directly with the X11 server via its own
"builtin_gui" termcap while Vim has an additional intermediate layer to
go through, namely the terminal, and different console programs running
at the same time for a single user on a single machine can still get
different bytecodes for the same keys depending on whether they run in
the Linux console, in "true" xterm, in xterm emulated by konsole, in
vt100 emulated by konsole, in gnome-terminal, etc.

On the Mac, I believe there are similar differences between gvim and
Console Vim but I don't know the details.


Best regards,
Tony.
--
There are many intelligent species in the universe.  They all own
cats.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Loading...