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?


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
    if os == 'Darwin' || os == 'Mac'
        " CLI-only stuff for Mac OS X
    elseif os == 'Linux'
        " CLI-only stuff for Linux

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.

  • 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 Apr 22 '13 at 22:13
  • 1
    New 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 Apr 22 '13 at 22:19
  • 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 Apr 23 '13 at 15:04
  • Thanks for your advice. It isn't a first vim config for me. So I try to understand what is under the hood :) – petRUShka Apr 26 '13 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.