Home Explore Blog CI



neovim

1st chunk of `runtime/doc/syntax.txt`
88054f30e6dfdef6b34d704d46073ab0f62e6668c51afe4b0000000100000fa5
*syntax.txt*	Nvim


		  VIM REFERENCE MANUAL	  by Bram Moolenaar


Syntax highlighting		*syntax* *syntax-highlighting* *coloring*

Syntax highlighting enables Vim to show parts of the text in another font or
color.	Those parts can be specific keywords or text matching a pattern.  Vim
doesn't parse the whole file (to keep it fast), so the highlighting has its
limitations.  Lexical highlighting might be a better name, but since everybody
calls it syntax highlighting we'll stick with that.

Vim supports syntax highlighting on all terminals.  But since most ordinary
terminals have very limited highlighting possibilities, it works best in the
GUI version, gvim.

In the User Manual:
|usr_06.txt| introduces syntax highlighting.
|usr_44.txt| introduces writing a syntax file.

                                      Type |gO| to see the table of contents.

==============================================================================
1. Quick start						*:syn-qstart*

				*:syn-enable* *:syntax-enable* *:syn-on* *:syntax-on*
Syntax highlighting is enabled by default. If you need to enable it again
after it was disabled (see below), use: >

	:syntax enable

Alternatively: >

	:syntax on

What this command actually does is to execute the command >
	:source $VIMRUNTIME/syntax/syntax.vim

If the VIM environment variable is not set, Vim will try to find
the path in another way (see |$VIMRUNTIME|).  Usually this works just
fine.  If it doesn't, try setting the VIM environment variable to the
directory where the Vim stuff is located.  For example, if your syntax files
are in the "/usr/vim/vim82/syntax" directory, set $VIMRUNTIME to
"/usr/vim/vim82".  You must do this in the shell, before starting Vim.
This command also sources the |menu.vim| script when the GUI is running or
will start soon.

					*:hi-normal* *:highlight-normal*
If you are running in the GUI, you can get white text on a black background
with: >
	:highlight Normal guibg=Black guifg=White
For a color terminal see |:hi-normal-cterm|.

NOTE: The syntax files on MS-Windows have lines that end in <CR><NL>.
The files for Unix end in <NL>.  This means you should use the right type of
file for your system.  Although on MS-Windows the right format is
automatically selected if the 'fileformats' option is not empty.

NOTE: When using reverse video ("gvim -fg white -bg black"), the default value
of 'background' will not be set until the GUI window is opened, which is after
reading the |gvimrc|.  This will cause the wrong default highlighting to be
used.  To set the default value of 'background' before switching on
highlighting, include the ":gui" command in the |gvimrc|: >

   :gui		" open window and set default for 'background'
   :syntax on	" start highlighting, use 'background' to set colors

NOTE: Using ":gui" in the |gvimrc| means that "gvim -f" won't start in the
foreground!  Use ":gui -f" then.

							*g:syntax_on*
You can toggle the syntax on/off with this command: >
   :if exists("g:syntax_on") | syntax off | else | syntax enable | endif

To put this into a mapping, you can use: >
   :map <F7> :if exists("g:syntax_on") <Bar>
	\   syntax off <Bar>
	\ else <Bar>
	\   syntax enable <Bar>
	\ endif <CR>
[using the |<>| notation, type this literally]

Details:
The ":syntax" commands are implemented by sourcing a file.  To see exactly how
this works, look in the file:
    command		file ~
    :syntax enable	$VIMRUNTIME/syntax/syntax.vim
    :syntax on		$VIMRUNTIME/syntax/syntax.vim
    :syntax manual	$VIMRUNTIME/syntax/manual.vim
    :syntax off		$VIMRUNTIME/syntax/nosyntax.vim
Also see |syntax-loading|.

NOTE: If displaying long lines is slow and switching off syntax highlighting
makes it fast, consider setting the 'synmaxcol' option to a lower value.

==============================================================================
2. Syntax files						*:syn-files*

The syntax and highlighting commands for one language are normally stored in
a syntax file.	The name convention is: "{name}.vim".

Title: Syntax Highlighting in Vim: Quick Start and Syntax Files
Summary
This section of the Vim reference manual introduces syntax highlighting, its basic commands like `:syntax enable` and `:syntax on`, and how to toggle it on/off. It also explains how Vim locates syntax files and provides a workaround for slow display of long lines by adjusting the 'synmaxcol' option. Additionally, it briefly introduces the concept of syntax files and their naming convention.