]> git.lizzy.rs Git - micro.git/blob - runtime/help/colors.md
Merge branch 'bug-endless-reload-prompt' of https://github.com/jawahars16/micro into...
[micro.git] / runtime / help / colors.md
1 # Colors
2
3 This help page aims to cover two aspects of micro's syntax highlighting engine:
4
5 * How to create colorschemes and use them.
6 * How to create syntax files to add to the list of languages micro can
7   highlight.
8
9 ## Colorschemes
10
11 To change your colorscheme, press CtrlE in micro to bring up the command
12 prompt, and type:
13
14 ```
15 set colorscheme twilight
16 ```
17
18 (or whichever colorscheme you choose).
19
20 Micro comes with a number of colorschemes by default. The colorschemes that you
21 can display will depend on what kind of color support your terminal has.
22
23 Modern terminals tend to have a palette of 16 user-configurable colors (these
24 colors can often be configured in the terminal preferences), and additional
25 color support comes in three flavors.
26
27 * 16-color: A colorscheme that uses the 16 default colors will always work but
28   will only look good if the 16 default colors have been configured to the
29   user's liking. Using a colorscheme that only uses the 16 colors from the
30   terminal palette will also preserve the terminal's theme from other
31   applications since the terminal will often use those same colors for other
32   applications. Default colorschemes of this type include `simple` and
33   `solarized`.
34
35 * 256-color: Almost all terminals support displaying an additional 240 colors
36   on top of the 16 user-configurable colors (creating 256 colors total).
37   Colorschemes which use 256-color are portable because they will look the
38   same regardless of the configured 16-color palette. However, the color
39   range is fairly limited due to the small number of colors available.
40   Default 256-color colorschemes include `monokai`, `twilight`, `zenburn`,
41   `darcula` and more.
42
43 * true-color: Some terminals support displaying "true color" with 16 million
44   colors using standard RGB values. This mode will be able to support
45   displaying any colorscheme, but it should be noted that the user-configured
46   16-color palette is ignored when using true-color mode (this means the
47   colors while using the terminal emulator will be slightly off). Not all
48   terminals support true color but at this point most do. True color
49   support in micro is off by default but can be enabled by setting the
50   environment variable `MICRO_TRUECOLOR` to 1.  In addition your terminal
51   must support it (usually indicated by setting `$COLORTERM` to `truecolor`).
52   True-color colorschemes in micro typically end with `-tc`, such as
53   `solarized-tc`, `atom-dark-tc`, `material-tc`, etc... If true color is not
54   enabled but a true color colorscheme is used, micro will do its best to
55   approximate the colors to the available 256 colors.
56
57 Here is the list of colorschemes:
58
59 ### 256 color
60
61 These should work and look nice in most terminals. I recommend these
62 themes the most.
63
64 * `monokai` (also the `default` colorscheme)
65 * `zenburn`
66 * `gruvbox`
67 * `darcula`
68 * `twilight`
69 * `railscast`
70 * `bubblegum`
71
72 ### 16 color
73
74 These may vary widely based on the 16 colors selected for your terminal.
75
76 * `simple`
77 * `solarized` (must have the solarized color palette in your terminal to use
78    this colorscheme properly)
79 * `cmc-16`
80 * `cmc-paper`
81 * `geany`
82
83 ### True color
84
85 True color requires your terminal to support it. This means that the
86 environment variable `COLORTERM` should have the value `truecolor`, `24bit`,
87 or `24-bit`. In addition, to enable true color in micro, the environment
88 variable `MICRO_TRUECOLOR` must be set to 1.
89
90 * `solarized-tc`: this is the solarized colorscheme for true color.
91 * `atom-dark-tc`: this colorscheme is based off of Atom's "dark" colorscheme.
92 * `cmc-tc`: A true colour variant of the cmc theme.  It requires true color to
93   look its best. Use cmc-16 if your terminal doesn't support true color.
94 * `gruvbox-tc`: The true color version of the gruvbox colorscheme
95 * `github-tc`: The true color version of the Github colorscheme
96 * `material-tc`: Colorscheme based off of Google's Material Design palette
97
98 ## Creating a Colorscheme
99
100 Micro's colorschemes are also extremely simple to create. The default ones can
101 be found
102 [here](https://github.com/zyedidia/micro/tree/master/runtime/colorschemes).
103
104 Custom colorschemes should be placed in the `~/.config/micro/colorschemes`
105 directory.
106
107 A number of custom directives are placed in a `.micro` file. Colorschemes are 
108 typically only 18-30 lines in total.
109
110 To create the colorscheme you need to link highlight groups with
111 actual colors. This is done using the `color-link` command.
112
113 For example, to highlight all comments in green, you would use the command:
114
115 ```
116 color-link comment "green"
117 ```
118
119 Background colors can also be specified with a comma:
120
121 ```
122 color-link comment "green,blue"
123 ```
124
125 This will give the comments a blue background.
126
127 If you would like no foreground you can just use a comma with nothing in front:
128
129 ```
130 color-link comment ",blue"
131 ```
132
133 You can also put bold, or underline in front of the color:
134
135 ```
136 color-link comment "bold red"
137 ```
138
139 ---
140
141 There are three different ways to specify the color.
142
143 Color terminals usually have 16 colors that are preset by the user. This means
144 that you cannot depend on those colors always being the same. You can use those
145 colors with the names `black, red, green, yellow, blue, magenta, cyan, white`
146 and the bright variants of each one (brightblack, brightred...).
147
148 Then you can use the terminals 256 colors by using their numbers 1-256 (numbers
149 1-16 will refer to the named colors).
150
151 If the user's terminal supports true color, then you can also specify colors
152 exactly using their hex codes. If the terminal is not true color but micro is
153 told to use a true color colorscheme it will attempt to map the colors to the 
154 available 256 colors.
155
156 Generally colorschemes which require true color terminals to look good are
157 marked with a `-tc` suffix and colorschemes which supply a white background are
158 marked with a `-paper` suffix.
159
160 ---
161
162 Here is a list of the colorscheme groups that you can use:
163
164 * default (color of the background and foreground for unhighlighted text)
165 * comment
166 * identifier
167 * constant
168 * statement
169 * symbol
170 * preproc
171 * type
172 * special
173 * underlined
174 * error
175 * todo
176 * statusline (Color of the statusline)
177 * tabbar (Color of the tabbar that lists open files)
178 * indent-char (Color of the character which indicates tabs if the option is
179   enabled)
180 * line-number
181 * gutter-error
182 * gutter-warning
183 * cursor-line
184 * current-line-number
185 * color-column
186 * ignore
187 * divider (Color of the divider between vertical splits)
188
189 Colorschemes must be placed in the `~/.config/micro/colorschemes` directory to
190 be used.
191
192 ---
193
194 In addition to the main colorscheme groups, there are subgroups that you can
195 specify by adding `.subgroup` to the group. If you're creating your own custom
196 syntax files, you can make use of your own subgroups.
197
198 If micro can't match the subgroup, it'll default to the root group, so  it's
199 safe and recommended to use subgroups in your custom syntax files.
200
201 For example if `constant.string` is found in your colorscheme, micro will us
202 that for highlighting strings. If it's not found, it will use constant instead.
203 Micro tries to match the largest set of groups it can find in the colorscheme
204 definitions, so if, for examle `constant.bool.true` is found then micro will
205 use that. If `constant.bool.true` is not found but `constant.bool` is found
206 micro will use `constant.bool`. If not, it uses `constant`. 
207
208 Here's a list of subgroups used in micro's built-in syntax files.
209
210 * comment.bright (Some filetypes have distinctions between types of comments)
211 * constant.bool
212 * constant.bool.true
213 * constant.bool.false
214 * constant.number 
215 * constant.specialChar
216 * constant.string
217 * constant.string.url 
218 * identifier.class (Also used for functions)
219 * identifier.macro
220 * identifier.var
221 * preproc.shebang (The #! at the beginning of a file that tells the os what
222   script interpreter to use)
223 * symbol.brackets (`{}()[]` and sometimes `<>`)
224 * symbol.operator (Color operator symbols differently)
225 * symbol.tag (For html tags, among other things)
226 * type.keyword (If you want a special highlight for keywords like `private`)
227
228 In the future, plugins may also be able to use color groups for styling.
229
230
231 ## Syntax files
232
233 The syntax files are written in yaml-format and specify how to highlight
234 languages.
235
236 Micro's builtin syntax highlighting tries very hard to be sane, sensible and
237 provide ample coverage of the meaningful elements of a language. Micro has
238 syntax files built in for over 100 languages now! However, there may be 
239 situations where you find Micro's highlighting to be insufficient or not to
240 your liking. The good news is that you can create your own syntax files, and
241 place them in  `~/.config/micro/syntax` and Micro will use those instead.
242
243 ### Filetype definition
244
245 You must start the syntax file by declaring the filetype:
246
247 ```
248 filetype: go
249 ```
250
251 ### Detect definition
252
253 Then you must provide information about how to detect the filetype:
254
255 ```
256 detect:
257     filename: "\\.go$"
258 ```
259
260 Micro will match this regex against a given filename to detect the filetype.
261 You may also provide an optional `header` regex that will check the first line
262 of the file. For example:
263
264 ```
265 detect:
266     filename: "\\.ya?ml$"
267     header: "%YAML"
268 ```
269
270 ### Syntax rules
271
272 Next you must provide the syntax highlighting rules. There are two types of
273 rules: patterns and regions. A pattern is matched on a single line and usually
274 a single word as well. A region highlights between two patterns over multiple
275 lines and may have rules of its own inside the region.
276
277 Here are some example patterns in Go:
278
279 ```
280 rules:
281     - special: "\\b(break|case|continue|default|go|goto|range|return)\\b"
282     - statement: "\\b(else|for|if|switch)\\b"
283     - preproc: "\\b(package|import|const|var|type|struct|func|go|defer|iota)\\b"
284 ```
285
286 The order of patterns does matter as patterns lower in the file will overwrite
287 the ones defined above them.
288
289 And here are some example regions for Go:
290
291 ```
292 - constant.string:
293     start: "\""
294     end: "\""
295     rules:
296         - constant.specialChar: "%."
297         - constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]"
298         - constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})"
299
300 - comment:
301     start: "//"
302     end: "$"
303     rules:
304         - todo: "(TODO|XXX|FIXME):?"
305
306 - comment:
307     start: "/\\*"
308     end: "\\*/"
309     rules:
310         - todo: "(TODO|XXX|FIXME):?"
311 ```
312
313 Notice how the regions may contain rules inside of them. Any inner rules that
314 are matched are then skipped when searching for the end of the region. For
315 example, when highlighting `"foo \" bar"`, since `\"` is matched by an inner
316 rule in the region, it is skipped. Likewise for `"foo \\" bar`, since `\\` is
317 matched by an inner rule, it is skipped, and then the `"` is found and the
318 string ends at the correct place.
319
320 You may also explicitly mark skip regexes if you don't want them to be
321 highlighted. For example:
322
323 ```
324 - constant.string:
325     start: "\""
326     end: "\""
327     skip: "\\."
328     rules: []
329 ```
330
331 #### Includes
332
333 You may also include rules from other syntax files as embedded languages. For
334 example, the following is possible for html:
335
336 ```
337 - default:
338     start: "<script.*?>"
339     end: "</script.*?>"
340     rules:
341         - include: "javascript"
342
343 - default:
344     start: "<style.*?>"
345     end: "</style.*?>"
346     rules:
347         - include: "css"
348 ```
349
350 ## Syntax file headers
351
352 Syntax file headers are an optimization and it is likely you do not need to
353 worry about them.
354
355 Syntax file headers are files that contain only the filetype and the detection
356 regular expressions for a given syntax file. They have a `.hdr` suffix and are
357 used by default only for the pre-installed syntax files. Header files allow
358 micro to parse the syntax files much faster when checking the filetype of a
359 certain file. Custom syntax files may provide header files in
360 `~/.config/micro/syntax` as well but it is not necessary (only do this if you
361 have many (100+) custom syntax files and want to improve performance).