Vim: remap 'D' modifier on linux

1

1

I'm using Mac-oriented vimfiles with linux. In this config modifier D (Cmd key on Mac) is intensively used. I don't want to change every D to M, but I want to remap D to something like Meta or Alt. Is it possible?

petRUShka

Posted 2013-04-22T21:42:57.923

Reputation: 245

Answers

3

D is the "Apple/Cmd" key. The only version of Vim that understands it is MacVim and only in its GUI incarnation: D is simply a non-existing key for CLI Vim in any terminal emulator and GVim on any platform.

The immediate consequence is that you'll actually need to replace/duplicate all the <D- mappings in your config if you want it to be portable across environments.

Another somewhat softer way to deal with this issue is to branch your ~/.vimrc. Here is how I do it, there might be better ways:

let os=substitute(system('uname'), '\n', '', '')

if has('gui_running')
    if os == 'Darwin' || os == 'Mac'
        " GUI-only stuff for Mac OS X
    elseif os == 'Linux'
        " GUI-only stuff for Linux
    endif
else
    if os == 'Darwin' || os == 'Mac'
        " CLI-only stuff for Mac OS X
    elseif os == 'Linux'
        " CLI-only stuff for Linux
    endif
endif

Considering the unnecessary mess introduced by splitting an honest ~/.vimrc into many vimrc.after and plugin_name.vim, I'll let you find the correct location for that block of code on your own.

Vim's ubiquity is a strong plus: using and maintaining platform-specific mappings is both impractical and counter-productive. I strongly suggest you choose a better, more portable, strategy for your custom mappings: use the "Control" key or even better the <leader> key. See :h mapleader.

Also, using someone else's config is a very bad idea. You should drop that "package" and take care of your own config yourself.

romainl

Posted 2013-04-22T21:42:57.923

Reputation: 19 227

I'd like to inject a touch of moderation here: it's not necessary simply to junk the dotfile package you're using, but it would be advisable to review each file in it and construct your own dotfiles from just the bits you find worthwhile (i.e., understandable and applicable to your situation). This still counts as maintaining your own configuration, but doesn't imply that you have to ditch everything you're using and start from scratch -- because who wants, or needs, to do that? – Aaron Miller – 2013-04-22T22:13:18.313

1New vim users need to do that as part of the learning process: using a distribution only hides things, create bad habits and generally prevent proper learning. Unfortunately, they often want the bells and whistles without having to put any effort in it, hence the success of YADR/SPF13/JANUS among newbies – romainl – 2013-04-22T22:19:36.537

I don't disagree; the same problem exists among Emacs users, but tends to be even worse because newbies find elisp so intimidating. Fortunately (?), Emacs is nigh-impossible to use until you've thoroughly customized it, so the problem tends to limit itself. – Aaron Miller – 2013-04-23T15:04:46.513

Thanks for your advice. It isn't a first vim config for me. So I try to understand what is under the hood :) – petRUShka – 2013-04-26T08:43:06.097