Hacker News new | ask | show | jobs
by AlchemistCamp 2307 days ago
Really? I didn't think iTerm would pass along cmd keys, which is the primary reason I use MacVim instead.

For example, I use these kinds of mappings:

    nmap <D-j> <C-j>
    nmap <D-k> <C-k>
    nmap <D-h> <C-h>
    nmap <D-l> <C-l>
    nmap <C-[> <C-T>
    nmap <D-]> <C-]>
    nmap <D-[> <C-]>
    nmap <D-p> :CtrlP pwd<cr>
    nmap <D-r> :CtrlPBufTag<cr>
    nmap <D-e> :CtrlPMRUFiles<cr>
This way, when on a Mac I can use cmd in place of ctrl for various commands I use all the time that are less convenient with ctrl.

In my .gvimrc, I added the following to make sure that cmd-p and cmd-l don't get incercepted: "Disable the print key for MacVim" if has("gui_macvim") macmenu &File.Print key=<nop> macmenu &Tools.List\ Errors key=<nop> "macmenu &MacVim.Hide\ MacVim key=<nop> set macligatures endif

If there's any possible way to accomplish the same with iTerm, I'd give it another try!

3 comments

Sorry for seeing this late. Basically, iTerm allows you to send Escape sequences and even Vim special characters.

Here's a screenshot http://snid.es/d156c6b7deea

In mine, under profiles/keys, I've set ⌘s to [17~

This is essentially F6, which I then bind in vim to

nnoremap <F6> :w<CR> imap <F6> <Esc>:w<CR>

I do this with a lot of ⌘ or otherwise unbindable settings (again, this only effects iterm2). This is how you can get iterm2 to pick up any keybinding and send it to vim as something else.

I think this is a bit different than what I wrote above. I just want to send the command key as itself.

It looks like you're changing your .vimrc itself.

How would I get iTerm to just send cmd+p as cmd+p? I tried making a keymapping in that menu with "Key Combination": "cmd+p", "Action": "Do Not Remap Modifiers". Rather than sending it to VIM, it still brings up a print screen dialogue.

Similarly, I can't get cmd+[, cmd+], cmd+h (or j, k, l, etc) to send through to VIM.

With both VS Code and MacVim, that stuff is easily configurable. My failure (thus far) to figure out how to do the same with iTerm is why I don't really use it.

AFAIK there is no way to tell vim about such a keystroke. If neovim adds something I’ll support it.
Sure there is! This has been in MacVim for many years and in NeoVim for four years and two days:

https://github.com/mgraczyk/neovim/commit/ac2b770c25c234ee3f...

Not a vim user but iTerm2 settings have a section for rebinding modifier keys, (plus you also have karabiner-elements)
I don't have karabiner-elements, but doesn't it basically just remap keys across your whole system (much like my mechanical keyboard can)?

I don't want change my cmd-keys into control keys system wide. I just want to be able to map my cmd-keys in vim (which to be honest is the lion's share of what I use any terminal for).

Karabiner-elements is good for mapping single keys to other keys. It doesn’t handle key combinations. (There is something called complex modifiers, but I can’t figure out how to edit them.)

BetterTouchTool is good for mapping key sequences. Further, it can do it selectively based on what application is active.

The complex modifiers are just a json file that’s fairly easy to edit. I have a file that has caps+hjkl to arrow keys. Caps by itself is Esc. caps with anything else is Cmd-shift-option-control+anything else. And finally right shift plus caps toggles caps lock.
Wow. That’s good know. I will poke around. Thank you.

I like KE and have contributed to the dev several times. In typical modest Japanese fashion, contributions are limited to $10 max. Mapping ‘Enter’ to ‘Caps’ and ‘right shift‘ to ‘right command‘ staved off RSI in my right pinky, so I’m happy to send him/her some cash.

https://pqrs.org/osx/karabiner/json.html if you want to know a bit more about them
Is it per program or global? If it's global, it fixes nothing for this specific issue.
BTT can do both. Karabiner Elements is global only.