Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I scroll up/down without leaving insert mode?

Tags:

vim

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?

like image 276
Hubro Avatar asked Jan 13 '13 20:01

Hubro


1 Answers

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>
like image 134
Daan Bakker Avatar answered Nov 15 '22 10:11

Daan Bakker