Reputation: 59323
In Vim normal mode, you can press ctrl+e and ctrl+y to scroll down and up, respectively. I'm trying to make a key-bind that lets me do this from insert mode as well. This is what I've got:
" Scroll up and down while in insert mode.
inoremap <C-e> <C-o><C-e>
inoremap <C-y> <C-o><C-y>
This works like expected, but it has a big flaw. It leaves insert mode, scrolls, then re-enters insert mode. This is relevant when it comes to undo, repeat command etc. and I would like to be able to scroll up and down without leaving insert mode. Thoughts?
Upvotes: 5
Views: 1414
Reputation: 60255
undojoin fixes the undo part of it:
ino <C-E> <Space><BS><ESC><C-E>:undojoin<CR>gi
The <Space><BS>
sequence makes sure there's an undo block to join with.
Surprisingly (to me) this doesn't help with the .
breakage, so this might leave you in just as annoying a spot as you're in now...
Upvotes: 2
Reputation: 6332
You could take a look at :h i_CTRL-X_CTRL-E
, which is a built-in insert-mode mapping to scroll:
*i_CTRL-X_CTRL-E*
CTRL-X CTRL-E scroll window one line up.
When doing completion look here: |complete_CTRL-E|
*i_CTRL-X_CTRL-Y*
CTRL-X CTRL-Y scroll window one line down.
When doing completion look here: |complete_CTRL-Y|
So in your case, this would probably do the trick:
inoremap <C-e> <C-x><C-e>
inoremap <C-y> <C-x><C-y>
Upvotes: 10