I've been using Vim and MacVim as may main development tool for last two weeks and have noticed that the cursor scroll speed is much fast and fluent in MacVim than it is in Vim in the Terminal. It's a difference like night and day. Both applications use the same .vimrc
file. Dose anyone have an idea what could cause the performance difference?
Mac – Why is MacVim much faster than Vim in the Terminal
macvimterminalvim
Related Solutions
I've tried a good dozen times to compile Vim on my Mac but I've never managed to obtain a usable Vim: each time it worked but it was unbearably slow and laggy.
After loosing too much time trying to make it work I simply dropped the towel and created an alias to MacVim's bundled CLI executable.
alias vim='/path/to/MacVim.app/Content/MacOS/Vim'
Not only is it fast and responsive but it has the exact same features you could find in MacVim, as long as it makes sense in a terminal. Since then, using MacVim and/or Vim makes no difference for me and whether I use one or the other is dictated only by the context. Not by one being better than the other.
Why is my vim configuration slow? How can I improve the speed of my vim configuration within Terminal or iTerm2?
By using MacVim's pre-compiled binary.
Also try Linux one day. MacVim is fast only if you have never used GVim or Vim on a linux box.
Summary
The issue clearly starts with PuTTY, but it doesn't necessarily stop there. There is a link to a potential fix for the PuTTY issue below, as well as an analysis of the issue as a whole.
Issue Description
Configuration
vim
with mouse=a
enabled for scrolling, selection, and cursor movement
tmux
, with no tmux
mouse functionality enabled, i.e. the following:
set -g mode-mouse off
set -g mouse-select-pane off
set -g mouse-resize-pane off
set -g mouse-select-window off
Use Case
A typical use case is to use vim
inside of tmux
. Avoiding negative interactions between tmux
and vim
is one of the primary reasons to disable tmux
scrolling.
Behavior
Please note that the following only occurs when using PuTTY as the terminal emulator, and is not reproducible in gnome-terminal or any other tested Linux terminal emulator.
When attempting to 'scroll up' using the mouse in vim
inside of a tmux
session, the action simply fails. As OP describes, it is often possible to see the buffer jerking 'up and down' as if there is a counter-action taking place with each scroll attempt (more on this below).
This is basically the same as OP's description, but recapped just in case something isn't clear in my explanation or OP's question.
Potential Solution -- PuTTY
There appears to be an issue where PuTTY sends an extraneous ScrollDown event with every ScrollDown/ScrollUp event. This means that each attempt to scroll up gets cancelled out and nothing happens. Conversely, when scrolling down, each scroll event is doubled. The behavior is easy to validate by looking at the vim
scrolling behavior first outside of tmux
(where scrolling works properly), and second inside of tmux
(where scrolling up does not work, and a single attempt to scroll down scrolls twice as much).
According to the following gmane thread, the issue described above is resolved with a patch from Putty-X (https://github.com/atsepkov/putty-X/commit/bbcedf5a85ca1ccaa27005e7f7ebeb4c8a783b88):
Link to gmane thread: http://comments.gmane.org/gmane.comp.terminal-emulators.tmux.user/5498.
NOTE: I haven't validated the above solution myself, so please review the gmane thread for additional information.
Additional Observations
Where it really gets interesting is that this is a new issue not reproducible using older versions of tmux
/vim
. Using the same version of PuTTY (0.63), the issue can be actively demonstrated on an Ubuntu 13.10 system, while an Ubuntu 12.04 system does not exhibit the issue.
At first, the issue seems to point to a system configuration delta (i.e. missing ncurses-term or similar), but no fix has been identified using this type of solution. Furthermore, the multiple reports of this same issue (including this thread) tend to support the existence of the issue.
Because of the co-dependent nature of the issue and versions of the related software, it seems the issue isn't limited to a single application. It may be that a newer version of tmux
/vim
'fixed' something that created a regression. Or, it may be that a newer version of tmux
/vim
simply exposed the existing issue in PuTTY. Either way, it will require some additional investigation to fully iron out. Please find some pertinent version information below if this can help anyone in their investigation.
Version Information
Ubuntu 12.04 version info ('scrolling up' in vim
inside of tmux
works):
tmux
: 1.6-1vim
: 7.3.429-2
Ubuntu 13.10 version info ('scrolling up' in vim
inside of tmux
is broken):
tmux
: 1.8-4vim
: 7.4.000-1
Also of note -- the gmane poster reported not observing the issue on tmux
1.7 + vim
7.3. Poster's first observation of the issue was also with tmux
1.8 + vim
7.4.
Hopefully, at the very least, this answer provides anyone dedicated to (or stuck with) PuTTY an option for working around this issue. Beyond that, hopefully someone can make sense of the additional observations above and help bring the topic to a proper resolution.
Best Answer
Vim is run in your shell which is run in your terminal: it inherits many layers of latency, mostly related to redrawing the window and input handling.
MacVim is not run in a terminal and its rendering engine is much snappier. It's not that great, though, when you are used to GVim on Linux.