[英]How do I manually execute a key combo from a Vim script file?
Say I want to run the key combo <Ce>
five times from a Vim script. 假设我要从Vim脚本中运行键组合
<Ce>
五次。 Is that possible? 那可能吗? If so, how is it done?
如果是这样,怎么做?
Specifically, I need this because I want to map a key to nudge the viewport one fourth of the screen height in a direction. 具体来说,我需要这样做是因为我想映射一个键以将视口在某个方向上移动到屏幕高度的四分之一。 For that I need to combine the function
winheight(".")
with the key combo <Ce>
somehow. 为此,我需要以某种方式将功能
winheight(".")
与组合键<Ce>
组合在一起。
Note: I know I can change the option 'scroll'
to set the number of lines <Cu>
and <Cd>
scroll, but that key combo also moves the cursor. 注意:我知道我可以更改选项
'scroll'
来设置<Cu>
和<Cd>
滚动行数,但是该组合键也可以移动光标。 Additionally, I don't know how to set the 'scroll'
option to scroll a portion of the window height, except that it scrolls half the window height when I set it to 0. 另外,我不知道如何设置
'scroll'
选项来滚动一部分窗口高度,只是当我将其设置为0时它滚动了一半的窗口高度。
For simple commands, :norm[al][!]
is sufficient. 对于简单的命令,
:norm[al][!]
就足够了。 For example, to yank a line: 例如,要拉线:
norm! yy
For special characters, use :exe[cute] "norm[al][!]"
. 对于特殊字符,请使用
:exe[cute] "norm[al][!]"
。 For example, to do 5<Ce>
: 例如,执行
5<Ce>
:
exe "norm! 5\<C-e>"
With exe
, other code can be inserted by using multiple arguments: 使用
exe
,可以使用多个参数插入其他代码:
exe "norm!" winheight(".")/4 "\<C-e>"
However, arguments are joined with spaces, which are then interpreted literally. 但是,参数用空格连接,然后按字面意义进行解释。 To avoid this, use
.
为避免这种情况,请使用
.
to join arguments. 参加辩论。 Thus, for the desired effect:
因此,为了达到预期的效果:
exe "norm!" winheight(".")/4 . "\<C-e>"
See :help norm
and :help exe
for more information. 有关更多信息,请参见
:help norm
和:help exe
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.