Vim configuration slow in Terminal & iTerm2 but not in MacVim

12

9

Ideally, I want to use Vim from Terminal or iTerm2. However, it becomes unbearably slow so I had to resort to using MacVim. There is nothing wrong with MacVim, however my workflow would be much smoother if I used only Terminal/iTerm2.

When its slow

  • Loading files, in particular Rails files takes about 1 - 1.5s. Removing rails.vim decreases this time to 0.5 - 1s. In MacVim this is instantaneous.

  • Scrolling through the rows and columns via h, j, k, l. It progressively gets slower the longer I hold down the keys. Eventually, it starts jumping rows. I have my Key Repeat set to Fast and Delay Until Repeat set to Short.

  • After 10 - 15 minutes of usage, using plugins such as ctrlp or Command-T gets very laggy. I'd type a letter, wait 2 - 3s, then type the next.

My Setup

11" MacBook Air running Mac OS X Version 10.7.3 (1.6 Ghz Intel Core 2 Duo, 4 GB DDR3)

My dotfiles.

> vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Nov 16 2011 16:44:23)
MacOS X (unix) version
Included patches: 1-333
Huge version without GUI.  Features included (+) or not (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent 
-clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
+conceal +cryptv -cscope +cursorbind +cursorshape +dialog_con +diff +digraphs 
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path 
+find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv 
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent 
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape 
+mouse_dec -mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse 
+mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg +path_extra -perl
 +persistent_undo +postscript +printer +profile +python -python3 +quickfix 
+reltime +rightleft +ruby +scrollbind +signs +smartindent -sniff +startuptime 
+statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white 
-tcl +terminfo +termresponse +textobjects +title -toolbar +user_commands 
+vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore 
+wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard 
-xterm_save 
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/Cellar/vim/7.3.333/share/vim"
Compilation: /usr/bin/llvm-gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX -no-cpp-precomp  -O3 -march=core2 -msse4.1 -w -pipe -D_FORTIFY_SOURCE=1      
Linking: /usr/bin/llvm-gcc   -L.     -L/usr/local/lib -o vim       -lm  -lncurses -liconv -framework Cocoa     -framework Python   -lruby

I've tried running without any plugins or syntax highlighting. It opens files a lot faster but still not as fast as MacVim. But the other two problems still exist.

  1. Why is my vim configuration slow?
  2. How can I improve the speed of my vim configuration within Terminal or iTerm2?

Jey Balachandran

Posted 2012-03-19T15:59:14.383

Reputation: 255

Answers

8

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.

romainl

Posted 2012-03-19T15:59:14.383

Reputation: 19 227

I tried using MacVim's version. So much faster! Still not as fast as using MacVim itself but this is tolerable. Curious, what makes Vim on a linux box that much faster than Vim in OS X terminal? – Jey Balachandran – 2012-03-20T05:10:20.683

1I don't know. At home I run Ubuntu on a small and old Dell Inspiron and everything related to text is much much snappier than on the quad core Mac Pro I use at work. Specially MacVim/Gvim that I use all day long. Maybe less abstraction levels and stacked fraeworks. I don't know. – romainl – 2012-03-20T07:04:06.423

I'd like to see more posts on this. It should be possible to make iTerm2 run almost as fast as MacVim. – xer0x – 2012-08-21T22:45:22.027

12

I've found that any plugins or settings that affect the display (cursorline, cursorcolumn, vim-powerline, vim-airline, matchit.vim, etc.) slow down Vim in the terminal most significantly.

Here are some lines from my .vimrc to keep things speedy:

let loaded_matchparen=1 " Don't load matchit.vim (paren/bracket matching)
set noshowmatch         " Don't match parentheses/brackets
set nocursorline        " Don't paint cursor line
set nocursorcolumn      " Don't paint cursor column
set lazyredraw          " Wait to redraw
set scrolljump=8        " Scroll 8 lines at a time at bottom/top
let html_no_rendering=1 " Don't render italic, bold, links in HTML

Also see :help slow-terminal

That said, why Vim in the terminal is slower is beyond me.

Jay

Posted 2012-03-19T15:59:14.383

Reputation: 221

6

In Mac Terminal Vim, if you have opacity set on the window, it greatly decreases scroll speed. Turn opacity=100 and blur=0, and it's as fast as MacVim -- I timed it.

user177393

Posted 2012-03-19T15:59:14.383

Reputation: 61

nice catch, i've being looking for the cause of the slowness for month and I tried every settings, except this one (it was transparent without picture, so it looks like opaque, but it wasn't) – Ismael – 2017-07-10T14:55:58.993

To clarify, this is referring to the terminal application's opacity and blur settings, not the settings of Vim itself. Works like a charm though, thanks for the tip! – user72923 – 2013-12-06T16:20:00.400

3

I've had pretty good results installing MacVim via homebrew and then using alias vim="mvim -v".

user770148

Posted 2012-03-19T15:59:14.383

Reputation: 31

2

set cursorline was the culprit for me.

I hadn't noticed a problem with it until one specific file started rendering at .25 fps, but disabling cursorline sped things back up.

csq

Posted 2012-03-19T15:59:14.383

Reputation: 21

1

I've also encountered a slow terminal MacVim in iTerm2. I've tried everything I could get my hands on, but nothing seemed to help. Eventually, I narrowed it down to a setting in my .vimrc:

set cursorcolumn

So, I removed it, and my terminal MacVim was significantly faster when navigating files. Maybe someone else, who's tried everything else, and has this setting turned on, will find this useful.

russianbandit

Posted 2012-03-19T15:59:14.383

Reputation: 111