简体   繁体   English

将多个命令映射到Vim中的同一键

[英]Map several commands to the same key in Vim

I want to map a few different functions to one key in Vim, and have them happen one after the other. 我想将一些不同的功能映射到Vim中的一个键,并使它们一个接一个地发生。

For example, I'd like to map two different functions to the enter key - one that does something if the last character of the previous line is a brace, the other that does something if the last character of the previous line is a ~ . 例如,我想将两个不同的函数映射到enter键-一个在前一行的最后一个字符是大括号的情况下执行某些操作,另一个在前一行的最后一个字符是~执行某些操作。 But I want these in two separate functions. 但是我希望它们具有两个独立的功能。

Is this possible? 这可能吗?

PS I'll also be willing to go for a solution that lets me, within one function that maps the enter key , call any other mappings if it wasn't successful. PS我也将愿意寻求一种解决方案,使我可以在映射回车key一个函数内调用任何其他映射(如果未成功)。

(this should be a comment, but I'm afraid it's gonna be too long) (这应该是评论,但恐怕太长了)

So generally, you want to map that key to a call to a function. 因此,通常,您希望将该键映射到对函数的调用。 You cannot map it to two things, so just map it to one function, and inside that one, execute the other two functions - one that does something if the last character of the previous line is a space, and the other that does something if the last character of the previous line is a tilde. 您无法将其映射到两件事,因此只需将其映射到一个函数,然后在其中一个函数中执行其他两个函数-如果上一行的最后一个字符是空格,则一个函数将执行某些操作,如果执行则将另一个函数执行前一行的最后一个字符是波浪号。

Or you could use the mapped function to check what is the last character in the previous line, and then execute the - functions that do something - depending on what is that particular character. 或者,您可以使用映射函数检查上一行中的最后一个字符是什么,然后根据特定字符是什么,执行-做某事的函数。

I really have nothing more to go on here, so am just gonna leave it at this :-/ 我真的没有什么可继续的了,所以我就把它留在这里:-/


Edit after comments: Well, not to go into specifics here, but plugins are generally just functions. 注释后编辑:嗯,这里不做详细说明,但是插件通常只是函数。 Vim doesn't have subroutines, just several "types" of functions. Vim没有子例程,只有几个“类型”的函数。 Plugins are merely functions mapped to some keys. 插件仅仅是映射到某些键的功能。

Now, I don't use SuperTab plugin (heard of it, but that's about it) but if you go and wanter in it, you should be able to find out first, what are the keys mapped to (what is the function name) and from there, what does that particular function do. 现在,我不使用SuperTab插件(听说过,但仅此而已),但是如果您随意使用它,则应该能够先找出映射到的键是什么(函数名是什么)从那里开始,特定功能的作用是什么。 What arguments it takes and so on ... 它需要什么参数,等等...

From there it's merely a problem of finding out how to create one wrapper function that will test for previous character and based on that either execute that plugin function, or the one that you had in mind which does something else. 从那里开始,只有一个问题,那就是找出如何创建一个包装器功能来测试先前的字符,然后基于该包装器功能执行该插件功能,或者您打算执行的其他操作。

Not sure what you ment by "generic way". 不确定您通过“通用方式”提出了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM