TextMate's Command + Enter in Vim?

不羁岁月 提交于 2019-12-11 13:56:10

问题


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!


回答1:


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
    



回答2:


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


来源:https://stackoverflow.com/questions/8513160/textmates-command-enter-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!