Use mouse scroll wheel in Vim
Asked Answered
P

6

59

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

Primeval answered 29/8, 2011 at 0:40 Comment(2)
Suggestion: Check out MacVim. It has some nice Cocoa bindings.Homoeo
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=<mode> 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://mcmap.net/q/238559/-how-do-i-scroll-through-a-terminal-using-vim-8-1-39-s-new-terminal-termpack-support-closed/969196 (I already use CTRL-Z for that though...)Kaikaia
A
115

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.

Arista answered 27/10, 2015 at 0:43 Comment(7)
Worked perfectly for terminal also. In case, there is a problem, try cmd+r and then try this conditionAtrophy
:set mouse=n if you only want scrolling enabled in normal mode.Parette
Works in vim in Bash on Windows too.Exarchate
awesome! but how would you scroll horizontally when lines are long and set unwrap?Ogbomosho
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.Hausfrau
Do you know how to make it work in Windows ?Netty
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 <Enter> on it.Schenck
L
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.

Litter answered 27/12, 2017 at 12:33 Comment(1)
thanks a ton for this... looking specifically for this for hours.Shoot
Y
4

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

Yazzie answered 10/1, 2012 at 23:1 Comment(0)
N
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.

Nicki answered 21/10, 2011 at 11:45 Comment(0)
A
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.

Atalanta answered 8/1, 2014 at 14:19 Comment(0)
B
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.

Babylonia answered 10/11, 2016 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.