Programing

구문 강조로 인해 Vim에서 끔찍한 지연이 발생합니다.

lottogame 2020. 12. 28. 07:42
반응형

구문 강조로 인해 Vim에서 끔찍한 지연이 발생합니다.


저는 Vim을 좋아합니다. 그러나 그것은 지금 나에게 힘든 시간을줍니다.

저는 많은 플러그인을 사용하며 지난 6 개월 동안 멋진 플러그인을 많이 발견했습니다. 하지만 내 Vim도 정말 느려졌습니다. 나는 끊임없는 청소를하지만별로 도움이되지 않습니다.

저는 Vim을 완전히 사용할 수없는 시점에 있습니다. 초당 2-5 프레임으로 렌더링되는 것처럼 느껴지고 탭 / 버퍼를 전환하는 데 약 1 초가 걸리고 스크롤 hjkl이 끔찍하고 지연이 너무 심하며 삽입 모드에서 문장을 입력하는 것조차 혼란 스럽습니다 (지연으로 인해).

편집 : 사실, Vim의 새 인스턴스를 열면 정상이지만 15 분 이내에 사용할 수 없게됩니다.

나는 어떤 플러그인이나 구성이 고통을 일으키는 지 알아 내기 위해 4 시간을 보냈다. 나는 성공하지 못했습니다.

그러나이 설정을 제거하면 모든 지연이 사라진다는 것을 알았습니다. syntax on

구문과 함께이 세 줄은 모든 것을 더욱 악화시킵니다.

set t_Co=256
set background=dark
colorscheme candyman

흥미 롭군. 그렇다면 구문 강조 기능이 Vim을 엄청나게 빠른 속도에서 엄청나게 느린 속도로 바꾸고 있습니까?

"깨끗한"모드에서 구문 활성화를 시도했습니다. vim -u NONE

그리고 거기에는 문제가 없습니다.

그래서 문제인 것처럼 보이는 것은 하나 이상의 플러그인과 결합 된 구문 강조입니다. 나는 무리를 비활성화하려고 시도했지만 운이 없었습니다.

프로파일 링을 할 수있는 방법이 있습니까? 수동 테스트에 상당히 지쳤습니다.

비슷한 경험이있는 사람이 있습니까? 내을 살짝 들여다 .vimrc보고 벨이 울리는 지 확인하십시오. https://bitbucket.org/furion/dotfiles

해결책 : 혼란을 일으키는 플러그인은 다음과 같습니다.

Bundle "gorodinskiy/vim-coloresque.git"

나는 대답, 좋은 통찰력을 읽는 것이 좋습니다.

편집 (1 개월 후) : coloresque 플러그인이 일부 개선되었습니다.


autocmd스팸 있습니다. autocmd를 다시 추가하기 전에 그룹을 지우는 모든 autocmd 문을 그룹으로 래핑해야합니다. .vimrc대부분의 autocmd가 주석 처리 된 것처럼 보이 므로 문제를 일으키는 플러그인이있을 수 있습니다. 이 명령의 출력을 확인하십시오.

:au CursorMoved

거기에 중복 처리기가 많이 있으면 그게 문제입니다.

다음은 내 .vimrc 의 autocmd 규율의 예입니다 .

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

autocmd!의 선두에서 augroup블록 (현재 그룹을 클리어 vimrc_autocmdautocmds을 재 - 첨가하기 전에,이 경우).


:syntime on

루비 파일에서 이동 한 다음

:syntime report

저에게 다음과 같이 가장 느린 매칭을보고했고, 매치가 하나도 없다는 것을 알 수 있습니다.

ruby.vim 파일에서 rubyPredefinedConstant를 비활성화하고 문제가 해결되었습니다. Vim 정규식 엔진은 루비 구문 강조 정규식을 좋아하지 않습니다. 충분한 구문 강조와 좋은 성능 사이의 균형을 찾아야합니다.

도움이 되길 바랍니다. 여기 내 Mac OS 10.8.5, homebrew Vim 7.4 (콘솔 vim)에서보고 된 ruby ​​용 정규식을 강조하는 가장 느린 구문 3 가지가 있습니다.

    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*(\)\@!

또는 vim-rubyDojosto가 지적한대로 시도 할 수 있습니다.


에서 다른 스택 오버플로 질문 : 나는의 .vimrc 파일에 다음 줄을 추가하여 빠른 정력 얻을
set re=1
이 정규식 엔진의 이전 버전을 사용하는 것이 정력 강제 그리고 루비를 위해 실제로 빠릅니다.


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).


I found that "set foldmethod=syntax" makes 7.4 almost unusable slow e.g. for js&ruby files (ubuntu 13.10) whereas "set foldmethod=indent" works fine.


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.


I'm pretty sure that

set t_Co=256
set background=dark
colorscheme candyman

have nothing to do with that lag. The two first lines are useless (the number of usable colors is defined according to your $TERM and your colorscheme already does set background=dark) but not really harmful.

Common "Vim is slowing to a crawl" causes include poorly written autocmds, too many autocmds, reloading one's ~/.vimrc too often, poorly written plugins…

Please post your setup so that we can help you find out why you experience that lag.


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.


I have had this problem for a long time, and it was driving me crazy. I tried installing vim-ruby. Not sure if that helped but at least now I have the most up-to-date version of ruby syntax highlighting (with any performance improvements since the last version of Vim was released).

But then I looked further, and discovered that vim-ruby has a mode that skips all the expensive highlighting. Try adding this line to your vimrc and see if it helps (it did for me, finally!):

let ruby_no_expensive=1


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

ReferenceURL : https://stackoverflow.com/questions/19030290/syntax-highlighting-causes-terrible-lag-in-vim

반응형