Created
April 16, 2011 18:28
-
-
Save abachman/923376 to your computer and use it in GitHub Desktop.
acclimating myself to the Mac keyboard layout by reclaiming keyboard shortcuts. https://twitter.com/#!/abachman/status/59323764772569088
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the last two years I've been using Ubuntu Linux for software development. | |
Last week I got a MacBook Pro and have been changing over. I run a heavily | |
customized vim setup, so the change was particularly difficult with regards to | |
my keyboard layout. | |
These step show what I did to make my Mac work like my Linux machines which all | |
have caps-lock remapped to control. I used OSX's built in keyboard setup tool | |
to remap my caps-lock key to be a command key, since command, for the most | |
part, takes the place of control as the primary shortcut key modifier. | |
The hardest part is managing vim shortcuts that rely on control. Partly because | |
MacVim maps default Command-[letter] shortcuts, and partly because Mac OSX | |
itself has some default Command-[letter] shortcuts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First, I took out some Mac OSX default keyboard shortcuts. In this case I want to reclaim | |
<Command-h> and change it to <Command-Shift-h>. Advice taken from | |
http://www.hoboes.com/Mimsy/hacks/disabling-quit-rewriting/ | |
From the command line ($ is my prompt character): | |
$ defaults write org.vim.MacVim NSUserKeyEquivalents -dict-add "Hide MacVim" "@\$H" | |
This is a command in the form: | |
defaults [action] [domain] [key] [value] | |
I can check before I write by using the `read` action and I got the domain by | |
ls-ing ~/Library/Preferences. e.g.: | |
$ ls ~/Library/Preferences | grep -i vim | |
org.vim.MacVim.LSSharedFileList.plist | |
org.vim.MacVim.plist | |
Keyboard modifiers are: @ = command, ~ = option, $ = shift, ^ = control. I had | |
to use "@\$h" on the command line because otherwise the $ would be interpreted | |
as a variable prefix by bash. | |
As a quick aside, if you want to change a shortcut in another app, find the app | |
domain in your preferences folder and the name of the menu command to use in | |
the [value] argument. For example, to replace <Command-q> with | |
<Command-Shift-q> for closing Google Chrome (so I don't fat finger it), I used: | |
$ defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Quit Google Chrome" "@\$Q" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In my ~/.gvimrc file, I include: | |
" key unbinding | |
if has("mac") | |
macm File.New\ Tab key=<nop> | |
macm File.Close key=<nop> | |
macm File.Close\ Window key=<nop> | |
macm File.Print key=<D-P> | |
macm File.New\ Window key=<nop> | |
macm Tools.List\ Errors key=<nop> | |
macm File.Save key=<nop> | |
endif | |
That lets me reclaim <D-t>, <D-w>, <D-W>, <D-l>, and <D-s>. Use :help :macmenu | |
to find more info on fiddling with the menu. | |
(in vim config language, <D-t> means <Command-t>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now I can remap to my hearts content (in ~/.vimrc): | |
if has("mac") | |
map <D-w>s <C-w>s " create window splits with <Command-w>{s,v} | |
map <D-w><D-s> <C-w>s " in case I fat finger it | |
map <D-w>q <C-w>q | |
map <D-w><D-q> <C-w>q | |
map <D-w>v <C-w>v | |
map <D-w><D-v> <C-w>v | |
imap <D-w>s <C-w>s " create window splits with <Command-w>{s,v} | |
imap <D-w><D-s> <C-w>s " in case I fat finger it | |
imap <D-w>q <C-w>q | |
imap <D-w><D-q> <C-w>q | |
imap <D-w>v <C-w>v | |
imap <D-w><D-v> <C-w>v | |
imap <D-w> <C-w> | |
imap <D-p> <C-p> | |
imap <D-n> <C-n> | |
map <D-t> :CommandT<CR> | |
noremap <D-t> :CommandT<CR> | |
inoremap <D-t> :CommandT<CR> | |
" paste current yank buffer | |
inoremap <D-V> <esc>""pi | |
map <D-s> :w<CR> " just save | |
imap <D-s> <esc>:w<CR> " save and return to normal mode (saves a keystroke) | |
" navigate splits quickly with the normal movement keys | |
inoremap <D-h> <esc><C-w><C-h> | |
inoremap <D-j> <esc><C-w><C-j> | |
inoremap <D-k> <esc><C-w><C-k> | |
inoremap <D-l> <esc><C-w><C-l> | |
noremap <D-h> <C-w><C-h> | |
noremap <D-j> <C-w><C-j> | |
noremap <D-k> <C-w><C-k> | |
noremap <D-l> <C-w><C-l> | |
" esc | |
inoremap <D-[> <esc> | |
" format paragraph | |
map <D-p> vipgq | |
endif | |
Nope, unfortunately. I've added to the has("mac")
section, in fact. The full vimrc is up at https://github.com/abachman/dotfiles/blob/master/.vimrc but I've updated the file here to reflect that block.
Because I'm using some of MacVim's native command key shortcuts (e.g., system copy and paste), I didn't want to do anything that would hurt those. I also want to make sure my .vimrc keeps working on my linux machines which all have caps lock remapped to control. It has caused some problems, with trying to use macvim in a terminal specifically, but it's been working well since I set it all up.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey, I know this is old, but I'm currently going through much the same thing - have you found any way to completely swap control and command for macvim? I'm wanting to do it across the (macvim) board, instead of just for a few key sequences.