Putting syntax sync fromstart in ~/.vimrc

917 views
Skip to first unread message

Guy Rutenberg

unread,
Jun 6, 2008, 4:49:44 AM6/6/08
to vim_use
Hi,

I've tried putting

:syntax sync from start

In my ~/.vimrc file but it seems it doesn't have any effect and I have
to issue the command manually for every file I open. Does anyone have
an idea how can I make the syntax highlighting evaluate the whole file
automatically?


Regards,
Guy

badmagic

unread,
Jun 6, 2008, 5:03:42 AM6/6/08
to vim...@googlegroups.com
> Hi,

I'm using Vim version 7.1.145 and all I've got in my ~/.vimrc file is:

syntax on

and all of my files are completely syntax highlighted (if that's correct
English) - *.c, *.html, *.conf, *.vimrc etc. All of them.

Don't know if this helps?

Cheers,
Steve (BM)


Liang Chen

unread,
Jun 6, 2008, 5:06:05 AM6/6/08
to vim...@googlegroups.com
Does your VIM support HIGHLIGHT SYNTAX ,make sure of that by typing
version ,and find out .
If it does, just put 'syntax on' in your .vim script,if not ,get a
version supporting
syntax.

Guy Rutenberg

unread,
Jun 6, 2008, 7:35:22 AM6/6/08
to vim_use
Hi,

Thanks for the quick reply.

My vim has syntax highlighting turned on and the syntax highlighting
works. The problem is that vim by default doesn't inspect the whole
file when it highlights the code, but only a given number of lines
before the current top line. While this works great for certain
filetypes (like C) it can result in incorrect highlighting when
editing a very long file that incorporates multiple highlighting
schemes, like HTML.

The best solution I've fount for it is you do
:syntax sync fromstart
which tells vim to always inspect the file from the start. The problem
is that vim ignores this command in the vimrc so I have to do it
manually when I open each file.

I hope I made my problem a bit clearer.

Thanks,

Guy

Tony Mechelynck

unread,
Jun 6, 2008, 8:02:55 AM6/6/08
to vim...@googlegroups.com
On 06/06/08 13:35, Guy Rutenberg wrote:
> Hi,
>
> Thanks for the quick reply.
>
> My vim has syntax highlighting turned on and the syntax highlighting
> works. The problem is that vim by default doesn't inspect the whole
> file when it highlights the code, but only a given number of lines
> before the current top line. While this works great for certain
> filetypes (like C) it can result in incorrect highlighting when
> editing a very long file that incorporates multiple highlighting
> schemes, like HTML.
>
> The best solution I've fount for it is you do
> :syntax sync fromstart
> which tells vim to always inspect the file from the start. The problem
> is that vim ignores this command in the vimrc so I have to do it
> manually when I open each file.
>
> I hope I made my problem a bit clearer.
>
> Thanks,
>
> Guy

I think each syntax scripts sets syn sync for the files it highlights.

You might want top place your syn sync command in some after-script, e.g.
(Unix) $HOME/.vim/after/syntax/html.vim
(Windows) $HOME/vimfiles/after/syntax/html.vim

Create the directories if they don't exist yet.

Best regards,
Tony.
--
"I am not an Economist. I am an honest man!"
-- Paul McCracken

Ben Schmidt

unread,
Jun 6, 2008, 8:11:22 AM6/6/08
to vim...@googlegroups.com

When each file loads, it loads the syntax for that file, which usually
contains sync commands which override the earlier one in your vimrc.

One solution is to use after files for each filetype to override this by
creating files for the different filetypes you edit where you want this
different behaviour, e.g. for c, you create ~/.vim/after/syntax/c.vim
and put your command in that (create necessary parent directories).

Another is using an autocommand to run the command automatically after
the syntax changes

:au Syntax * syntax sync fromstart

This command must be in your vimrc after the syntax highlighting is
turned on, or it will happen before the syntax change still!

By replacing the * with some other pattern you can make it apply to only
specific syntaxes if you desire, too.

Also note that 'fromstart' should be one word, I believe.

Ben.


badmagic

unread,
Jun 6, 2008, 9:59:09 AM6/6/08
to vim...@googlegroups.com
Thanks, Liang

Petr Mach

unread,
May 14, 2018, 2:54:10 PM5/14/18
to vim_use
> Another is using an autocommand to run the command automatically after
> the syntax changes
>
> :au Syntax * syntax sync fromstart
>
> This command must be in your vimrc after the syntax highlighting is
> turned on, or it will happen before the syntax change still!

I'm trying it, but this is do not work for me. Syntax is showed incorrectly still. Syntax is repaired after manual comand :synatx sync fromstart.

Christian Brabandt

unread,
May 14, 2018, 2:57:19 PM5/14/18
to vim_use
You are probably experiencing it because the syntax file uses some
complex regular expressions and then it times out. You might want to
increase the 'redrawtime' setting.

In any case, you should always mention the filetype/syntax in use and
possibly post the :syntime report when you are experiencing this issue.

Best,
Christian
--
Ausführungsbestimmungen sind Erklärungen zu den Erklärungen, mit denen
man eine Erklärung erklärt.
-- Abraham Lincoln
Reply all
Reply to author
Forward
0 new messages