Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind vim (through tmux) to Cmd key

Tags:

vim

tmux

I usually use macvim, and have a number of key bindings using my macs command key. I'm trying to switch over to tmux, but none of those bindings are working. Any tips on how to modify my .tmux.config or .vimrc to get those bindings back?

like image 325
Forrest Avatar asked Dec 06 '22 16:12

Forrest


1 Answers

Do you, by any chance, use <D-> to emulate another editor's shortcuts?

You can use the command key for mappings only in MacVim. There is no Vim-specific workaround.

This is because this key is "intercepted" by Terminal.app (or iTerm.app) for its own use and isn't even registered by any CLI program. The only modifiers you can rely on in CLI Vim are Shift and Control. Even Option needs some workarounds to work and it can't be achieved without side effects.

While you can remap some keys/key-combinations in the preferences of both terminal emulators and/or use third party solutions/hacks to remap the command key I'd advise you to rethink your approach and consider using mappings that make more sense in Vim-world.

My recommendation is to use the <leader> key as the basis for all your custom mappings. The default <leader> is \ which is quite inconvenient. A lot of people change it to a more convenient key:

let mapleader=","

Here is an example from my ~/.vimrc:

nnoremap <silent> <leader>k :m-2<CR>==
like image 190
romainl Avatar answered Dec 14 '22 22:12

romainl