On Mar 10, 2:09 pm, Charles Campbell <[email protected]>
wrote:
> Try the following:
>
> au InsertEnter * if exists("syntax_on")| syn off | endif
> au InsertLeave * syn on
> au CursorMoved * if &modified && exists("syntax_on") | syn off | endif
> au BufWritePost * if !exists("syntax_on") | syn on | endif
>
> As you can see, I added one event -- if you've written the buffer,
> presumably its safe to syntax highlight.
Chris, in hindsight the extra logic (although tempting) is a failure.
The reason is that the logic of lines 2 and 3 is mutually incompatible
in a subtle sense (assuming I understand vim correctly!). Just noticed
that while analyzing another side effect:
Symptoms:
I go into insert mode -> Highlighting disappears [good!]
I come out of insert mode with an Esc. ->highlighting re-appears.
[great]
I press any cursor key -> Highlighting disappears [crap; this is not
what we wanted!]
As I understand it, even if Line 2 ( au InsertLeave * syn on) succeeds
in turning HL on as soon as I leave insert mode the next line 3 (au
CursorMoved * if &modified && exists("syntax_on") | syn off | endif )
reacts to the cursor movement immediately after. And it "sees" the
buffer changes made during the Insert mode via the "modified" tag and
hence immediately turns HL off.
Hard to spot! Of course, the design depends on the fact the Inser mode
changes returned the file to a consistent state suitlble for syn-HL
again.
As far as I can see my best bet might be to comment out the "extra
logic" "au InsertLeave * syn on" totally. Thus vim takes care of
turning HL off but turning it on would be upto the user manually (or
post a write). Not so satisfactory. I had really liked the "au
InsertLeave * syn on" bit!
If you see any ways around do let me know!
--
Rahul
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---