防止 x 在 Vim 中删除折叠
我真的很喜欢 Vim 中的 zx
组合键(它可以折叠除文本活动区域之外的所有内容)。 然而,这似乎是一个相当危险的组合键。 在折叠上按 x
可删除该折叠。 因此,如果 z
被省略,或者被其他一些前面的组合键捕获,它 通过单独按 x
很容易意外删除折叠中的文本。
鉴于 dd 也可以用于删除折叠中的文本,如果我可以的话那就太好了 禁用 x
作为折叠删除工具。
- 如何禁用
x
作为折叠删除键?
I really like the zx
key combination in Vim (it folds everything but the active area of text).
However, it seems like quite a dangerous key combination.
Pressing x
on a fold deletes the fold.
Thus, if z
is omitted, or gets captured by some other preceding key combination, it
becomes quite easy to accidentally delete the text in a fold by pressing x
on its own.
Given that dd
can also be used to delete the text in a fold, it would be good if I could
disable x
as a fold deletion tool.
- How can
x
be disabled as a fold deletion key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只能使用以下简单的
映射来禁用折叠上的x
:与 @Eelvex 函数不同,它保留所有
x
功能,并且将还将在折叠上运行的x
重新映射到zx
。You can disable
x
on folds only with the following simple<expr>
mapping:Unlike @Eelvex function, it keeps all
x
functionality and will also remapx
being run on folds tozx
.1. 禁用
x
您可以通过以下方式完全禁用
x
(或任何其他键/组合):(x
,顺便说一句,是相同的asdl
notdd
)使用运算符时,闭合折叠始终作为一个整体包含在内,因此(afaik)不可能禁用
x
只是为了折叠删除。2. 自动打开折叠
一种可能的解决方法是当您“打开”折叠时自动打开折叠,这样
x
只会删除一个字符(正常情况下):但这使得折叠变得更加麻烦浏览代码。
3. 重新映射
x
如果您不介意禁用
x
的某些功能(例如删除到寄存器),这也可以完成这项工作:1. Disable
x
You can completely disable
x
(or any other key/combination) by:(
x
, by the way, is the same asdl
notdd
)A closed fold is always included as a whole when using operators, thus (afaik) it is not possible to disable
x
just for fold deletion.2. Automatically open the fold
A possible workaround is to have the fold automatically open when you are "on" it, so
x
would delete only one character (as normal):but this makes it more cumbersome to navigate through the code.
3. Remap
x
If you don't mind disabling some of
x
's functionality (eg delete into register), this will also do the job: