23

I'm using Vim in a terminal, so scrolling with the scroll wheel uses the \e[A and \e[B syntax (where \e symbolizes \x1b, or escape).

However, Vim interprets this by moving the cursor up or down a line. The desired behavior is that the screen is moved up or down, like <C-e> and <C-y> do.

How can I tell Vim to move the screen when I used my scroll wheel, while keeping the cursor on the same line? This should work in all common modes (insert, normal, visual select).

I've already tried, for example, :nnoremap <esc>[A <C-e> (replacing <esc> with a literal escape character inserted with Ctrl+V Esc), but this proved to be futile.

I'm using Vim 7.4.52 on Ubuntu 14.04 with GNOME.

3
  • Could you limit the question to an operating system or windowing environment? Feb 3, 2015 at 23:12
  • @200_success Alright, I've edited my environment into the question.
    – Doorknob
    Feb 3, 2015 at 23:14
  • I think this question should be tagged 'terminal' too. Is it un-editable because it's answered?
    – bsmith89
    Feb 3, 2015 at 23:21

3 Answers 3

20

As @Doorknob said in his comment, :set mouse=a fixes the problem.

3
  • 1
    Is there a way to do this without setting mouse=a? I don't want accidental clicks messing up my editing flow.
    – wchargin
    Apr 24, 2015 at 23:23
  • 2
    the a in mouse=a stands for all (not append). from :help mouse : "the mouse can be enabled for different modes ... Normally you would enable the mouse in all four modes with: :set mouse=a" at least in my vim when I enabled that it didn't mess up with mode switching (just enabled scrolling - and "click to go to the line")
    – Fawix
    Aug 27, 2017 at 21:42
  • 4
    Though this thread is old, for someone who wants set mouse=a without accidental clicks messing up flow, :map <LeftMouse> <nop> would do the trick.
    – Sunny Pun
    Nov 21, 2017 at 6:08
3

I know this is a few years late, but you can use nmap <Down> <C-e> nmap <Up> <C-y>

This worked for me.

1
0

The behavior that you want is what happens on my vim. I can't find a setting that turns it on/off. Maybe check the :help scrolling? scrolloff might be involved.

You could also consider using marks as a workaround.

  1. ma (set mark 'a')
  2. scroll the screen as you'd like
  3. `a (send cursor to mark 'a')
3
  • I get this behavior even without loading my vimrc (vim -u NONE). This is Vim 7.4 on Ubuntu 14.04 with GNOME.
    – Doorknob
    Feb 3, 2015 at 23:05
  • @Doorknob And I get the window instead of the cursor moving without my .vimrc (just set mouse=a). :help scrolling says that the scrolling behavior is platform specific. I'm using vim in iterm2 on OSX.
    – bsmith89
    Feb 3, 2015 at 23:07
  • Aha! :set mouse=a has fixed the problem for me. Edit that into your answer, and I'll accept it. Thanks!
    – Doorknob
    Feb 3, 2015 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.