Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Emulate TextMate's Command-Return Feature in Vim

Tags:

vim

textmate

TextMate has a feature where pressing Command-Return at any point inserts a new line below the current line placing your cursor at the beginning of the new line. This works much (exactly?) like pressing 'o' while in command mode in Vim.

Is there a way to emulate this TextMate feature while in insert mode in Vim? The same question phrased differently: Can I make Cmd-Return in insert mode do what 'o' does in command mode?

like image 751
dstrelau Avatar asked Oct 06 '09 15:10

dstrelau


2 Answers

Untested, since I don't use a Mac, tried with Ctrl-Return (<C-CR>). Ctrl-O executes a single command in normal mode.

:inoremap <D-CR> <C-O>o
like image 70
Jörn Horstmann Avatar answered Nov 17 '22 18:11

Jörn Horstmann


Updating this page to say that Jörn's answer worked for me, too, although it's worth noting that in Snow Leopard or higher, you have to disable the Full Screen menu option, because that's also mapped to Cmd-Enter by default. So here's what I have in my ~/.gvimrc:

macmenu Window.Toggle\ Full\ Screen\ Mode key=<nop>
inoremap <D-CR> <C-O>o
like image 43
Elliot Winkler Avatar answered Nov 17 '22 17:11

Elliot Winkler