Christian Brabandt | 701c863 | 2024-09-08 20:05:23 +0200 | [diff] [blame] | 1 | *textprop.txt* For Vim version 9.1. Last change: 2024 Sep 08 |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
Bram Moolenaar | a6c27c4 | 2019-05-09 19:16:22 +0200 | [diff] [blame] | 7 | Displaying text with properties attached. *textprop* *text-properties* |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 8 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 9 | |
| 10 | 1. Introduction |text-prop-intro| |
| 11 | 2. Functions |text-prop-functions| |
Bram Moolenaar | d09091d | 2019-01-17 16:07:22 +0100 | [diff] [blame] | 12 | 3. When text changes |text-prop-changes| |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 13 | |
| 14 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 15 | {not able to use text properties when the |+textprop| feature was |
| 16 | disabled at compile time} |
| 17 | |
| 18 | ============================================================================== |
| 19 | 1. Introduction *text-prop-intro* |
| 20 | |
| 21 | Text properties can be attached to text in a buffer. They will move with the |
| 22 | text: If lines are deleted or inserted the properties move with the text they |
| 23 | are attached to. Also when inserting/deleting text in the line before the |
| 24 | text property. And when inserting/deleting text inside the text property, it |
| 25 | will increase/decrease in size. |
| 26 | |
| 27 | The main use for text properties is to highlight text. This can be seen as a |
| 28 | replacement for syntax highlighting. Instead of defining patterns to match |
| 29 | the text, the highlighting is set by a script, possibly using the output of an |
| 30 | external parser. This only needs to be done once, not every time when |
| 31 | redrawing the screen, thus can be much faster, after the initial cost of |
| 32 | attaching the text properties. |
| 33 | |
| 34 | Text properties can also be used for other purposes to identify text. For |
| 35 | example, add a text property on a function name, so that a search can be |
| 36 | defined to jump to the next/previous function. |
| 37 | |
| 38 | A text property is attached at a specific line and column, and has a specified |
| 39 | length. The property can span multiple lines. |
| 40 | |
| 41 | A text property has these fields: |
| 42 | "id" a number to be used as desired |
| 43 | "type" the name of a property type |
| 44 | |
| 45 | |
| 46 | Property Types ~ |
| 47 | *E971* |
Bram Moolenaar | 664f3cf | 2019-12-07 16:03:51 +0100 | [diff] [blame] | 48 | A text property normally has the name of a property type, which defines |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 49 | how to highlight the text. The property type can have these entries: |
| 50 | "highlight" name of the highlight group to use |
Bram Moolenaar | 574ee7b | 2019-11-13 23:04:29 +0100 | [diff] [blame] | 51 | "combine" when omitted or TRUE the text property highlighting is |
| 52 | combined with any syntax highlighting; when FALSE the |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 53 | text property highlighting replaces the syntax |
| 54 | highlighting |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 55 | "priority" when properties overlap, the one with the highest |
| 56 | priority will be used. |
| 57 | "start_incl" when TRUE inserts at the start position will be |
| 58 | included in the text property |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 59 | "end_incl" when TRUE inserts at the end position will be |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 60 | included in the text property |
| 61 | |
| 62 | |
| 63 | Example ~ |
| 64 | |
| 65 | Suppose line 11 in a buffer has this text (excluding the indent): |
| 66 | |
| 67 | The number 123 is smaller than 4567. |
| 68 | |
Bram Moolenaar | 4c05fa0 | 2019-01-01 15:32:17 +0100 | [diff] [blame] | 69 | To highlight the numbers in this text: > |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 70 | call prop_type_add('number', {'highlight': 'Constant'}) |
Bram Moolenaar | 9d87a37 | 2018-12-18 21:41:50 +0100 | [diff] [blame] | 71 | call prop_add(11, 12, {'length': 3, 'type': 'number'}) |
| 72 | call prop_add(11, 32, {'length': 4, 'type': 'number'}) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 73 | |
Bram Moolenaar | 4c05fa0 | 2019-01-01 15:32:17 +0100 | [diff] [blame] | 74 | Try inserting or deleting lines above the text, you will see that the text |
| 75 | properties stick to the text, thus the line number is adjusted as needed. |
| 76 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 77 | Setting "start_incl" and "end_incl" is useful when white space surrounds the |
| 78 | text, e.g. for a function name. Using false is useful when the text starts |
| 79 | and/or ends with a specific character, such as the quote surrounding a string. |
| 80 | |
| 81 | func FuncName(arg) ~ |
| 82 | ^^^^^^^^ property with start_incl and end_incl set |
| 83 | |
| 84 | var = "text"; ~ |
| 85 | ^^^^^^ property with start_incl and end_incl not set |
| 86 | |
| 87 | Nevertheless, when text is inserted or deleted the text may need to be parsed |
Bram Moolenaar | 9d87a37 | 2018-12-18 21:41:50 +0100 | [diff] [blame] | 88 | and the text properties updated. But this can be done asynchronously. |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 89 | |
Bram Moolenaar | 96f45c0 | 2019-10-26 19:53:45 +0200 | [diff] [blame] | 90 | |
| 91 | Internal error *E967* |
| 92 | |
| 93 | If you see E967, please report the bug. You can do this at Github: |
| 94 | https://github.com/vim/vim/issues/new |
| 95 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 96 | ============================================================================== |
| 97 | 2. Functions *text-prop-functions* |
| 98 | |
| 99 | Manipulating text property types: |
| 100 | |
| 101 | prop_type_add({name}, {props}) define a new property type |
| 102 | prop_type_change({name}, {props}) change an existing property type |
| 103 | prop_type_delete({name} [, {props}]) delete a property type |
Bram Moolenaar | cb80aa2 | 2020-10-26 21:12:46 +0100 | [diff] [blame] | 104 | prop_type_get({name} [, {props}]) get property type values |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 105 | prop_type_list([{props}]) get list of property types |
| 106 | |
| 107 | |
| 108 | Manipulating text properties: |
| 109 | |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 110 | prop_add({lnum}, {col}, {props}) add a text property |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 111 | prop_add_list({props}, [{item}, ...]) |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 112 | add a text property at multiple |
| 113 | positions. |
Bram Moolenaar | c8c8849 | 2018-12-27 23:59:26 +0100 | [diff] [blame] | 114 | prop_clear({lnum} [, {lnum-end} [, {bufnr}]]) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 115 | remove all text properties |
| 116 | prop_find({props} [, {direction}]) search for a text property |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 117 | prop_list({lnum} [, {props}]) text properties in {lnum} |
Bram Moolenaar | c8c8849 | 2018-12-27 23:59:26 +0100 | [diff] [blame] | 118 | prop_remove({props} [, {lnum} [, {lnum-end}]]) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 119 | remove a text property |
| 120 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 121 | *text-prop-functions-details* |
| 122 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 123 | *prop_add()* *E965* |
| 124 | prop_add({lnum}, {col}, {props}) |
| 125 | Attach a text property at position {lnum}, {col}. {col} is |
| 126 | counted in bytes, use one for the first column. |
| 127 | If {lnum} is invalid an error is given. *E966* |
| 128 | If {col} is invalid an error is given. *E964* |
| 129 | |
| 130 | {props} is a dictionary with these fields: |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 131 | type name of the text property type |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 132 | length length of text in bytes, can only be used |
| 133 | for a property that does not continue in |
| 134 | another line; can be zero |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 135 | end_lnum line number for the end of text (inclusive) |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 136 | end_col column just after the text; not used when |
| 137 | "length" is present; when {col} and "end_col" |
| 138 | are equal, and "end_lnum" is omitted or equal |
| 139 | to {lnum}, this is a zero-width text property |
| 140 | bufnr buffer to add the property to; when omitted |
| 141 | the current buffer is used |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 142 | id user defined ID for the property; must be a |
Christian Brabandt | 701c863 | 2024-09-08 20:05:23 +0200 | [diff] [blame] | 143 | number, should be positive |E1510|; |
| 144 | when using "text" then "id" must not be |
| 145 | present and will be set automatically to a |
| 146 | negative number; otherwise zero is used |
Bram Moolenaar | 9712ff1 | 2022-09-18 13:04:22 +0100 | [diff] [blame] | 147 | *E1305* |
Bram Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 148 | text text to be displayed before {col}, or |
| 149 | above/below the line if {col} is zero; prepend |
| 150 | and/or append spaces for padding with |
| 151 | highlighting; cannot be used with "length", |
Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 152 | "end_lnum" and "end_col" |
| 153 | See |virtual-text| for more information. |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 154 | *E1294* |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 155 | text_align when "text" is present and {col} is zero; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 156 | specifies where to display the text: |
| 157 | after after the end of the line |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 158 | right right aligned in the window (unless |
| 159 | the text wraps to the next screen |
| 160 | line) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 161 | below in the next screen line |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 162 | above just above the line |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 163 | When omitted "after" is used. Only one |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 164 | "right" property can fit in each line, if |
Bram Moolenaar | 9712ff1 | 2022-09-18 13:04:22 +0100 | [diff] [blame] | 165 | there are two or more these will go in a |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 166 | separate line (still right aligned). |
| 167 | text_padding_left *E1296* |
| 168 | used when "text" is present and {col} is zero; |
| 169 | padding between the end of the text line |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 170 | (leftmost column for "above" and "below") and |
| 171 | the virtual text, not highlighted |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 172 | text_wrap when "text" is present and {col} is zero, |
| 173 | specifies what happens if the text doesn't |
| 174 | fit: |
| 175 | wrap wrap the text to the next line |
| 176 | truncate truncate the text to make it fit |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 177 | When omitted "truncate" is used. |
Bram Moolenaar | 3c053a1 | 2022-10-16 13:11:12 +0100 | [diff] [blame] | 178 | Note that this applies to the individual text |
| 179 | property, the 'wrap' option sets the overall |
| 180 | behavior |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 181 | All fields except "type" are optional. |
| 182 | |
| 183 | It is an error when both "length" and "end_lnum" or "end_col" |
| 184 | are given. Either use "length" or "end_col" for a property |
| 185 | within one line, or use "end_lnum" and "end_col" for a |
| 186 | property that spans more than one line. |
| 187 | When neither "length" nor "end_col" are given the property |
Bram Moolenaar | bc93ceb | 2020-02-26 13:36:21 +0100 | [diff] [blame] | 188 | will be zero-width. That means it will move with the text, as |
| 189 | a kind of mark. One character will be highlighted, if the |
| 190 | type specifies highlighting. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 191 | The property can end exactly at the last character of the |
| 192 | text, or just after it. In the last case, if text is appended |
| 193 | to the line, the text property size will increase, also when |
| 194 | the property type does not have "end_incl" set. |
| 195 | |
| 196 | "type" will first be looked up in the buffer the property is |
| 197 | added to. When not found, the global property types are used. |
| 198 | If not found an error is given. |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 199 | *virtual-text* |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 200 | When "text" is used and the column is non-zero then this text |
Bram Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 201 | will be displayed at the specified start location of the text |
| 202 | property. The text of the buffer line will be shifted to make |
| 203 | room. This is called "virtual text". |
| 204 | When the column is zero the virtual text will appear above, |
| 205 | after or below the buffer text. The "text_align" and |
| 206 | "text_wrap" arguments determine how it is displayed. |
| 207 | To separate the virtual text from the buffer text prepend |
| 208 | and/or append spaces to the "text" field or use the |
| 209 | "text_padding_left" value. |
| 210 | |
| 211 | Make sure to use a highlight that makes clear to the user that |
| 212 | this is virtual text, otherwise it will be very confusing that |
| 213 | the text cannot be edited. When using "above" you need to |
| 214 | make clear this text belongs to the text line below it, when |
| 215 | using "below" you need to make sure it belongs to the text |
| 216 | line above it. |
| 217 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 218 | The text will be displayed but it is not part of the actual |
| 219 | buffer line, the cursor cannot be placed on it. A mouse click |
| 220 | in the text will move the cursor to the first character after |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 221 | the text, or the last character of the line. |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 222 | Any Tab and other control character in the text will be |
| 223 | changed to a space (Rationale: otherwise the size of the text |
| 224 | is difficult to compute). |
Bram Moolenaar | f1dcd14 | 2022-12-31 15:30:45 +0000 | [diff] [blame] | 225 | A negative "id" will be chosen and is returned. |
| 226 | |
| 227 | Before text properties with text were supported it was |
| 228 | possible to use a negative "id", even though this was very |
| 229 | rare. Now that negative "id"s are reserved for text |
| 230 | properties with text an error is given when using a negative |
| 231 | "id". When a text property with text already exists using a |
| 232 | negative "id" results in *E1293* . If a negative "id" was |
| 233 | used and later a text property with text is added results in |
| 234 | *E1339* . |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 235 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 236 | Can also be used as a |method|: > |
| 237 | GetLnum()->prop_add(col, props) |
Yegappan Lakshmanan | 820d552 | 2021-09-17 21:07:35 +0200 | [diff] [blame] | 238 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 239 | Return type: |Number| |
| 240 | |
| 241 | |
| 242 | prop_add_list({props}, [{item}, ...]) *prop_add_list()* |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 243 | Similar to prop_add(), but attaches a text property at |
| 244 | multiple positions in a buffer. |
| 245 | |
| 246 | {props} is a dictionary with these fields: |
| 247 | bufnr buffer to add the property to; when omitted |
| 248 | the current buffer is used |
| 249 | id user defined ID for the property; must be a |
| 250 | number; when omitted zero is used |
| 251 | type name of the text property type |
| 252 | All fields except "type" are optional. |
| 253 | |
Bram Moolenaar | d93009e | 2022-10-13 14:35:24 +0100 | [diff] [blame] | 254 | The second argument is a List of items, where each {item} is a |
| 255 | list that specifies the starting and ending position of the |
| 256 | text: [{lnum}, {col}, {end-lnum}, {end-col}] |
| 257 | or: [{lnum}, {col}, {end-lnum}, {end-col}, {id}] |
| 258 | |
| 259 | The first two items {lnum} and {col} specify the starting |
| 260 | position of the text where the property will be attached. |
| 261 | The next two items {end-lnum} and {end-col} specify the |
| 262 | position just after the text. |
| 263 | An optional fifth item {id} can be used to give a different ID |
| 264 | to a property. When omitted the ID from {props} is used, |
| 265 | falling back to zero if none are present. |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 266 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 267 | It is not possible to add a text property with a "text" field |
| 268 | here. |
| 269 | |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 270 | Example: > |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 271 | call prop_add_list(#{type: 'MyProp', id: 2}, |
| 272 | \ [[1, 4, 1, 7], |
| 273 | \ [1, 15, 1, 20], |
Christian Brabandt | 701c863 | 2024-09-08 20:05:23 +0200 | [diff] [blame] | 274 | \ [2, 30, 3, 30]]) |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 275 | < |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 276 | Can also be used as a |method|: > |
| 277 | GetProp()->prop_add_list([[1, 1, 1, 2], [1, 4, 1, 8]]) |
| 278 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 279 | |
| 280 | prop_clear({lnum} [, {lnum-end} [, {props}]]) *prop_clear()* |
| 281 | Remove all text properties from line {lnum}. |
| 282 | When {lnum-end} is given, remove all text properties from line |
| 283 | {lnum} to {lnum-end} (inclusive). |
| 284 | |
| 285 | When {props} contains a "bufnr" item use this buffer, |
| 286 | otherwise use the current buffer. |
| 287 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 288 | Can also be used as a |method|: > |
| 289 | GetLnum()->prop_clear() |
| 290 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 291 | Return type: |Number| |
| 292 | |
| 293 | |
| 294 | prop_find({props} [, {direction}]) *prop_find()* |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 295 | Search for a text property as specified with {props}: |
| 296 | id property with this ID |
| 297 | type property with this type name |
Bram Moolenaar | 24f21fd | 2021-03-27 22:07:29 +0100 | [diff] [blame] | 298 | both "id" and "type" must both match |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 299 | bufnr buffer to search in; when present a |
| 300 | start position with "lnum" and "col" |
| 301 | must be given; when omitted the |
| 302 | current buffer is used |
| 303 | lnum start in this line (when omitted start |
| 304 | at the cursor) |
| 305 | col start at this column (when omitted |
| 306 | and "lnum" is given: use column 1, |
| 307 | otherwise start at the cursor) |
| 308 | skipstart do not look for a match at the start |
| 309 | position |
| 310 | |
Bram Moolenaar | 24f21fd | 2021-03-27 22:07:29 +0100 | [diff] [blame] | 311 | A property matches when either "id" or "type" matches. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 312 | {direction} can be "f" for forward and "b" for backward. When |
| 313 | omitted forward search is performed. |
| 314 | |
| 315 | If a match is found then a Dict is returned with the entries |
| 316 | as with prop_list(), and additionally an "lnum" entry. |
| 317 | If no match is found then an empty Dict is returned. |
| 318 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 319 | Return type: dict<any> |
| 320 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 321 | |
| 322 | prop_list({lnum} [, {props}]) *prop_list()* |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 323 | Returns a List with all the text properties in line {lnum}. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 324 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 325 | The following optional items are supported in {props}: |
| 326 | bufnr use this buffer instead of the current buffer |
| 327 | end_lnum return text properties in all the lines |
| 328 | between {lnum} and {end_lnum} (inclusive). |
| 329 | A negative value is used as an offset from the |
| 330 | last buffer line; -1 refers to the last buffer |
| 331 | line. |
| 332 | types List of property type names. Return only text |
| 333 | properties that match one of the type names. |
| 334 | ids List of property identifiers. Return only text |
| 335 | properties with one of these identifiers. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 336 | |
| 337 | The properties are ordered by starting column and priority. |
| 338 | Each property is a Dict with these entries: |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 339 | lnum starting line number. Present only when |
| 340 | returning text properties between {lnum} and |
| 341 | {end_lnum}. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 342 | col starting column |
| 343 | length length in bytes, one more if line break is |
| 344 | included |
| 345 | id property ID |
Yegappan Lakshmanan | f9037f1 | 2023-08-20 18:27:45 +0200 | [diff] [blame] | 346 | text text to be displayed before {col}. Only |
| 347 | present for |virtual-text| properties. |
| 348 | text_align alignment property of |virtual-text|. |
Yegappan Lakshmanan | 171c5b9 | 2023-08-22 21:48:50 +0200 | [diff] [blame] | 349 | text_padding_left |
| 350 | left padding used for virtual text. |
Yegappan Lakshmanan | f9037f1 | 2023-08-20 18:27:45 +0200 | [diff] [blame] | 351 | text_wrap specifies whether |virtual-text| is wrapped. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 352 | type name of the property type, omitted if |
| 353 | the type was deleted |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 354 | type_bufnr buffer number for which this type was defined; |
| 355 | 0 if the type is global |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 356 | start when TRUE property starts in this line |
| 357 | end when TRUE property ends in this line |
| 358 | |
| 359 | When "start" is zero the property started in a previous line, |
| 360 | the current one is a continuation. |
| 361 | When "end" is zero the property continues in the next line. |
| 362 | The line break after this line is included. |
| 363 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 364 | Returns an empty list on error. |
| 365 | |
| 366 | Examples: |
| 367 | " get text properties placed in line 5 |
| 368 | echo prop_list(5) |
| 369 | " get text properties placed in line 20 in buffer 4 |
| 370 | echo prop_list(20, {'bufnr': 4}) |
| 371 | " get all the text properties between line 1 and 20 |
| 372 | echo prop_list(1, {'end_lnum': 20}) |
| 373 | " get all the text properties of type 'myprop' |
| 374 | echo prop_list(1, {'types': ['myprop'], |
| 375 | \ 'end_lnum': -1}) |
| 376 | " get all the text properties of type 'prop1' or 'prop2' |
| 377 | echo prop_list(1, {'types': ['prop1', 'prop2'], |
| 378 | \ 'end_lnum': -1}) |
| 379 | " get all the text properties with ID 8 |
| 380 | echo prop_list(1, {'ids': [8], 'end_lnum': line('$')}) |
| 381 | " get all the text properties with ID 10 and 20 |
| 382 | echo prop_list(1, {'ids': [10, 20], 'end_lnum': -1}) |
| 383 | " get text properties with type 'myprop' and ID 100 |
| 384 | " in buffer 4. |
| 385 | echo prop_list(1, {'bufnr': 4, 'types': ['myprop'], |
| 386 | \ 'ids': [100], 'end_lnum': -1}) |
| 387 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 388 | Can also be used as a |method|: > |
| 389 | GetLnum()->prop_list() |
| 390 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 391 | Return type: list<dict<any>> or list<any> |
| 392 | |
Bram Moolenaar | 7ff7846 | 2020-07-10 22:00:53 +0200 | [diff] [blame] | 393 | *prop_remove()* *E968* *E860* |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 394 | prop_remove({props} [, {lnum} [, {lnum-end}]]) |
| 395 | Remove a matching text property from line {lnum}. When |
| 396 | {lnum-end} is given, remove matching text properties from line |
| 397 | {lnum} to {lnum-end} (inclusive). |
| 398 | When {lnum} is omitted remove matching text properties from |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 399 | all lines (this requires going over all lines, thus will be a |
| 400 | bit slow for a buffer with many lines). |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 401 | |
| 402 | {props} is a dictionary with these fields: |
| 403 | id remove text properties with this ID |
| 404 | type remove text properties with this type name |
Bram Moolenaar | fd99945 | 2022-08-24 18:30:14 +0100 | [diff] [blame] | 405 | types remove text properties with type names in this |
| 406 | List |
| 407 | both "id" and "type"/"types" must both match |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 408 | bufnr use this buffer instead of the current one |
| 409 | all when TRUE remove all matching text properties, |
| 410 | not just the first one |
Bram Moolenaar | fd99945 | 2022-08-24 18:30:14 +0100 | [diff] [blame] | 411 | Only one of "type" and "types" may be supplied. *E1295* |
| 412 | |
| 413 | A property matches when either "id" or one of the supplied |
| 414 | types matches. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 415 | If buffer "bufnr" does not exist you get an error message. |
| 416 | If buffer "bufnr" is not loaded then nothing happens. |
| 417 | |
| 418 | Returns the number of properties that were removed. |
| 419 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 420 | Can also be used as a |method|: > |
| 421 | GetProps()->prop_remove() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 422 | < |
| 423 | Return type: |Number| |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 424 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 425 | |
| 426 | prop_type_add({name}, {props}) *prop_type_add()* *E969* *E970* |
| 427 | Add a text property type {name}. If a property type with this |
Bram Moolenaar | 06fe74a | 2019-08-31 16:20:32 +0200 | [diff] [blame] | 428 | name already exists an error is given. Nothing is returned. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 429 | {props} is a dictionary with these optional fields: |
| 430 | bufnr define the property only for this buffer; this |
| 431 | avoids name collisions and automatically |
| 432 | clears the property types when the buffer is |
| 433 | deleted. |
| 434 | highlight name of highlight group to use |
| 435 | priority when a character has multiple text |
| 436 | properties the one with the highest priority |
| 437 | will be used; negative values can be used, the |
| 438 | default priority is zero |
Bram Moolenaar | dad4473 | 2021-03-31 20:07:33 +0200 | [diff] [blame] | 439 | combine when omitted or TRUE combine the highlight |
| 440 | with any syntax highlight; when FALSE syntax |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 441 | highlight will not be used |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 442 | override when TRUE the highlight overrides any other, |
| 443 | including 'cursorline' and Visual |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 444 | start_incl when TRUE inserts at the start position will |
| 445 | be included in the text property |
| 446 | end_incl when TRUE inserts at the end position will be |
| 447 | included in the text property |
| 448 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 449 | Can also be used as a |method|: > |
| 450 | GetPropName()->prop_type_add(props) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 451 | < |
| 452 | Return type: |Number| |
| 453 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 454 | |
| 455 | prop_type_change({name}, {props}) *prop_type_change()* |
| 456 | Change properties of an existing text property type. If a |
| 457 | property with this name does not exist an error is given. |
| 458 | The {props} argument is just like |prop_type_add()|. |
| 459 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 460 | Can also be used as a |method|: > |
| 461 | GetPropName()->prop_type_change(props) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 462 | < |
| 463 | Return type: |Number| |
| 464 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 465 | |
| 466 | prop_type_delete({name} [, {props}]) *prop_type_delete()* |
| 467 | Remove the text property type {name}. When text properties |
| 468 | using the type {name} are still in place, they will not have |
| 469 | an effect and can no longer be removed by name. |
| 470 | |
| 471 | {props} can contain a "bufnr" item. When it is given, delete |
| 472 | a property type from this buffer instead of from the global |
| 473 | property types. |
| 474 | |
| 475 | When text property type {name} is not found there is no error. |
| 476 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 477 | Can also be used as a |method|: > |
| 478 | GetPropName()->prop_type_delete() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 479 | < |
| 480 | Return type: |Number| |
| 481 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 482 | |
Bram Moolenaar | cb80aa2 | 2020-10-26 21:12:46 +0100 | [diff] [blame] | 483 | prop_type_get({name} [, {props}]) *prop_type_get()* |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 484 | Returns the properties of property type {name}. This is a |
| 485 | dictionary with the same fields as was given to |
| 486 | prop_type_add(). |
| 487 | When the property type {name} does not exist, an empty |
| 488 | dictionary is returned. |
| 489 | |
| 490 | {props} can contain a "bufnr" item. When it is given, use |
| 491 | this buffer instead of the global property types. |
| 492 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 493 | Can also be used as a |method|: > |
| 494 | GetPropName()->prop_type_get() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 495 | < |
| 496 | Return type: dict<any> |
| 497 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 498 | |
| 499 | prop_type_list([{props}]) *prop_type_list()* |
| 500 | Returns a list with all property type names. |
| 501 | |
| 502 | {props} can contain a "bufnr" item. When it is given, use |
| 503 | this buffer instead of the global property types. |
| 504 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 505 | Return type: list<string> or list<any> |
| 506 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 507 | |
Bram Moolenaar | d09091d | 2019-01-17 16:07:22 +0100 | [diff] [blame] | 508 | ============================================================================== |
| 509 | 3. When text changes *text-prop-changes* |
| 510 | |
| 511 | Vim will do its best to keep the text properties on the text where it was |
| 512 | attached. When inserting or deleting text the properties after the change |
| 513 | will move accordingly. |
| 514 | |
| 515 | When text is deleted and a text property no longer includes any text, it is |
| 516 | deleted. However, a text property that was defined as zero-width will remain, |
| 517 | unless the whole line is deleted. |
Bram Moolenaar | 30e9b3c | 2019-09-07 16:24:12 +0200 | [diff] [blame] | 518 | *E275* |
Bram Moolenaar | 45311b5 | 2019-08-13 22:27:32 +0200 | [diff] [blame] | 519 | When a buffer is unloaded, all the text properties are gone. There is no way |
| 520 | to store the properties in a file. You can only re-create them. When a |
| 521 | buffer is hidden the text is preserved and so are the text properties. It is |
| 522 | not possible to add text properties to an unloaded buffer. |
Bram Moolenaar | d09091d | 2019-01-17 16:07:22 +0100 | [diff] [blame] | 523 | |
| 524 | When using replace mode, the text properties stay on the same character |
| 525 | positions, even though the characters themselves change. |
| 526 | |
Bram Moolenaar | 68e6560 | 2019-05-26 21:33:31 +0200 | [diff] [blame] | 527 | To update text properties after the text was changed, install a callback with |
| 528 | `listener_add()`. E.g, if your plugin does spell checking, you can have the |
| 529 | callback update spelling mistakes in the changed text. Vim will move the |
| 530 | properties below the changed text, so that they still highlight the same text, |
| 531 | thus you don't need to update these. |
| 532 | |
Christian Brabandt | 946f61c | 2024-06-17 13:17:58 +0200 | [diff] [blame] | 533 | *text-prop-cleared* |
Bram Moolenaar | bc93ceb | 2020-02-26 13:36:21 +0100 | [diff] [blame] | 534 | Text property columns are not updated or copied: ~ |
Bram Moolenaar | d09091d | 2019-01-17 16:07:22 +0100 | [diff] [blame] | 535 | |
| 536 | - When setting the line with |setline()| or through an interface, such as Lua, |
Bram Moolenaar | a6c27c4 | 2019-05-09 19:16:22 +0200 | [diff] [blame] | 537 | Tcl or Python. Vim does not know what text got inserted or deleted. |
Bram Moolenaar | bc93ceb | 2020-02-26 13:36:21 +0100 | [diff] [blame] | 538 | - With a command like `:move`, which takes a line of text out of context. |
Bram Moolenaar | d09091d | 2019-01-17 16:07:22 +0100 | [diff] [blame] | 539 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 540 | |
| 541 | vim:tw=78:ts=8:noet:ft=help:norl: |