]> git.lizzy.rs Git - micro.git/blob - runtime/help/colors.md
Merge branch 'issue_1008' of https://github.com/sum01/micro into sum01-issue_1008
[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
97 ## Creating a Colorscheme
98
99 Micro's colorschemes are also extremely simple to create. The default ones can
100 be found
101 [here](https://github.com/zyedidia/micro/tree/master/runtime/colorschemes).
102
103 Custom colorschemes should be placed in the `~/.config/micro/colorschemes`
104 directory.
105
106 A number of custom directives are placed in a `.micro` file. Colorschemes are 
107 typically only 18-30 lines in total.
108
109 To create the colorscheme you need to link highlight groups with
110 actual colors. This is done using the `color-link` command.
111
112 For example, to highlight all comments in green, you would use the command:
113
114 ```
115 color-link comment "green"
116 ```
117
118 Background colors can also be specified with a comma:
119
120 ```
121 color-link comment "green,blue"
122 ```
123
124 This will give the comments a blue background.
125
126 If you would like no foreground you can just use a comma with nothing in front:
127
128 ```
129 color-link comment ",blue"
130 ```
131
132 You can also put bold, or underline in front of the color:
133
134 ```
135 color-link comment "bold red"
136 ```
137
138 ---
139
140 There are three different ways to specify the color.
141
142 Color terminals usually have 16 colors that are preset by the user. This means
143 that you cannot depend on those colors always being the same. You can use those
144 colors with the names `black, red, green, yellow, blue, magenta, cyan, white`
145 and the bright variants of each one (brightblack, brightred...).
146
147 Then you can use the terminals 256 colors by using their numbers 1-256 (numbers
148 1-16 will refer to the named colors).
149
150 If the user's terminal supports true color, then you can also specify colors
151 exactly using their hex codes. If the terminal is not true color but micro is
152 told to use a true color colorscheme it will attempt to map the colors to the 
153 available 256 colors.
154
155 Generally colorschemes which require true color terminals to look good are
156 marked with a `-tc` suffix and colorschemes which supply a white background are
157 marked with a `-paper` suffix.
158
159 ---
160
161 Here is a list of the colorscheme groups that you can use:
162
163 * default (color of the background and foreground for unhighlighted text)
164 * comment
165 * identifier
166 * constant
167 * statement
168 * symbol
169 * preproc
170 * type
171 * special
172 * underlined
173 * error
174 * todo
175 * statusline (Color of the statusline)
176 * tabbar (Color of the tabbar that lists open files)
177 * indent-char (Color of the character which indicates tabs if the option is
178   enabled)
179 * line-number
180 * gutter-error
181 * gutter-warning
182 * cursor-line
183 * current-line-number
184 * color-column
185 * ignore
186 * divider (Color of the divider between vertical splits)
187
188 Colorschemes must be placed in the `~/.config/micro/colorschemes` directory to
189 be used.
190
191 ---
192
193 In addition to the main colorscheme groups, there are subgroups that you can
194 specify by adding `.subgroup` to the group. If you're creating your own custom
195 syntax files, you can make use of your own subgroups.
196
197 If micro can't match the subgroup, it'll default to the root group, so  it's
198 safe and recommended to use subgroups in your custom syntax files.
199
200 For example if `constant.string` is found in your colorscheme, micro will us
201 that for highlighting strings. If it's not found, it will use constant instead.
202 Micro tries to match the largest set of groups it can find in the colorscheme
203 definitions, so if, for examle `constant.bool.true` is found then micro will
204 use that. If `constant.bool.true` is not found but `constant.bool` is found
205 micro will use `constant.bool`. If not, it uses `constant`. 
206
207 Here's a list of subgroups used in micro's built-in syntax files.
208
209 * comment.bright (Some filetypes have distinctions between types of comments)
210 * constant.bool
211 * constant.bool.true
212 * constant.bool.false
213 * constant.number 
214 * constant.specialChar
215 * constant.string
216 * constant.string.url 
217 * identifier.class (Also used for functions)
218 * identifier.macro
219 * identifier.var
220 * preproc.shebang (The #! at the beginning of a file that tells the os what
221   script interpreter to use)
222 * symbol.brackets (`{}()[]` and sometimes `<>`)
223 * symbol.operator (Color operator symbols differently)
224 * symbol.tag (For html tags, among other things)
225 * type.keyword (If you want a special highlight for keywords like `private`)
226
227 In the future, plugins may also be able to use color groups for styling.
228
229
230 ## Syntax files
231
232 The syntax files are written in yaml-format and specify how to highlight
233 languages.
234
235 Micro's builtin syntax highlighting tries very hard to be sane, sensible and
236 provide ample coverage of the meaningful elements of a language. Micro has
237 syntax files built in for over 100 languages now! However, there may be 
238 situations where you find Micro's highlighting to be insufficient or not to
239 your liking. The good news is that you can create your own syntax files, and
240 place them in  `~/.config/micro/syntax` and Micro will use those instead.
241
242 ### Filetype definition
243
244 You must start the syntax file by declaring the filetype:
245
246 ```
247 filetype: go
248 ```
249
250 ### Detect definition
251
252 Then you must provide information about how to detect the filetype:
253
254 ```
255 detect:
256     filename: "\\.go$"
257 ```
258
259 Micro will match this regex against a given filename to detect the filetype.
260 You may also provide an optional `header` regex that will check the first line
261 of the file. For example:
262
263 ```
264 detect:
265     filename: "\\.ya?ml$"
266     header: "%YAML"
267 ```
268
269 ### Syntax rules
270
271 Next you must provide the syntax highlighting rules. There are two types of
272 rules: patterns and regions. A pattern is matched on a single line and usually
273 a single word as well. A region highlights between two patterns over multiple
274 lines and may have rules of its own inside the region.
275
276 Here are some example patterns in Go:
277
278 ```
279 rules:
280     - special: "\\b(break|case|continue|default|go|goto|range|return)\\b"
281     - statement: "\\b(else|for|if|switch)\\b"
282     - preproc: "\\b(package|import|const|var|type|struct|func|go|defer|iota)\\b"
283 ```
284
285 The order of patterns does matter as patterns lower in the file will overwrite
286 the ones defined above them.
287
288 And here are some example regions for Go:
289
290 ```
291 - constant.string:
292     start: "\""
293     end: "\""
294     rules:
295         - constant.specialChar: "%."
296         - constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]"
297         - constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})"
298
299 - comment:
300     start: "//"
301     end: "$"
302     rules:
303         - todo: "(TODO|XXX|FIXME):?"
304
305 - comment:
306     start: "/\\*"
307     end: "\\*/"
308     rules:
309         - todo: "(TODO|XXX|FIXME):?"
310 ```
311
312 Notice how the regions may contain rules inside of them. Any inner rules that
313 are matched are then skipped when searching for the end of the region. For
314 example, when highlighting `"foo \" bar"`, since `\"` is matched by an inner
315 rule in the region, it is skipped. Likewise for `"foo \\" bar`, since `\\` is
316 matched by an inner rule, it is skipped, and then the `"` is found and the
317 string ends at the correct place.
318
319 You may also explicitly mark skip regexes if you don't want them to be
320 highlighted. For example:
321
322 ```
323 - constant.string:
324     start: "\""
325     end: "\""
326     skip: "\\."
327     rules: []
328 ```
329
330 #### Includes
331
332 You may also include rules from other syntax files as embedded languages. For
333 example, the following is possible for html:
334
335 ```
336 - default:
337     start: "<script.*?>"
338     end: "</script.*?>"
339     rules:
340         - include: "javascript"
341
342 - default:
343     start: "<style.*?>"
344     end: "</style.*?>"
345     rules:
346         - include: "css"
347 ```
348
349 ## Syntax file headers
350
351 Syntax file headers are an optimization and it is likely you do not need to
352 worry about them.
353
354 Syntax file headers are files that contain only the filetype and the detection
355 regular expressions for a given syntax file. They have a `.hdr` suffix and are
356 used by default only for the pre-installed syntax files. Header files allow
357 micro to parse the syntax files much faster when checking the filetype of a
358 certain file. Custom syntax files may provide header files in
359 `~/.config/micro/syntax` as well but it is not necessary (only do this if you
360 have many (100+) custom syntax files and want to improve performance).