VIM - 如何根据行是否为空为键分配不同的映射?
我想根据上下文分配不同的命令。
我正在尝试做这样的事情:
if line is empty:
map x key to y command
else
map x key to z command
I want to assign different commands depending on context.
I'm trying to do something like this:
if line is empty:
map x key to y command
else
map x key to z command
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它通常是通过
映射来实现的:当您要使用 NerdCommenter 时,您被迫不使用“nore”:
将
''
替换为所需的代码因为我不明白你所说的“附加评论”是什么意思。It is normally achieved by
<expr>
mapping:As you are going to use NerdCommenter, you are forced not to use “nore”:
Replace
''
with the desired code as I do not understand what you mean by “appending a comment”.更好的方法是使用一个函数,其行为取决于该行的内容。那么您就不必为不同的映射而烦恼。例如:
然后映射所需的键来调用此函数:
A better approach would be to have a single function whose behaviour depends on the contents of the line. Then you don't have to bother with different mappings. For example:
And then map the desired key to call this function: