blob: b4aeaf7c8122cbe6afcc94b885a1101c032cac69 [file] [log] [blame]
Bram Moolenaar4c05fa02019-01-01 15:32:17 +01001*textprop.txt* For Vim version 8.1. Last change: 2018 Dec 30
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|
20
21
22{Vi does not have text properties}
23{not able to use text properties when the |+textprop| feature was
24disabled at compile time}
25
26==============================================================================
271. Introduction *text-prop-intro*
28
29Text properties can be attached to text in a buffer. They will move with the
30text: If lines are deleted or inserted the properties move with the text they
31are attached to. Also when inserting/deleting text in the line before the
32text property. And when inserting/deleting text inside the text property, it
33will increase/decrease in size.
34
35The main use for text properties is to highlight text. This can be seen as a
36replacement for syntax highlighting. Instead of defining patterns to match
37the text, the highlighting is set by a script, possibly using the output of an
38external parser. This only needs to be done once, not every time when
39redrawing the screen, thus can be much faster, after the initial cost of
40attaching the text properties.
41
42Text properties can also be used for other purposes to identify text. For
43example, add a text property on a function name, so that a search can be
44defined to jump to the next/previous function.
45
46A text property is attached at a specific line and column, and has a specified
47length. The property can span multiple lines.
48
49A text property has these fields:
50 "id" a number to be used as desired
51 "type" the name of a property type
52
53
54Property Types ~
55 *E971*
56A text property normally has the name of a property type, which defines
57how to highlight the text. The property type can have these entries:
58 "highlight" name of the highlight group to use
59 "priority" when properties overlap, the one with the highest
60 priority will be used.
61 "start_incl" when TRUE inserts at the start position will be
62 included in the text property
63 "end_incl" when TRUE inserts at the end position will be
64 included in the text property
65
66
67Example ~
68
69Suppose line 11 in a buffer has this text (excluding the indent):
70
71 The number 123 is smaller than 4567.
72
Bram Moolenaar4c05fa02019-01-01 15:32:17 +010073To highlight the numbers in this text: >
Bram Moolenaar98aefe72018-12-13 22:20:09 +010074 call prop_type_add('number', {'highlight': 'Constant'})
Bram Moolenaar9d87a372018-12-18 21:41:50 +010075 call prop_add(11, 12, {'length': 3, 'type': 'number'})
76 call prop_add(11, 32, {'length': 4, 'type': 'number'})
Bram Moolenaar98aefe72018-12-13 22:20:09 +010077
Bram Moolenaar4c05fa02019-01-01 15:32:17 +010078Try inserting or deleting lines above the text, you will see that the text
79properties stick to the text, thus the line number is adjusted as needed.
80
Bram Moolenaar98aefe72018-12-13 22:20:09 +010081Setting "start_incl" and "end_incl" is useful when white space surrounds the
82text, e.g. for a function name. Using false is useful when the text starts
83and/or ends with a specific character, such as the quote surrounding a string.
84
85 func FuncName(arg) ~
86 ^^^^^^^^ property with start_incl and end_incl set
87
88 var = "text"; ~
89 ^^^^^^ property with start_incl and end_incl not set
90
91Nevertheless, when text is inserted or deleted the text may need to be parsed
Bram Moolenaar9d87a372018-12-18 21:41:50 +010092and the text properties updated. But this can be done asynchronously.
Bram Moolenaar98aefe72018-12-13 22:20:09 +010093
94==============================================================================
952. Functions *text-prop-functions*
96
97Manipulating text property types:
98
99prop_type_add({name}, {props}) define a new property type
100prop_type_change({name}, {props}) change an existing property type
101prop_type_delete({name} [, {props}]) delete a property type
102prop_type_get([{name} [, {props}]) get property type values
103prop_type_list([{props}]) get list of property types
104
105
106Manipulating text properties:
107
108prop_add({lnum}, {col}, {props}) add a text property
Bram Moolenaarc8c88492018-12-27 23:59:26 +0100109prop_clear({lnum} [, {lnum-end} [, {bufnr}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100110 remove all text properties
111prop_find({props} [, {direction}]) search for a text property
112prop_list({lnum} [, {props}) text properties in {lnum}
Bram Moolenaarc8c88492018-12-27 23:59:26 +0100113prop_remove({props} [, {lnum} [, {lnum-end}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100114 remove a text property
115
116
117 vim:tw=78:ts=8:noet:ft=help:norl: