3 This help page aims to cover two aspects of micro's syntax highlighting engine:
5 * How to create colorschemes and use them.
6 * How to create syntax files to add to the list of languages micro can
11 To change your colorscheme, press CtrlE in micro to bring up the command
15 set colorscheme twilight
18 (or whichever colorscheme you choose).
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.
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.
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
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`,
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.
57 Here is the list of colorschemes:
61 These should work and look nice in most terminals. I recommend these
64 * `monokai` (also the `default` colorscheme)
74 These may vary widely based on the 16 colors selected for your terminal.
77 * `solarized` (must have the solarized color palette in your terminal to use
78 this colorscheme properly)
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.
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
98 ## Creating a Colorscheme
100 Micro's colorschemes are also extremely simple to create. The default ones can
102 [here](https://github.com/zyedidia/micro/tree/master/runtime/colorschemes).
104 Custom colorschemes should be placed in the `~/.config/micro/colorschemes`
107 A number of custom directives are placed in a `.micro` file. Colorschemes are
108 typically only 18-30 lines in total.
110 To create the colorscheme you need to link highlight groups with
111 actual colors. This is done using the `color-link` command.
113 For example, to highlight all comments in green, you would use the command:
116 color-link comment "green"
119 Background colors can also be specified with a comma:
122 color-link comment "green,blue"
125 This will give the comments a blue background.
127 If you would like no foreground you can just use a comma with nothing in front:
130 color-link comment ",blue"
133 You can also put bold, or underline in front of the color:
136 color-link comment "bold red"
141 There are three different ways to specify the color.
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...).
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).
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.
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.
162 Here is a list of the colorscheme groups that you can use:
164 * default (color of the background and foreground for unhighlighted text)
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
184 * current-line-number
187 * divider (Color of the divider between vertical splits)
189 Colorschemes must be placed in the `~/.config/micro/colorschemes` directory to
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.
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.
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`.
208 Here's a list of subgroups used in micro's built-in syntax files.
210 * comment.bright (Some filetypes have distinctions between types of comments)
213 * constant.bool.false
215 * constant.specialChar
217 * constant.string.url
218 * identifier.class (Also used for functions)
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`)
228 In the future, plugins may also be able to use color groups for styling.
233 The syntax files are written in yaml-format and specify how to highlight
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.
243 ### Filetype definition
245 You must start the syntax file by declaring the filetype:
251 ### Detect definition
253 Then you must provide information about how to detect the filetype:
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:
266 filename: "\\.ya?ml$"
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.
277 Here are some example patterns in Go:
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"
286 The order of patterns does matter as patterns lower in the file will overwrite
287 the ones defined above them.
289 And here are some example regions for Go:
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})"
304 - todo: "(TODO|XXX|FIXME):?"
310 - todo: "(TODO|XXX|FIXME):?"
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.
320 You may also explicitly mark skip regexes if you don't want them to be
321 highlighted. For example:
333 You may also include rules from other syntax files as embedded languages. For
334 example, the following is possible for html:
341 - include: "javascript"
350 ## Syntax file headers
352 Syntax file headers are an optimization and it is likely you do not need to
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).