Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - changing to normal mode is slow on large PHP files with syntax highlighting enabled

When I'm using Vim 7.3 to edit a large PHP file (2000 lines), if I switch from insert mode to normal mode there is a delay of about 1-2 seconds.

It is quite frustrating when I need to make some quick edits.

On smaller files (300 lines) there is no delay. The reverse (normal mode to insert mode) there is also no delay.

The issue is related to syntax highlighting, because if I turn syntax highlighting off, the problem goes away.

:syntax off

Some things I have tried to no avail:

  • turning folding off
  • turning matchparen plugin off
  • turning all custom plugins off
  • using "largefile" plugin

Note, other than this insert-to-normal mode switching issue, nothing else about the syntax highlighting appears slow for me when editing large files. I.e. typing text in insert mode performs fine, completion works fine, etc.

This makes me think that it is something that can be fixed.

I have tested this in gVim and console vim (under cygwin) on Windows XP.

Does anyone know what could be the issue?

Or is anyone else able to reproduce this problem? I have googled, but can't see anyone else with this same issue which is weird.

UPDATE: I think it may be related only to PHP syntax highlighting. I just tried coffeescript and javascript files with 2000+ lines and did not have any issues with them.

like image 606
asgeo1 Avatar asked Mar 20 '12 01:03

asgeo1


2 Answers

I haven't seen the issue you're describing, but the InsertLeave event would be one place to start looking. Check your color scheme (and any other plugins) to see if there's an InsertLeave autocommand. On my own system the 'lettuce.vim' colorscheme file has a handful of those; it's conceivable they're expensive, or possibly even triggering some kind of recursive processing (just thinking out loud).

Edit You can check to see what autocommands are associated with a given event by doing :au {EventName}, e.g. :au InsertLeave.

like image 112
David Pope Avatar answered Sep 23 '22 20:09

David Pope


Try this setting in your .vimrc file.

set ttimeoutlen=0

like image 2
kknoer Avatar answered Sep 24 '22 20:09

kknoer