How to bind vim (through tmux) to Cmd key

£可爱£侵袭症+ 提交于 2020-01-03 17:42:08

问题


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?


回答1:


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>==


来源:https://stackoverflow.com/questions/9450905/how-to-bind-vim-through-tmux-to-cmd-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!