macos - 在命令模式下将按键重新映射到 <Esc> 不起作用

标签 macos vim remap

我在成功将 key 重新映射到 <Esc> 时遇到一些问题。我已经尝试过使用多个字符,所以假设我想重新映射 1<Esc> 。在我的.vimrc文件中,我添加了以下行:

noremap! 1 <Esc>

这对于退出插入模式效果很好,但是当我处于命令模式时,命令会被执行而不是退出。例如,在正常模式下,如果我输入:

/searchtext1

显示“searchtext”的搜索结果,而不是退出到正常模式而不进行搜索。对于以 : 开头的命令也是如此。有解决方法吗?我是否使用了错误的 map 功能?

我从终端使用 Vim,尽管在 MacVim GUI 上测试后,它也有这个问题。

最佳答案

根据文档,这是预期行为。它是 vi 兼容性的一部分。

如果你看:h i_esc | /*3 Go您将看到以下段落。

*3 Go from Command-line mode to Normal mode by:
   - Hitting <CR> or <NL>, which causes the entered command to be executed.
   - Deleting the complete line (e.g., with CTRL-U) and giving a final <BS>.
   - Hitting CTRL-C or <Esc>, which quits the command-line without executing
     the command.
   In the last case <Esc> may be the character defined with the 'wildchar'
   option, in which case it will start command-line completion.  You can
   ignore that and type <Esc> again.  {Vi: when hitting <Esc> the command-line
   is executed.  This is unexpected for most people; therefore it was changed
   in Vim.  But when the <Esc> is part of a mapping, the command-line is
   executed.  If you want the Vi behaviour also when typing <Esc>, use ":cmap
   ^V<Esc> ^V^M"}

{Vi: ... } 开头的部分正在谈论 vi 兼容性并解释您所看到的行为。

映射:noremap! 1 <c-u><bs>会做你想做的事。也就是彻底删除当前行。这是列表中的第 2 条。

关于macos - 在命令模式下将按键重新映射到 <Esc> 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24396516/

相关文章:

java - 将 JNI 模块放在 Linux 或 OS X 中的什么地方

java - 无法在 macOS 上初始化 Cassandra

mysql - docker 。 MySQL 镜像。无法更改 my.cnf 文件

vim - 防止自动完成 vim-go 分屏

linux - 我可以恢复上次更改 vim 时丢失的代码吗?

c++ - 我可以在 OpenCV 中使用重映射来获取点位置吗

linux - 运行 Elasticsearch Mountain Lion Mac OSX

search - 在 vim 中用另一行代码替换一行代码?

macos - 在 OS X 中重新映射按键

c++ - Farneback 光流 - 处理视野外的像素、流结果错误的像素、不同尺寸的图像