10

I'm trying to get it to be like default text editing in Mac. I tried map! <D-Left> 0 and map! <D-Right> $ in ~/.vimrc, but of course it didn't work. How can i do this?

9

As far as I know, the Command key modifier syntax (<D-...>) is only effective in GUI-mode instances of Vim on Mac OS X.

The Vim instance must be GUI-based because most terminal emulators (Terminal, iTerm, etc.) do not generate control sequences for Command key combinations, so a tty-only instance of Vim has no way to know that a Command key combination was ever pressed (the terminal emulator never sends anything across the tty interface). In fact, Terminal binds ⌘← and ⌘→ (Command-Left and -Right) to cycling through its open windows, so those keys are “already taken” when you are typing in the context of Terminal.

MacVim (when run in GUI mode) does come with functional mappings for (among other Mac-style keystrokes) <D-Left> and <D-Right> (respectively, to <Home> (nearly identical to 0) and <End> (identical to $)). One caveat is that these default mappings are established in $VIM/gvimrc, so they can only be properly overridden from your ~/.gvimrc.

I think there have been other GUI-based versions of Vim for Mac OS X, but MacVim seems like the only modern one.

Roughly, the startup files are processed in this order: $VIM/vimrc, ~/.vimrc, $VIM/gvimrc, ~/.gvimrc. Since MacVim’s $VIM/gvimrc maps <D-Left>, you need to put your mapping of <D-Left> (if you actually want to override it) in your ~/.gvimrc so that it has the “final say”.

  • thanks. i tried iTerm 2, it worked with that, but still...what a pain...welcome back into my life, Xcode – Marty Jan 22 '12 at 4:17

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.