Map Command key to Control on OS X

93 views
Skip to first unread message

Heldraug

unread,
Oct 30, 2012, 11:10:37 AM10/30/12
to vim...@googlegroups.com
Here's the deal: I use a lot a Macbook to code, problem is, it only has a small Control key on the left side, so it's kind of uncomfortable to use, particularly when using keys that have to be typed with the left hand. There are two Command keys, though. I looked around but I couldn't find an answer to this. Is there a way to map the Command key to Control, so I can use it as a Control key? Has anyone done this?

Tim Gray

unread,
Oct 30, 2012, 1:29:10 PM10/30/12
to vim...@googlegroups.com
No I haven't done that. However, what I have done is to swap the caps
lock key and the left control key. You can probably the command key as
well, but I'm not sure if OS X lets you change just one of the command
keys and not the other. I use the built in capability on 10.7. It's
probably available in other versions of OS X, but I can't verify that at
the moment. Go to System Preferences -> Keyboard, select the Keyboard
tab and then hit the Modifier Keys... button. There are other apps out
there that let you remap things in fancier ways, but for simple modifier
key remapping, this works for me.

Heldraug

unread,
Oct 31, 2012, 11:48:29 AM10/31/12
to vim...@googlegroups.com

That works, problem is, it remaps completely the Command key system wide. What I'm looking for is to map the Cmd key only within Vim.

Tony Mechelynck

unread,
Oct 31, 2012, 12:19:41 PM10/31/12
to vim...@googlegroups.com, Heldraug
The problem with that is that Cmd and Ctrl are modifier keys, Vim
doesn't see them separately but only together to whatever letter or
function key you pressed together with them.

A possible but ugly solution would be

noremap <C-A> <D-A>
noremap! <C-A> <D-A>
noremap <D-A> <C-A>
noremap! <D-A> <C-A>
noremap <C-B> <D-B>
noremap! <C-B> <D-B>
noremap <D-B> <C-B>
noremap! <D-B> <C-B>
etc.

There are, however, IIRC, a hundred or so keys on the keyboard. Let's
see� four statements as above for each of them, plus four other ones to
swap Ctrl-Alt-<key> with Cmd-Alt-<key>, that's eight, plus eight more to
swap Ctrl-Shift- and Ctrl-Alt-Shift- with Cmd-Shift- and Cmd-Alt-Shift-�
That's something like sixteen hundred mappings just for swapping those
two keys� You could of course define a keymap: see
http://vim.wikia.com/wiki/How_to_make_a_keymap but keymaps work only in
Insert and Command-line mones, and is the game worth the candle?

If someone knows an easier way to do it "just for Vim"� or is it
possible to change the system keyboard preferences just for one application?


Best regards,
Tony.
--
"It's Fabulous! We haven't seen anything like it in the last half an
hour!"
-- Macy's

Alexandre Provencio

unread,
Nov 1, 2012, 11:43:03 AM11/1/12
to Vim List
As I've never owned a Mac so I can't give you setup details, but I've
heard that some people are setting their ITerm's Cmd to send Ctrl, and
also about the use of softwares like keyremap4macbook, keymando, etc
which might also help you with that.
-Alexandre
> There are, however, IIRC, a hundred or so keys on the keyboard. Let's see…
> four statements as above for each of them, plus four other ones to swap
> Ctrl-Alt-<key> with Cmd-Alt-<key>, that's eight, plus eight more to swap
> Ctrl-Shift- and Ctrl-Alt-Shift- with Cmd-Shift- and Cmd-Alt-Shift-… That's
> something like sixteen hundred mappings just for swapping those two keys…
> You could of course define a keymap: see
> http://vim.wikia.com/wiki/How_to_make_a_keymap but keymaps work only in
> Insert and Command-line mones, and is the game worth the candle?
>
> If someone knows an easier way to do it "just for Vim"… or is it possible to
> change the system keyboard preferences just for one application?
>
>
> Best regards,
> Tony.
> --
> "It's Fabulous! We haven't seen anything like it in the last half an
> hour!"
> -- Macy's
>
>
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
Reply all
Reply to author
Forward
0 new messages