Re: how to automagically run a "syn off" the moment I start "editing" a file.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: how to automagically run a "syn off" the moment I start "editing" a file.

Bee-9


On Mar 10, 2009, at 8:44 PM, Charles Campbell:
> 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.

Recently I tried using  exists("syntax_on")  but it always failed.

Then I tried  exists("g:syntax_on")  and that worked.

Could that be the problem?
--
Bill Muench
Santa Cruz, California
vim 7.2.124
MacOS 10.4.11


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to automagically run a "syn off" the moment I start "editing" a file.

Tony Mechelynck

On 11/03/09 06:36, Bee wrote:

>
>
> On Mar 10, 2009, at 8:44 PM, Charles Campbell:
>> 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.
>
> Recently I tried using  exists("syntax_on")  but it always failed.
>
> Then I tried  exists("g:syntax_on")  and that worked.
>
> Could that be the problem?

Hm. At the command-line, or, I expect (but haven't checked), in an
autocommand, I get the same result (1 in my case) for both parts of

        :echo exists('syntax_on') exists('g:syntax_on')

However, _in a function_ the default namespace is the _local_ space, and
there, exists('syntax_on') would always return zero because, _in that
function_, l:syntax_on has never been defined.


Best regards,
Tony.
--
This message contains 78% recycled characters.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---