45
votes

I've been using vim over ssh to work for a week or two now and all has been going great. Today I decided to add in some syntax highlighting, autocomplete, and some other general plugins. Set up vundle and went to work.

My current .vimrc can be found at https://github.com/scottopell/dotfiles/blob/master/.vimrc

I have cloned my vimrc and vim files onto my local ubuntu desktop and vim runs exactly as expected, no slowness on any files that I can find. Same plugins and same vimrc and no slowness on ruby files.

update

I can reproduce this issue with the following .vimrc

syntax on

and an empty ~/.vim folder.

However, vim on this vps is very slow with ruby/haml files. Much moreso ruby files. When I open any ruby file, startup takes about 2 seconds (timed with --startuptime). With a comparable length haml file, its about .5 seconds. This slowness isn't just on startup either, moving around and editing the file are both painfully slow.

Haml/erb(they are basically the same)

268.818  000.005: before starting main loop
848.871  580.053: first screen update

Ruby

199.613  000.004: before starting main loop
2937.859  2738.246: first screen update

Without syntax highlighting on the same ruby file as above

149.047  000.004: before starting main loop
152.912  003.865: first screen update 

I have tried using mosh(http://mosh.mit.edu) and it doesn't help. not really relevant anymore

As you can see in my .vimrc file, I have tried a few different solutions to this problem. I have tried running with all plugins disabled (I moved them all from ~/vim/bundle/PLUGINNAME to ~/vim/bundle/disabled/PLUGINNAME, is this correct?), set ruby path, set foldlevel to manual, disabled my colorscheme, nothing helps. see edit3

I can post the full startupttime log for any file if that will help.
I have tested a few other languages(php, c, python, vimL) and none experience any slowdown.


EDIT: Just to clarify, I am running an ssh session with ssh user@server then once inside the server I am doing vim file.rb.

EDIT2: I just tried accessing the server directly and the slowness persists without ssh, I have updated to reflect that this isn't a problem with ssh.

EDIT3: I can reproduce the issue with a .vimrc file that contains the single line syntax on with an empty ~/.vim folder

EDIT4 I uninstalled my compiled version of vim and any versions that I may have installed through apt, manually removed all vim stuff from my system, and I can run vim with vim -u NONE /path/to/file.rb then do :syn on and the issue will be there. The file in question is a rails controller, but like I've said, I can recreate it to some degree with most any file, but rails controllers see to be the worst.

7
How exactly are you running Vim over SSH? Editing files locally or remotely? - timss
You could play with :set ttyfast and I believe there are a few other settings that control intention UI delays - demure
what if you are in the actual machine? The loadtime of vim should not be influenced by ssh, because it computes all on the machine and send all the information through the network only once. - fotanus
@timss I have clarified in the post, I'm editing remotely. - ScottO
@demure I just tried ttyfast with no change. - ScottO

7 Answers

103
votes

The solution to this problem turned out to be the regex engine that vim uses. The speculation on #vim on freenode is that the ruby syntax files use something that is slower on the new regex engine.

Any version older than and including Vim 7.3.969 has the old regex engine. Add in set re=1 to your vimrc to force the old regex engine on any version newer (and don't forget to reload the file you're currently editing with :e).

Thanks to Houl, Dolio and dmedvinsky from #vim for help figuring it out.

I haven't had a chance to try the absolute latest version, there was a commit last night that may help with this issue. I will update this if I get the chance to try the bleeding edge version again.

16
votes

You should set this tw options in your vimrc:

set ttyfast
set lazyredraw

If this is not solving your problem try to start vim without your vimrc to be sure that none of your current settings are screwing it up.

vim -u NONE
13
votes

Two things that will drastically help speed up Ruby syntax highlighting are disabling cursor line and relative number for Ruby (if you use those).

I have the following in my .vimrc:

" Ruby is an oddball in the family, use special spacing/rules
if v:version >= 703
  " Note: Relative number is quite slow with Ruby, so is cursorline
  autocmd FileType ruby setlocal ts=2 sts=2 sw=2 norelativenumber nocursorline
else
  autocmd FileType ruby setlocal ts=2 sts=2 sw=2
endif
8
votes

I'm using vim 7.4.52 and none of these solutions worked for me.

According to this github comment on the issue (https://github.com/vim/vim/issues/282#issuecomment-169837021), foldmethod=syntax is responsible for the slowness.

Adding this to my .vimrc finally fixed it!

augroup ft_rb
    au!
    " fix the SLOOOW syntax highlighting
    au FileType ruby setlocal re=1 foldmethod=manual
augroup END
7
votes

Try setting your ruby path explicitly in your vimrc:

let g:ruby_path="/usr/bin/ruby"
1
votes

see UPDATE at the bottom.

this may be helpful as a workaround -

i am using vim version

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 2 2014 19:40:46)

Included patches: 1-52

it is the stock version from Linux Mint 17.1 Rebecca.

the php.vim syntax file is not version'd that i can see, but it sez last edit'd 28 aug 13.

it isn't a ruby project, but when editing a large php class file (

    $ php -w test.inc | wc
    2    2410   19220

) i note significant delays near the top of the class, but not above or below the class, and, notably, not toward the bottom of the class. as i attempt to insert new text near the bottom of the class, delay is minimal and seems to be proportional to the line number inside the class. "minimal" means almost instantly, "significant" means 1 to 1.5 seconds per character.

the file is approx 1800 lines with approx 500 lines of legit php and 1300 lines of comments and doc. the class begins at approx line 30 and ends at approx line 1700. it is conceded it's a bit large, but well documented :-\

if i insert

    class dummy { }

in front of the original "class originalName {", there is no delay anywhere in the file. this unsightly kluge permits vim/gvim to regain its responsiveness and could be considered a workaround. note no linefeed between the two, just

    class dummy { } class originalName {

it can even be comment'd out:

    /*class dummy {}*/class originalName {

additional info:

  1. during this test, the plugins directory was moved.

  2. with "set syntax=off", the problem completely disappears. this is NOT a fix.

  3. setting the regular expression engine with

    set regexpengine=1   (or any other number)
    

    does not appreciably change the results.

based on these results, i would suspect the regular expression engine as well. my point is that diddling a bit with the syntax in ruby files may lead to a workaround.

UPDATE: i have found that the issue is "caused" by setting php_folding to 1 (enabled). the vimrc i THOUGHT i was using was not, but at least some of the mystery is solved due to that mistake. a simple vimrc like this will induce the problem (for me, as least):

    :syntax enable
    :let php_folding = 1

this means my issue is totally unrelated to the ruby issue, but there may be a similar thing going on with the ruby.vim file. maybe not.

apologies for the deflection.

0
votes

I tried most of these solutions but what ended up working for me the best was removing any plugins associated with airline.