I often find myself accidentally pressing <c-e>
/^E
while in normal mode inside a terminal buffer. This causes the terminal buffer to scroll down and a line with a ~
is displayed, like when your file doesn't reach the bottom of the screen.
I've created a mapping that stops ^E
from being called if the current buffer is a terminal.
nnoremap ^E :call ScrollStop()<cr>
function! ScrollStop()
if &buftype !=# "terminal"
normal! ^E
endif
endfunction
I would now like to do the same thing for ^Y
by extending the function to allow me to pass in either ^E
or ^Y
but all my attempts so far have caused various errors, mainly E119: Not enough arguments for function: ScrollStop
.
Thanks to the comments by @GaryJohn we've narrowed the problem down. If we have the following function:
function! MyScroll(key)
exe 'normal' a:key
endfunction
and we call it via :call MyScroll('^E')
where ^E
is entered via ctrl-v + crtl-e then we get the expected result, the buffer scrolls down one line.
If however we create a mapping :nnoremap ^E :call MyScroll('^E')<cr>
then press ^E
, we get an error E471: Argument required: normal
. This happens for both Vim and Neovim.
^E
and^Y
, why could you just not call the function with:call ScrollStop('E')
and:call ScrollStop('Y')
respectively? Why would it need to be the control character and not just a string?:function MyScroll(key)
:exe 'normal' a:key
:endfunction
:call MyScroll('^E')
where I entered^E
by typingCtrl-V Ctrl-E
.