Vim 在按键映射方面的奇怪之处
我喜欢在不进入插入模式的情况下插入空行,并且我使用了这个键盘映射:
nomap go o <esc>
这确实创建了空行,但引入了一些奇怪的行为。我设置了智能缩进和自动缩进。新行跟随缩进,但不会删除缩进,即使手动这样做会自动删除多余的空格。它还在每次光标所在的位置添加一个空格。
有人对解释这种行为有任何见解吗?
I like to insert blank lines without entering insert mode and I used this keymapping:
nomap go o <esc>
This does create the blank line but introduces some weird behaviour. I have smart indent and autoindent set. The new line follows the indents but doesn't remove them even though doing so manually automatically removes the redundant whitespace. It also adds a single whitespace where the cursor is each time.
Anyone have any insights as to explain this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Vim 对于编写映射命令的方式非常直白 - 它实际上是在执行
之前处理映射中的空间。换句话说,您的映射执行以下操作:您应该将其更改为:
并确保映射中没有任何额外的空格!
Vim is very literal with how you write your mapping commands - it's actually processing the space in your mapping before it does the
<ESC>
. In other words, your mapping does this:You should change it to:
And make sure you don't have any extra spaces in the mapping!
我同意“太多的php”。
这是我的 .vimrc 中的相关部分,
我认为它更快,因为您将光标返回到原始行(尽管不在原始字符上)。
I agree with "too much php".
This is the relevant section from my .vimrc
I think it's faster since you get the cursor back at the original line (Although not on the original character).
和往常一样,vim wiki 有一个有用的提示:快速添加和删除空行。诀窍是在添加新行之前
设置粘贴
,然后设置nopaste
。此外,这将设置一个标记来记住光标位置并跳回到您所在的位置。As usual, the vim wiki has a useful tip: Quickly adding and deleting empty lines. The trick is to
set paste
before adding the new line and afterwardsset nopaste
. Additionally, this will set a mark to remember the cursor position and jump back to where you were.