如何映射 Shift-Enter [英] How to map Shift-Enter

查看:26
本文介绍了如何映射 Shift-Enter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义 Vim 中 Normal 模式下 Enter 键的行为.这是我的 .vimrc:

I am trying to customize the behaviour of Enter key in Normal mode in Vim. Here is my .vimrc:

nmap <CR> o<Esc>
nmap <S-CR> i<CR><Esc>

我试图让 Enter 按下时在当前行后简单地附加一个换行符.但是,当按下 Shift-Enter 组合时,我想在光标处断开当前行.

I am trying to make Enter simply append a newline after the current line when pressed. However, when the Shift-Enter combination is pressed, I want to break the current line at the cursor.

后者不起作用.每当我按 Shift-Enter 时,它只会附加一行而不会在光标处断行.

The latter does not work. Whenever I press Shift-Enter it just appends a line without breaking it at the cursor.

推荐答案

由于键盘输入是在内部处理的方式,不幸的是,这在今天的 Vim 终端版本中通常是不可能的 (<S-CR> 应该可以在所有平台上的 GVIM 和 Windows 控制台 Vim 中工作).这是一个已知的痛点,也是 vim_dev 和 #vim IRC 频道上各种讨论的主题.

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today in the terminal version of Vim (<S-CR> should work in GVIM on all platforms, and in the Windows console Vim). This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

有些人(最重要的是 Paul LeoNerd Evans)想要解决这个问题(即使对于支持这个的终端中的控制台 Vim),并且已经提出了各种建议,cp.http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa458b1f8b/a>

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

但截至今天,还没有补丁或志愿者出现,尽管许多人表示希望在未来的 Vim 8 主要版本中拥有它.

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

如果您在正常模式下映射 <CR>,它会干扰命令行窗口中历史项目的选择,并会干扰快速修复/位置列表窗口中光标下的错误!(除非您添加以下内容:)

If you map <CR> in normal mode, it'll interfere with selection of history items in the command-line window and with jumping to error under cursor in quickfix/location list windows! (Unless you add the following:)

:autocmd CmdwinEnter * nnoremap <CR> <CR>
:autocmd BufReadPost quickfix nnoremap <CR> <CR>

关于:nmap的注意事项:

你应该使用:noremap;它使映射不受重映射和递归的影响.

Note on :nmap:

You should use :noremap; it makes the mapping immune to remapping and recursion.

这篇关于如何映射 Shift-Enter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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