In TextMate when you are editing a line of text and you press command + enter
it inserts a newline and brings the cursor to that new line without bringing down any text from the previous line. Is there a way to create this feature in Vim? Any insight would be much appreciated. Thanks!
Asked
Active
Viewed 307 times
1

ab217
- 16,900
- 25
- 74
- 92
2 Answers
5
The following mapping works:
inoremap <D-Enter> <ESC>o
The D
maps the command key on Mac. The answer by CatPlusPlus shows how this would work when using the Control key instead.
Note that mapping the command key only works in MacVim.
So in order to make this fail proof inside your vimrc do the following:
Check if a gui vim is running via:
let isGui = has("gui_running")
Check if you are running on a Mac via:
let isMac = has("mac")
Now adjust your mapping accordingly:
if(isGui && isMac) inoremap <D-Enter> <ESC>o else inoremap <C-Enter> <ESC>o endif

Thorsten Lorenz
- 11,781
- 8
- 52
- 62
3
Press <Esc>
to get back to the normal mode and then o
. If you really want to access that from insert mode, you can use this binding (add to your .vimrc):
inoremap <C-Cr> <C-O>o

Cat Plus Plus
- 125,936
- 27
- 200
- 224
-
...and typical of Vim, `O` does the opposite :) – alex Dec 14 '11 at 23:30
-
I tried this and it didn't work. When in insert mode, I try pressing command + enter but nothing happens. – ab217 Dec 14 '11 at 23:40
-
That's strange. This solution works for me. Try pressing ^VM instead of typing CR and other things being the same. – kshenoy Dec 15 '11 at 01:09