无法映射在维姆中

发布于 2024-10-25 07:14:38 字数 259 浏览 3 评论 0原文

周末拿到了我的第一台 Mac,我正在努力适应。我的 vimrc 中的这一行在我的 Windows 上工作,但无法通过 iTerm 与 vim 一起工作,

inoremap <S-CR> <Esc>

我希望 Shift-Enter 在插入模式下充当 Escape 。我尝试过使用 Enter 和 Return,但这需要我使用 Macbook 上的 Fn 键,这和退出键一样烦人。

我很感谢您的帮助!

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>

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.

I Appreciate the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假装不在乎 2024-11-01 07:14:38

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

但是,如果您的终端应用程序能够重新映射按键组合(例如 iTerm2 就是这样做的),您仍然可以使所需的组合发挥作用。将终端应用程序的组合映射到某个你永远不会使用的 Unicode 字符,然后在 Vim 中将该键映射到所需的效果,这样你就可以绕过这个限制。

对于此示例,在 iTerm2 中,打开“键首选项”窗格,添加一个全局快捷键,输入 Shift 和 Return,为其指定“设置文本”操作,然后输入 ✠(马耳他十字,但您可以使用任何随机的不太可能-be-used Unicode 字符)作为其值。在您的 .vimrc 中,添加以下行:

" 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 中输入 现在将最终根据需要在 Vim 中生成

[1]:例如空格、制表符、回车、删除、控制、alt、转义。

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

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.

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>

Or:

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>

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

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

酷遇一生 2024-11-01 07:14:38

这是因为对于 iTerm来说与相同,输入 Ctrl+V Return,然后输入 Ctrl+V< /kbd> Shift+Return 你会看到在两种情况下都插入了相同的字符。

因此,当您输入时Vim 获得并且您的映射不会被触发。

That's because for iTerm <S-CR> is the same as <CR>, type Ctrl+V Return then Ctrl+V Shift+Return and you'll see that the same character is inserted in both cases.

So, when you type <S-CR> Vim gets <CR> and your mapping is not triggered.

匿名的好友 2024-11-01 07:14:38

MacVim 相当于 GVim:Vim 的 GUI。您不通过 iTerm 运行 MacVim。您可以运行 GUI 版本 (MacVim.app) 或 CLI 版本 ($ vim)。

您可以从 CLI 启动 GUI,但 iTerm 的设置不会以任何方式干扰 MacVim 的设置。

在 MacVim 中,您的映射工作完美。

据我所知,所有或大多数“终端”将 视为与 相同。也许您应该尝试另一个序列,例如 jj

MacVim is the equivalent of GVim: a GUI for Vim. You don't run MacVim through iTerm. You either run the GUI version (MacVim.app) OR the CLI version ($ vim).

You can launch the GUI from the CLI but iTerm's settings won't interfere in any way with MacVim's settings.

In MacVim your mapping works perfectly.

As far as I know all or most "terminals" treat the same as . Maybe you should try another sequence like jj?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文