58

My .vimrc has the following lines

set mouse=a
map <ScrollWheelUp> <C-Y>
map <ScrollWheelDown> <C-E>

But when I scroll up using the mouse wheel, I'd get the text above Vim. For example, I'd get my terminal session text if I'd just started Vim. I'm initially experimenting with the mouse scroll wheel on help files, then move on to other files, hence the a option.

What else do I need to set? I'm using Snow Leopard and Vim 7.3 inside a Terminal.

Here, I just did a wheel up. See the Terminal session at the top. enter image description here

Kit
  • 30,365
  • 39
  • 105
  • 149
  • 1
    Suggestion: Check out [MacVim](http://code.google.com/p/macvim/). It has some nice Cocoa bindings. – Chetan Aug 29 '11 at 01:34
  • Oddly I like this behavior and I'm looking for a way to always scroll terminal history while using vim. The mouse scrolling from vim can be generally be fixed by setting the desired `mouse=` as mentioned below, but when vim sets the terminal in window mode (sorry if that's not the correct terminology) some terms retain past history while others hide it and scroll within the window, mimicking vim's behavior. I think that's a terminal emulator issue though, but vim 8.1 apparently has some workaround - https://stackoverflow.com/q/50535334/969196 (I already use CTRL-Z for that though...) – Thomas Guyot-Sionnest Aug 14 '20 at 15:51

6 Answers6

111

Using vim in iTerm 2 in OS X, you can :set mouse=a to enable scrolling with the scroll wheel, as well as selecting to enter Visual mode, etc.

taylor
  • 1,568
  • 1
  • 10
  • 11
  • 3
    Worked perfectly for terminal also. In case, there is a problem, try cmd+r and then try this condition – ShikharDua Jan 31 '17 at 18:45
  • 11
    `:set mouse=n` if you only want scrolling enabled in `normal` mode. – Filip Kilibarda May 12 '17 at 18:49
  • Works in vim in Bash on Windows too. – x__x Apr 16 '19 at 10:18
  • awesome! but how would you scroll horizontally when lines are long and set unwrap? – kumetix Oct 24 '19 at 17:42
  • 1
    You can apply it to all vim windows automatically by adding the line `set mouse=a` to your .vimrc. Your vimrc probably lives in the `~/` directory. – Eduardo Barrera Jan 31 '20 at 20:48
  • Do you know how to make it work in Windows ? – Ayush Apr 27 '21 at 19:49
  • Weird follow-on question, but would there be a way to enable scroll but disable clicking? The use-case for this would be when opening up tar files in vim. I'd like to be able to scroll through the files in the tar but don't want it opening up the file within the tar if I click it (happens when I click the Terminal to bring it in scope among other windows). I only want to open up files when explicitly hitting `` on it. – tubensandwich Jun 22 '23 at 18:31
24

If you use iTerm, you can simply execute the following command:

defaults write com.googlecode.iterm2 AlternateMouseScroll -bool true

This will enable mouse scrolling without having to add anything in your .vimrc.

BiBi
  • 7,418
  • 5
  • 43
  • 69
4

You could try using https://github.com/brodie/mouseterm, which adds mouse reporting support to Terminal.

asmeurer
  • 86,894
  • 26
  • 169
  • 240
2

I had the same problem using Mac's Terminal. I think it is an issue with it. Once I upgraded to Lion I don't have the problem of scrolling in vim. Please consider using iTerm2. It will solve the problem of scrolling and gives you the 256 term colors.

satran
  • 1,222
  • 4
  • 16
  • 27
0

Just an option. I missed a lot of functionality in OSX, which I was totally used to from linux. The best setup that comes close to urxvt + vim is to use iTerm2 + MacVim.

Just a few things is missed and got back this way:

  • Pos1+End,
  • PgUp+PgDown,
  • Mouse support,
  • as-expected-scolling,
  • cool arrangements and the intuitive keyboard movement I horribly missed from the gorgeous i3-wm,
  • nerdy dimm effects and
  • sloppy focus (focus follows mouse).

Unfortunately the most outstanding feature "middlemouse-clipboard" from xorg is not implemented in any term I know. Well as said its an xorg feature, and will probably never be implemented.

If your on the way to make the terminal useful in OS X don't forget the masterpiece homebrew.

ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
0

Mouse wheel action works when your TERM is set to xterm not to linux. So, please set "setenv TERM xterm" in the .cshrc or .bashrc, then it will work.