TextMate 的 Command + Enter 在 Vim 中? [英] TextMate's Command + Enter in Vim?

查看:43
本文介绍了TextMate 的 Command + Enter 在 Vim 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 TextMate 中,当您编辑一行文本并按 command + enter 时,它会插入一个换行符并将光标带到该新行,而不会从前一行中删除任何文本.有没有办法在 Vim 中创建这个功能?任何见解将不胜感激.谢谢!

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!

推荐答案

以下映射有效:

inoremap <D-Enter> <ESC>o

D 映射 Mac 上的命令键.CatPlusPlus 的回答显示了当使用 Control 键时这是如何工作的.

The D maps the command key on Mac. The answer by CatPlusPlus shows how this would work when using the Control key instead.

请注意,映射命令键仅适用于 MacVim.

Note that mapping the command key only works in MacVim.

因此,为了在您的 vimrc 中进行此故障证明,请执行以下操作:

So in order to make this fail proof inside your vimrc do the following:

  • 通过以下方式检查 gui vim 是否正在运行:

  • Check if a gui vim is running via:

let isGui  = has("gui_running") 

  • 通过以下方式检查您是否在 Mac 上运行:

  • 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
    

  • 这篇关于TextMate 的 Command + Enter 在 Vim 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆