Hacker News new | ask | show | jobs
by snide 2308 days ago
I was one of those vim users that was stuck on MacVim for years because my brain was too wired to hitting "cmd-s" for save and other dedicated app niceties. I mean, sure I can :w or bind it to another key, but there are a couple shared OS-level shortcuts like this I just like to retain. No worry, iTerm2 can capture ANYTHING, and rebind it as needed. This means I have a few remaps like "cmd-s" in iterm2 to map to obscure key combinations, which I then have vim interpret and pass along to whatever I want to bind over there. I had no idea the feature existed for years. And sure, I know you're all laughing, why would I even do such a thing... but vim is vim, and we all have our own weird version of it.

iTerm2 is amazing. I've been using it for years daily and it is 100% one of the best, most reliable pieces of software in my toolkit, right next to Alfred.

Show you love for George and contribute to his Patreon[0]. We always love to complain about how to make money with open source on HN. I'd love to see him making a lot more than he does, if for no other reason than we can get more people working full time on the project and provide some redundancy for a critical tool we all love. I wish I could pay for it, but I guess Patreon works.

[0]: https://www.patreon.com/gnachman

2 comments

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!

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.

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.
Other Vim user here. I was stuck on MacVim as well, but for mouse support. That's until I discovered that `set mouse=a` in Vim and using iTerm instead of the default Terminal essentially gave me the same thing.

Then I went into the tmux rabbit hole, but I never really liked iTerm's integration so I don't use it.