Smooth scrolling for vim in Mac Terminal/iTerm?

10,259

I'm using iterm2, and I'm finding very nice functionality using vim 7.3 in the terminal with the following options:

set mouse=niv #or set mouse=a
set clipboard=unnamed

EDIT: set mouse=a also seems cool to use as indicated by the other suggestion.

What this does is automatically switches you into either visual mode from normal while selecting text, or into the mode that says -- (insert) VISUAL -- from insert mode. This also has the handy advantage over not setting these modes at all in that when you've got line numbers or relative line numbers, it'll go ahead and copy those numbers you likely don't want to copy. When it drops you into mouse-enabled visual mode this way, it avoids copying those line numbers, as it works to control the visual mode selection rather than the native terminal's selection (which gets suppressed). Scrolling works just fine throughout, keeping in mind that it selects everything from where you had started the selection to the bottom of the screen. Forget about ctrl+c/ctrl+v in vim - You use the vim yankypasta commands (y, yy, p, etc) to copy to the system clipboard:

http://vim.wikia.com/wiki/Mac_OS_X_clipboard_sharing#Comments

Again, iterm2 -- osx's built in terminal is trash. I don't really see your beef with line-by-line scrolling, as I'm happy with how this simply functions as vim should, but maybe it's for similar reasons to why I can't watch other people play video games out of motion sickness or why flourescent light and CRT monitor flicker messes with people's heads to the point of migraine. Try adjusting the refresh rate on your brain, you can feel the knob if you press into your temple hard enough and turn.

Share:
10,259

Related videos on Youtube

Eddy
Author by

Eddy

Updated on September 18, 2022

Comments

  • Eddy
    Eddy over 1 year

    Is it possible to get smooth scrolling (using the mouse scroll wheel or macbook touchpad) within a terminal on Mac OSX (Lion)? Furthermore, could I do this within vim?

    I find that smooth scrolling aids the reading of code, I don't like it when you can only scroll in discrete lines as opposed to continuous pixel-by-pixel scrolling.

    Thanks

    • Chris Page
      Chris Page almost 12 years
      You may have a better experience if you use a Vim application instead of using it within a terminal session (code.google.com/p/macvim, macvim.org/OSX). Is there a reason you need to use it within a terminal?
    • romainl
      romainl almost 12 years
      MacVim doesn't provide smooth scrolling either.
    • Breno Macena
      Breno Macena over 10 years
      Hi @romainl. I wonder how vim behaves if the buffer size (windows size) is really big (i.e. the size of the whole file). GOtta test this out. Then we could put a vim buffer inside a smooth scrolling GTK (or QT) widget and scroll the entire vim buffer inside the widget smoothly. This would have the added benefit that the cursor could be easily hidden like with modern editors. When the user moves the cursor, the widget would know (using the same API gVim uses) and recenter the scroll position accordingly.
    • Breno Macena
      Breno Macena over 10 years
      (cont'd.) Window splitting could even be accomplished by duplicating vim's full-file-length output into a new widget and scrolling the widget smoothly to the appropriate position. This would all require some simple arithmetic and good knowledge of a nice widget toolkit. Window splitting (horizontal and vertical) and scrolling and resizing the widgets would be the. The rest would be a piece of cake to do (menus, tabs, things that gVim and qVim already do).
    • Breno Macena
      Breno Macena over 10 years
      (cont'd.) This has the potential to vastly improve vim's performance too. Think about this: every time you scroll the console vim or g/qvim windows (currently), vim has to rewrite almost every character on the screen. If the vim buffer was full length, and scrolling was handled independently by a smooth-scrolling widget, vim would only need to update one line's worth of characters at a time whenever you move the cursor to a new line (or better yet, a single character when you move forward or backward one character). This would be a HUGE performance advantage for vim!
    • Breno Macena
      Breno Macena over 10 years
      Oh, I forgot to mention, and if you you haven't pieced it together already: these smooth animations I speak of would be pixel by pixel, not line by line. #:^)
    • romainl
      romainl over 10 years
      @trusktr, your idea sounds good, at least superficially, but redrawing is not the only reason why scrolling is jerky in Vim. Syntax scripts (and the underlying regex engine) are quite slow too and cutting the buffer in smaller slices is also a way to make syntax highlighting more usable. Somehow I doubt Vim would be able to open a 5000 LOC PHP file as quickly as it does now if it had to deal with all of it.
    • Breno Macena
      Breno Macena over 10 years
      @romainl Yeah, syntax scripts seems like they could cause slow loads running on 5000 LOC. This'll be interesting to test.
    • Breno Macena
      Breno Macena over 10 years
      Another small (possibly negligible for some) advantage of using scrollable widgets would be that you could render a small mini-buffer similar to how Sublime does.
  • Eddy
    Eddy over 12 years
    Unfortunately the plugin requires SIMBL, which isn't available for Lion
  • romainl
    romainl over 12 years
    I didn't know because I don't have Lion. MouseTerm is the only way to add mouse scrolling to Terminal.app I've ever heard of. It appears that some people have reported limited success in using SIMBL on Lion, did you try? Also I see that iTerm2 provides "mouse reporting" and scrolling but it will probably scroll line by line. As a side note I hardly scroll (up/down/j/k) anymore: I find /, ?, fF, tT and <C-f>/<C-b> a lot more useful.
  • Chris Page
    Chris Page almost 12 years
    Note that these make the mouse-wheel scrolling work, but they don’t address the primary issue: “I don't like it when you can only scroll in discrete lines as opposed to continuous pixel-by-pixel scrolling.”
  • romainl
    romainl almost 12 years
    This type of scrolling (line by line) is hardcoded in Vim. There's thankfully no way around it. If one really needs it one should insist on it with carefully worded arguments on vim-dev or provide a patch.
  • Eddy
    Eddy almost 12 years
    The reason why I want smooth scrolling is that I tend to lose my place when scrolling through lines discretely. It's hard to explain. Maybe it doesn't effect everyone but it does for me