forked from vim-scripts/SyntaxRange
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
67 lines (55 loc) · 3.02 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
This is a mirror of http://www.vim.org/scripts/script.php?script_id=4168
DESCRIPTION
This plugin provides commands and functions to set up regions in the current
buffer that either use a syntax different from the buffer's 'filetype', or
completely ignore the syntax.
SEE ALSO
- If you also want different buffer options (like indent settings, etc.) for
each syntax region, the OnSyntaxChange.vim plugin (vimscript #4085) allows
you to dynamically change the buffer options as you move through the buffer.
RELATED WORKS
- If the highlighting doesn't work properly, you could alternatively edit the
range(s) in a separate scratch buffer. Plugins like NrrwRgn (vimscript #3075)
provide commands to set these up, with automatic syncing back to the
original buffer.
SOURCE
The code to include a different syntax in a region is based on
http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file
USAGE
For quick, ad-hoc manipulation of the syntax withing a range of lines, the
following commands are provided:
:[range]SyntaxIgnore Ignore the buffer's filetype syntax for the current
line / lines in [range]. (Top-level keywords will
still be highlighted.)
This can be a useful fix when some text fragments
confuse the syntax highlighting. (For example, when
buffer syntax set to an inlined here-document is
negatively affected by the foreign code surrounding
the here-document.)
:[range]SyntaxInclude {filetype}
Use the {filetype} syntax for the current line / lines
in [range].
Line numbers in [range] are fixed; i.e. they do not
adapt to inserted / deleted lines. But when in a
range, the last line ($) is interpreted as "end of
file".
For finer control and use in custom mappings or syntax tweaks, the following
functions can be used. You'll find the details directly in the
.vim/autoload/SyntaxRange.vim implementation file.
SyntaxRange#Include( startPattern, endPattern, filetype, ... )
Use the {filetype} syntax for the region defined by
{startPattern} and {endPattern}.
SyntaxRange#IncludeEx( regionDefinition, filetype )
Use the {filetype} syntax for the region defined by
{regionDefinition}.
EXAMPLE
To highlight the text between the markers
@begin=c@
int i = 42;
@end=c@
with C syntax, and make the markers themselves fade into the background:
:call SyntaxRange#Include('@begin=c@', '@end=c@', 'c', 'NonText')
To highlight inline patches inside emails:
:call SyntaxRange#IncludeEx('start="^changeset\|^Index: \|^diff \|^--- .*\%( ----\)\@<!$" skip="^[-+@ ]" end="^$"', 'diff')
To install this automatically for the "mail" filetype, put above line into a
script in ~/.vim/after/syntax/mail/SyntaxInclude.vim