Syntax highlighting causes terrible lag in Vim

前端 未结 10 1515
孤独总比滥情好
孤独总比滥情好 2020-12-12 11:20

I love Vim. But its giving me hard times right now.

I use a lot of plugins and during the last 6 months, I\'ve found a lot of awesome ones. But my Vim got really slu

相关标签:
10条回答
  • 2020-12-12 11:51

    I've noticed that vim can slow down to a halt if you're using anything that dynamically changes the background color. Try turning off :set cursorline or :set cursorcolumn (if you have them set).

    0 讨论(0)
  • 2020-12-12 11:51

    I'd like to thank everyone helping me out on this issue. Good news is, my Vim is snappy again.

    I've started with fresh Vim re-install. I've than added plugin by plugin, until I found the root of all evil.

    Bundle "gorodinskiy/vim-coloresque.git"
    

    Its a plugin that was causing me all this pain. Since I had it for a while, it wasn't a suspect, thats why I discovered it so late. What this plugin does, is whenever it finds a word for color (eg red, green), or hex value (eg. #FFFFFF), it sets background color of the text to match the color that its describing. Brilliant idea, but seems like poor implementation.

    Removing this plugin removed the lags.

    But I didn't stop here. I've done a major cleanup of my .vimrc as well. Removed some more plugins I hadn't used. Grouped my autocmds and removed unnecessary ones.

    My Vim is very snappy now. I'm happy again.

    0 讨论(0)
  • 2020-12-12 11:54

    For me that was set relativenumber feature which was slowing it down. Try to disable it with set norelativenumber and test.

    0 讨论(0)
  • 2020-12-12 11:57

    You have autocmd spam. You should wrap all of your autocmd statements in groups which clear the group before re-adding the autocmds. It looks like your .vimrc has most autocmds commented-out, so maybe there is a plugin that is causing the issue. Check the output of this command:

    :au CursorMoved
    

    If there's a bunch of duplicate handlers there, that's your problem.

    Here's an example of autocmd discipline from my .vimrc:

    augroup vimrc_autocmd
      autocmd!
      "toggle quickfix window
      autocmd BufReadPost quickfix map <buffer> <leader>qq :cclose<cr>|map <buffer> <c-p> <up>|map <buffer> <c-n> <down>
    
      autocmd FileType unite call s:unite_settings()
      " obliterate unite buffers (marks especially).
      autocmd BufLeave \[unite\]* if "nofile" ==# &buftype | setlocal bufhidden=wipe | endif
    
      " Jump to the last position when reopening a file
      autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
    
      " ...etc...
    
    augroup END
    

    The autocmd! at the beginning of the augroup block clears out the current group (vimrc_autocmd, in this case) before re-adding the autocmds.

    0 讨论(0)
  • 2020-12-12 12:00

    EDIT: Blogged about how this all works, with screenshots and awesome-sauce.

    https://eduncan911.com/software/fix-slow-scrolling-in-vim-and-neovim.html

    Original answer below...


    :syntime on
    

    move around in your ruby file and then

    :syntime report
    

    It reported the following slowest matching for me, and you can see that there are not even 1 match.

    I disabled rubyPredefinedConstant in ruby.vim file and problem solved. Vim regex engine does not like something in ruby syntax highlight regex. You will have to find the balance between enough syntax highligting and a good performance.

    hope that helps, here is the top 3 slowest syntax highlighting regex for ruby reported on my Mac OS 10.8.5, homebrew Vim 7.4 (console vim)

        TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
      3.498505   12494  0       0.008359    0.000280  rubyPredefinedConstant \%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\|TRUE\)\>\%(\s*(\)\@!
      2.948513   12494  0       0.006798    0.000236  rubyPredefinedConstant \%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(MatchingData\|ARGF\|ARGV\|ENV\)\>\%(\s*(\)\@!
      2.438253   12494  0       0.005346    0.000195  rubyPredefinedConstant \%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(DATA\|FALSE\|NIL\)\>\%(\s*(\)\@!
    

    Or you can try vim-ruby as pointed out by Dojosto

    0 讨论(0)
  • 2020-12-12 12:02

    Syntax highlighting can be slow, but that should be limited to some (somewhat pathological) files, and particular syntax(es). The latest Vim 7.4 has a new command :syntime to troubleshoot syntax highlighting slowness.

    Apart from that, often, a binary search where you disable half of your plugins, then only one half of that (when the problem is still there), or the other half (when the problem vanished) lets you get to the problematic script quickly.

    0 讨论(0)
提交回复
热议问题