无法映射< S-CR>在Vim中 [英] Can't Map <S-CR> in Vim

查看:148
本文介绍了无法映射< S-CR>在Vim中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在周末获得了我的第一台Mac,我正在努力调整.我的vimrc中的这行代码可以在Windows上使用,无法通过iTerm在vim中使用

Got my first Mac over the weekend, and I'm trying to get adjusted. This line in my vimrc, which worked on my windows, won't work with vim through iTerm

inoremap <S-CR> <Esc>

我希望Shift-Enter在插入模式下充当Escape.我已经尝试过使用Enter和Return键,但是这要求我在Macbook上使用Fn键,这与转义键一样令人讨厌.

I'm wanting Shift-Enter to act as Escape in insert mode. I've tried using Enter and Return, but that requires me to use the Fn key on my Macbook, which is just as annoying as the escape key.

我非常感谢您的帮助!

推荐答案

这里的问题是终端仿真.大多数终端无法区分非打印键[1]和那些与修饰键组合的键.

The problem here is with the terminal emulation. Most terminals cannot distinguish between non-printing keys [1] and those keys combined with modifier keys.

但是,如果您的终端应用程序具有重新映射按键组合的能力(例如,像iTerm2一样),您仍然可以使所需的组合起作用.将终端应用程序的组合映射到您永远不会使用的Unicode字符,然后将Vim中的该键映射到所需的效果,就可以解决此限制.

However, you can still make the desired combination work if your terminal application has the ability to remap key combinations (as iTerm2, for example, does). Map the terminal application's combination to some Unicode character you'll never use, then map that key in Vim to the desired effect, and you can get around this limitation.

对于此示例,在iTerm2中,打开键首选项"窗格,添加一个全局快捷键",输入shift和return,为其设置设置文本"操作,然后将✠(马耳他十字,但可以使用任意不太可能使用的Unicode字符)作为其值.在您的.vimrc中,添加以下行:

For this example, in iTerm2, open the Keys Preferences pane, add a Global Shortcut key, input shift and return, give it an action of Set Text, and then put ✠ (a Maltese Cross, but you could use any random unlikely-to-be-used Unicode character) as its value. In your .vimrc, add these lines:

" Map ✠ (U+2720) to <Esc> as <S-CR> is mapped to ✠ in iTerm2.
inoremap ✠ <Esc>

或者:

inoremap <S-CR> <Esc>
" Map ✠ (U+2720) to <S-CR>, so we have <S-CR> mapped to ✠ in iTerm2 and
" ✠ mapped back to <S-CR> in Vim. 
imap ✠ <S-CR>

现在在iTerm2中的Vim中输入<S-CR>最终将根据需要最终在Vim中产生<Esc>.

Entering <S-CR> in Vim in iTerm2 will now ultimately result in <Esc> in Vim as desired.

[1]:例如空格,制表符,输入,删除,控制,alt,转义.

[1]: E.g. space, tab, enter, delete, control, alt, escape.

这篇关于无法映射&lt; S-CR&gt;在Vim中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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