Vim 在按键映射方面的奇怪之处

发布于 2024-08-02 16:29:21 字数 210 浏览 1 评论 0原文

我喜欢在不进入插入模式的情况下插入空行,并且我使用了这个键盘映射:

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 技术交流群。

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

发布评论

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

评论(3

绝不服输 2024-08-09 16:29:21

Vim 对于编写映射命令的方式非常直白 - 它实际上是在执行 之前处理映射中的空间。换句话说,您的映射执行以下操作:

nnoremap go o<SPACE><ESC>

您应该将其更改为:

nnoremap go o<ESC>

并确保映射中没有任何额外的空格!

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:

nnoremap go o<SPACE><ESC>

You should change it to:

nnoremap go o<ESC>

And make sure you don't have any extra spaces in the mapping!

我不是你的备胎 2024-08-09 16:29:21

我同意“太多的php”。
这是我的 .vimrc 中的相关部分,

nnoremap <A-o> o<ESC>k
nnoremap <A-O> O<ESC>j

我认为它更快,因为您将光标返回到原始行(尽管不在原始字符上)。

I agree with "too much php".
This is the relevant section from my .vimrc

nnoremap <A-o> o<ESC>k
nnoremap <A-O> O<ESC>j

I think it's faster since you get the cursor back at the original line (Although not on the original character).

近箐 2024-08-09 16:29:21

和往常一样,vim wiki 有一个有用的提示:快速添加和删除空行。诀窍是在添加新行之前设置粘贴,然后设置nopaste。此外,这将设置一个标记来记住光标位置并跳回到您所在的位置。

nnoremap go :set paste<CR>m`o<Esc>``:set nopaste<CR>
nnoremap gO :set paste<CR>m`O<Esc>``:set nopaste<CR>

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 afterwards set nopaste. Additionally, this will set a mark to remember the cursor position and jump back to where you were.

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