Say I want to run the key combo <C-e>
five times from a Vim script. 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 <C-e>
somehow.
Note: I know I can change the option 'scroll'
to set the number of lines <C-u>
and <C-d>
scroll, but that key combo also moves the cursor. 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.
For simple commands, :norm[al][!]
is sufficient. For example, to yank a line:
norm! yy
For special characters, use :exe[cute] "norm[al][!]"
. For example, to do 5<C-e>
:
exe "norm! 5\<C-e>"
With exe
, other code can be inserted by using multiple arguments:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With