temporary keyboard mappings

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

temporary keyboard mappings

Robert Cussons
Hello all,
I have a keyboard mapping that someone suggested in tips that maps escape to
caps lock and vice versa. What I am trying to do is have this mapping only
present in Vim, i.e. in Vim if I press caps lock it will go into command
mode, but if I then go into firefox and press caps lock it will act as
normal. Is there a way to do it? It is well beyond my knowledge to work out
how!!
Many thanks,
Rob.
Reply | Threaded
Open this post in threaded view
|

Re: temporary keyboard mappings

John (Eljay) Love-Jensen
Hi Robert,

Are you using Vim or gVim?  If Vim, the answer is likely "no".

If you are using gVim, on what OS?  Let's presume it is Windows... you could
intercept the keyboard events from Windows and spoof the behavior you
desire.  That means you'd have to "hack the code", rather than putting in
some sort of neat mapping in your vimrc file.

If the OS is X11-on-top-of-whatever, you could probably hack together
something analogous to the above Windows scenario.

On Windows, if you wanted CapsLock to be Esc for ALL applications, there is
a registry entry that can be fiddled with to make that the keymap behavior
for all users, all applications, all connected keyboards.  But that sounds
like a much bigger hammer than what you are looking for.

HTH,
--Eljay

Reply | Threaded
Open this post in threaded view
|

Re: temporary keyboard mappings

Robert Cussons
Hi John,

thanks for the suggestions, I am actually using gvim on KDE Linux, sorry I
should have included that in the post. It is a networked machine at my
workplace however, so I do not have route permissions and I'm not sure
everyone else in the group would like my keyboard mappings especially as
there are very view Vim users!!

On Thursday 29 September 2005 13:59, John Love-Jensen wrote:

> Hi Robert,
>
> Are you using Vim or gVim?  If Vim, the answer is likely "no".
>
> If you are using gVim, on what OS?  Let's presume it is Windows... you
> could intercept the keyboard events from Windows and spoof the behavior you
> desire.  That means you'd have to "hack the code", rather than putting in
> some sort of neat mapping in your vimrc file.
>
> If the OS is X11-on-top-of-whatever, you could probably hack together
> something analogous to the above Windows scenario.
>
> On Windows, if you wanted CapsLock to be Esc for ALL applications, there is
> a registry entry that can be fiddled with to make that the keymap behavior
> for all users, all applications, all connected keyboards.  But that sounds
> like a much bigger hammer than what you are looking for.
>
> HTH,
> --Eljay

--
================================
Robert Cussons
Office SB3 3.163, Theory Group
Gesellschaft für Schwerionenforschung mbH (GSI)
Planckstraße 1
64291 Darmstadt
Germany.

Tel: +49 (0)6159 71 2754
E-mail: [hidden email]
================================
Reply | Threaded
Open this post in threaded view
|

Re: temporary keyboard mappings

A.J.Mechelynck
In reply to this post by Robert Cussons
Robert Cussons wrote:

> Hello all,
> I have a keyboard mapping that someone suggested in tips that maps escape to
> caps lock and vice versa. What I am trying to do is have this mapping only
> present in Vim, i.e. in Vim if I press caps lock it will go into command
> mode, but if I then go into firefox and press caps lock it will act as
> normal. Is there a way to do it? It is well beyond my knowledge to work out
> how!!
> Many thanks,
> Rob.
>
>
>
Unless I'm mistaken, mapping Caps Lock cannot be done from inside Vim
since it has no awareness of it. So you'll have to do that elsewhere, in
X11 I guess, seeing you're posting with kMail. I'm not sure if it can be
done or not, I guess it may depend on whether you can modify the XConfig
settings "on the fly" without killing and restarting X. But don't take
my word for it, the innards of X11 config is something I know only very
little of. You may want to check the relevant X11 documentation but from
where I sit I can't tell where it is.

Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: temporary keyboard mappings

A.J.Mechelynck
Robert Cussons wrote:
> I don't know what you mean by 'inside' Vim, when I start up gvim I have the
> command below in the .vimrc:
>
> !xmodmap ~/.speedswapper

xmodmap is an external command.

By "inside" Vim I mean "by purely Vim means" such as :map etc.

>
> where the file .speedswapper is as follows:
>
> remove Lock = Caps_Lock
> keysym Escape = Caps_Lock
> keysym Caps_Lock = Escape
> add Lock = Caps_Lock
>
> The trouble with having this is that each time I start a new gvim session it
> remaps back to the old keys. In other words it alternates between being the
> key mapping I want and the default one! I am using KDE on a linux network.
> What I want is once the key mapping is made for it to remain on (so
> maybe .vimrc is the wrong place for the command, as this is read everytime
> gvim is started) but I only want this mapping to be in place for gvim, not
> other applications and I have no idea how to achieve that!

xmodmap applies to the whole of X.

I don't think you can remap CapsLock for gvim and not for the rest of X
i.e. all other applications including the windows manager itself.

By executing that xmodmap command once at X startup (probably in a
"service" triggered by init when entering the appropriate runlevel,
number 5 IIRC) you could, if you have admin privileges on your system,
interchange Esc and CapsLock once and for all for all users of X11 on
that machine; but I guess you don't want that; and IIUC they would still
be unswapped on non-X terminals such as the virtual consoles /dev/tty.


Best regards,
Tony.

P.S., Next time, please reply to the list (e.g., use "Reply to all") and
not just privately to me (i.e., "Reply to Sender"). That way you will
give other Vim users a chance to see your post, and you will get a reply
even if I'm not available or if it's something to which I don't know the
answer.