blob: 263c40eb1ce875c965e59e11b75943c1c58513f7 [file] [log] [blame]
Bram Moolenaarde24a872019-05-05 15:48:00 +02001*textprop.txt* For Vim version 8.1. Last change: 2019 May 05
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Displaying text with properties attached. *text-properties*
8
9THIS IS UNDER DEVELOPMENT - ANYTHING MAY STILL CHANGE *E967*
10
11What is not working yet:
12- Adjusting column/length when inserting text
13- Text properties spanning more than one line
14- prop_find()
15- callbacks when text properties are outdated
16
17
181. Introduction |text-prop-intro|
192. Functions |text-prop-functions|
Bram Moolenaard09091d2019-01-17 16:07:22 +0100203. When text changes |text-prop-changes|
Bram Moolenaar98aefe72018-12-13 22:20:09 +010021
22
23{Vi does not have text properties}
24{not able to use text properties when the |+textprop| feature was
25disabled at compile time}
26
27==============================================================================
281. Introduction *text-prop-intro*
29
30Text properties can be attached to text in a buffer. They will move with the
31text: If lines are deleted or inserted the properties move with the text they
32are attached to. Also when inserting/deleting text in the line before the
33text property. And when inserting/deleting text inside the text property, it
34will increase/decrease in size.
35
36The main use for text properties is to highlight text. This can be seen as a
37replacement for syntax highlighting. Instead of defining patterns to match
38the text, the highlighting is set by a script, possibly using the output of an
39external parser. This only needs to be done once, not every time when
40redrawing the screen, thus can be much faster, after the initial cost of
41attaching the text properties.
42
43Text properties can also be used for other purposes to identify text. For
44example, add a text property on a function name, so that a search can be
45defined to jump to the next/previous function.
46
47A text property is attached at a specific line and column, and has a specified
48length. The property can span multiple lines.
49
50A text property has these fields:
51 "id" a number to be used as desired
52 "type" the name of a property type
53
54
55Property Types ~
56 *E971*
57A text property normally has the name of a property type, which defines
58how to highlight the text. The property type can have these entries:
59 "highlight" name of the highlight group to use
Bram Moolenaarde24a872019-05-05 15:48:00 +020060 "combine" when TRUE the text property highlighting is combined
61 with any syntax highligting, when omitted or FALSE the
62 text property highlighting replaces the syntax
63 highlighting
Bram Moolenaar98aefe72018-12-13 22:20:09 +010064 "priority" when properties overlap, the one with the highest
65 priority will be used.
66 "start_incl" when TRUE inserts at the start position will be
67 included in the text property
68 "end_incl" when TRUE inserts at the end position will be
69 included in the text property
70
71
72Example ~
73
74Suppose line 11 in a buffer has this text (excluding the indent):
75
76 The number 123 is smaller than 4567.
77
Bram Moolenaar4c05fa02019-01-01 15:32:17 +010078To highlight the numbers in this text: >
Bram Moolenaar98aefe72018-12-13 22:20:09 +010079 call prop_type_add('number', {'highlight': 'Constant'})
Bram Moolenaar9d87a372018-12-18 21:41:50 +010080 call prop_add(11, 12, {'length': 3, 'type': 'number'})
81 call prop_add(11, 32, {'length': 4, 'type': 'number'})
Bram Moolenaar98aefe72018-12-13 22:20:09 +010082
Bram Moolenaar4c05fa02019-01-01 15:32:17 +010083Try inserting or deleting lines above the text, you will see that the text
84properties stick to the text, thus the line number is adjusted as needed.
85
Bram Moolenaar98aefe72018-12-13 22:20:09 +010086Setting "start_incl" and "end_incl" is useful when white space surrounds the
87text, e.g. for a function name. Using false is useful when the text starts
88and/or ends with a specific character, such as the quote surrounding a string.
89
90 func FuncName(arg) ~
91 ^^^^^^^^ property with start_incl and end_incl set
92
93 var = "text"; ~
94 ^^^^^^ property with start_incl and end_incl not set
95
96Nevertheless, when text is inserted or deleted the text may need to be parsed
Bram Moolenaar9d87a372018-12-18 21:41:50 +010097and the text properties updated. But this can be done asynchronously.
Bram Moolenaar98aefe72018-12-13 22:20:09 +010098
99==============================================================================
1002. Functions *text-prop-functions*
101
102Manipulating text property types:
103
104prop_type_add({name}, {props}) define a new property type
105prop_type_change({name}, {props}) change an existing property type
106prop_type_delete({name} [, {props}]) delete a property type
107prop_type_get([{name} [, {props}]) get property type values
108prop_type_list([{props}]) get list of property types
109
110
111Manipulating text properties:
112
113prop_add({lnum}, {col}, {props}) add a text property
Bram Moolenaarc8c88492018-12-27 23:59:26 +0100114prop_clear({lnum} [, {lnum-end} [, {bufnr}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100115 remove all text properties
116prop_find({props} [, {direction}]) search for a text property
117prop_list({lnum} [, {props}) text properties in {lnum}
Bram Moolenaarc8c88492018-12-27 23:59:26 +0100118prop_remove({props} [, {lnum} [, {lnum-end}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100119 remove a text property
120
Bram Moolenaard09091d2019-01-17 16:07:22 +0100121==============================================================================
1223. When text changes *text-prop-changes*
123
124Vim will do its best to keep the text properties on the text where it was
125attached. When inserting or deleting text the properties after the change
126will move accordingly.
127
128When text is deleted and a text property no longer includes any text, it is
129deleted. However, a text property that was defined as zero-width will remain,
130unless the whole line is deleted.
131
132When using replace mode, the text properties stay on the same character
133positions, even though the characters themselves change.
134
135
136When text property columns are not updated ~
137
138- When setting the line with |setline()| or through an interface, such as Lua,
139 Tcl or Python.
140
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100141
142 vim:tw=78:ts=8:noet:ft=help:norl: