| 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 `Ctrl-e` 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 |
Omit color-link default "[fg color],[bg color]" will make the background color match the terminal's, and transparency if set. |
| 24 |
|
| 25 |
Modern terminals tend to have a palette of 16 user-configurable colors (these |
| 26 |
colors can often be configured in the terminal preferences), and additional |
| 27 |
color support comes in three flavors. |
| 28 |
|
| 29 |
* 16-color: A colorscheme that uses the 16 default colors will always work but |
| 30 |
will only look good if the 16 default colors have been configured to the |
| 31 |
user's liking. Using a colorscheme that only uses the 16 colors from the |
| 32 |
terminal palette will also preserve the terminal's theme from other |
| 33 |
applications since the terminal will often use those same colors for other |
| 34 |
applications. Default colorschemes of this type include `simple` and |
| 35 |
`solarized`. |
| 36 |
|
| 37 |
* 256-color: Almost all terminals support displaying an additional 240 colors |
| 38 |
on top of the 16 user-configurable colors (creating 256 colors total). |
| 39 |
Colorschemes which use 256-color are portable because they will look the |
| 40 |
same regardless of the configured 16-color palette. However, the color |
| 41 |
range is fairly limited due to the small number of colors available. |
| 42 |
Default 256-color colorschemes include `monokai`, `twilight`, `zenburn`, |
| 43 |
`darcula` and more. |
| 44 |
|
| 45 |
* true-color: Some terminals support displaying "true color" with 16 million |
| 46 |
colors using standard RGB values. This mode will be able to support |
| 47 |
displaying any colorscheme, but it should be noted that the user-configured |
| 48 |
16-color palette is ignored when using true-color mode (this means the |
| 49 |
colors while using the terminal emulator will be slightly off). Not all |
| 50 |
terminals support true color but at this point most do (see below). |
| 51 |
True-color colorschemes in micro typically end with `-tc`, such as |
| 52 |
`solarized-tc`, `atom-dark`, `material-tc`, etc... If true color is not |
| 53 |
enabled but a true color colorscheme is used, micro will do its best to |
| 54 |
approximate the colors to the available 256 colors. |
| 55 |
|
| 56 |
Here is the list of colorschemes: |
| 57 |
|
| 58 |
### 256 color |
| 59 |
|
| 60 |
These should work and look nice in most terminals. I recommend these |
| 61 |
themes the most. |
| 62 |
|
| 63 |
* `monokai` (also the `default` colorscheme) |
| 64 |
* `zenburn` |
| 65 |
* `gruvbox` |
| 66 |
* `darcula` |
| 67 |
* `twilight` |
| 68 |
* `railscast` |
| 69 |
* `bubblegum` (light theme) |
| 70 |
|
| 71 |
### 16 color |
| 72 |
|
| 73 |
These may vary widely based on the 16 colors selected for your terminal. |
| 74 |
|
| 75 |
* `simple` |
| 76 |
* `solarized` (must have the solarized color palette in your terminal to use |
| 77 |
this colorscheme properly) |
| 78 |
* `cmc-16` |
| 79 |
* `cmc-paper` |
| 80 |
* `geany` |
| 81 |
|
| 82 |
### True color |
| 83 |
|
| 84 |
Micro enables true color support by default as long as it detects that the |
| 85 |
terminal supports it (which is usually indicated by the environment variable |
| 86 |
`COLORTERM` being set to `truecolor`, `24bit` or `24-bit`). You can also force |
| 87 |
enabling it unconditionally by setting the option `truecolor` to `on` (or |
| 88 |
alternatively by setting the environment variable `MICRO_TRUECOLOR` to 1, which |
| 89 |
is supported for backward compatibility). |
| 90 |
|
| 91 |
* `solarized-tc`: this is the solarized colorscheme for true color. |
| 92 |
* `atom-dark`: this colorscheme is based off of Atom's "dark" colorscheme. |
| 93 |
* `cmc-tc`: A true colour variant of the cmc theme. It requires true color to |
| 94 |
look its best. Use cmc-16 if your terminal doesn't support true color. |
| 95 |
* `gruvbox-tc`: The true color version of the gruvbox 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, italic, 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 |
* selection (Color of the text selection) |
| 177 |
* statusline (Color of the statusline) |
| 178 |
* statusline.inactive (Color of the statusline of inactive split panes) |
| 179 |
* statusline.suggestions (Color of the autocomplete suggestions menu) |
| 180 |
* tabbar (Color of the tabbar that lists open files) |
| 181 |
* tabbar.active (Color of the active tab in the tabbar) |
| 182 |
* indent-char (Color of the character which indicates tabs if the option is |
| 183 |
enabled) |
| 184 |
* line-number |
| 185 |
* gutter-info |
| 186 |
* gutter-error |
| 187 |
* gutter-warning |
| 188 |
* diff-added |
| 189 |
* diff-modified |
| 190 |
* diff-deleted |
| 191 |
* cursor-line |
| 192 |
* current-line-number |
| 193 |
* color-column |
| 194 |
* ignore |
| 195 |
* scrollbar |
| 196 |
* divider (Color of the divider between vertical splits) |
| 197 |
* message (Color of messages in the bottom line of the screen) |
| 198 |
* error-message (Color of error messages in the bottom line of the screen) |
| 199 |
* match-brace (Color of matching brackets when `matchbracestyle` is set to `highlight`) |
| 200 |
* hlsearch (Color of highlighted search results when `hlsearch` is enabled) |
| 201 |
* tab-error (Color of tab vs space errors when `hltaberrors` is enabled) |
| 202 |
* trailingws (Color of trailing whitespaces when `hltrailingws` is enabled) |
| 203 |
|
| 204 |
Colorschemes must be placed in the `~/.config/micro/colorschemes` directory to |
| 205 |
be used. |
| 206 |
|
| 207 |
--- |
| 208 |
|
| 209 |
In addition to the main colorscheme groups, there are subgroups that you can |
| 210 |
specify by adding `.subgroup` to the group. If you're creating your own custom |
| 211 |
syntax files, you can make use of your own subgroups. |
| 212 |
|
| 213 |
If micro can't match the subgroup, it'll default to the root group, so it's |
| 214 |
safe and recommended to use subgroups in your custom syntax files. |
| 215 |
|
| 216 |
For example if `constant.string` is found in your colorscheme, micro will us |
| 217 |
that for highlighting strings. If it's not found, it will use constant instead. |
| 218 |
Micro tries to match the largest set of groups it can find in the colorscheme |
| 219 |
definitions, so if, for example `constant.bool.true` is found then micro will |
| 220 |
use that. If `constant.bool.true` is not found but `constant.bool` is found |
| 221 |
micro will use `constant.bool`. If not, it uses `constant`. |
| 222 |
|
| 223 |
Here's a list of subgroups used in micro's built-in syntax files. |
| 224 |
|
| 225 |
* comment.bright (Some filetypes have distinctions between types of comments) |
| 226 |
* constant.bool |
| 227 |
* constant.bool.true |
| 228 |
* constant.bool.false |
| 229 |
* constant.number |
| 230 |
* constant.specialChar |
| 231 |
* constant.string |
| 232 |
* constant.string.url |
| 233 |
* identifier.class (Also used for functions) |
| 234 |
* identifier.macro |
| 235 |
* identifier.var |
| 236 |
* preproc.shebang (The #! at the beginning of a file that tells the os what |
| 237 |
script interpreter to use) |
| 238 |
* symbol.brackets (`{}()[]` and sometimes `<>`) |
| 239 |
* symbol.operator (Color operator symbols differently) |
| 240 |
* symbol.tag (For html tags, among other things) |
| 241 |
* type.keyword (If you want a special highlight for keywords like `private`) |
| 242 |
|
| 243 |
In the future, plugins may also be able to use color groups for styling. |
| 244 |
|
| 245 |
--- |
| 246 |
|
| 247 |
Last but not least it's even possible to use `include` followed by the |
| 248 |
colorscheme name as string to include a different colorscheme within a new one. |
| 249 |
Additionally the groups can then be extended or overwritten. The `default.micro` |
| 250 |
theme can be seen as an example, which links to the chosen default colorscheme. |
| 251 |
|
| 252 |
## Syntax files |
| 253 |
|
| 254 |
The syntax files are written in yaml-format and specify how to highlight |
| 255 |
languages. |
| 256 |
|
| 257 |
Micro's builtin syntax highlighting tries very hard to be sane, sensible and |
| 258 |
provide ample coverage of the meaningful elements of a language. Micro has |
| 259 |
syntax files built in for over 100 languages now! However, there may be |
| 260 |
situations where you find Micro's highlighting to be insufficient or not to |
| 261 |
your liking. The good news is that you can create your own syntax files, and |
| 262 |
place them in `~/.config/micro/syntax` and Micro will use those instead. |
| 263 |
|
| 264 |
### Filetype definition |
| 265 |
|
| 266 |
You must start the syntax file by declaring the filetype: |
| 267 |
|
| 268 |
``` |
| 269 |
filetype: go |
| 270 |
``` |
| 271 |
|
| 272 |
### Detect definition |
| 273 |
|
| 274 |
Then you must provide information about how to detect the filetype: |
| 275 |
|
| 276 |
``` |
| 277 |
detect: |
| 278 |
filename: "\\.go$" |
| 279 |
``` |
| 280 |
|
| 281 |
Micro will match this regex against a given filename to detect the filetype. |
| 282 |
|
| 283 |
In addition to the `filename` regex (or even instead of it) you can provide |
| 284 |
a `header` regex that will check the first line of the file. For example: |
| 285 |
|
| 286 |
``` |
| 287 |
detect: |
| 288 |
filename: "\\.ya?ml$" |
| 289 |
header: "%YAML" |
| 290 |
``` |
| 291 |
|
| 292 |
This is useful in cases when the given file name is not sufficient to determine |
| 293 |
the filetype, e.g. with the above example, if a YAML file has no `.yaml` |
| 294 |
extension but may contain a `%YAML` directive in its first line. |
| 295 |
|
| 296 |
`filename` takes precedence over `header`, i.e. if there is a syntax file that |
| 297 |
matches the file with a filetype by the `filename` and another syntax file that |
| 298 |
matches the same file with another filetype by the `header`, the first filetype |
| 299 |
will be used. |
| 300 |
|
| 301 |
Finally, in addition to `filename` and/or `header` (but not instead of them) |
| 302 |
you may also provide an optional `signature` regex which is useful for resolving |
| 303 |
ambiguities when there are multiple syntax files matching the same file with |
| 304 |
different filetypes. If a `signature` regex is given, micro will match a certain |
| 305 |
amount of first lines in the file (this amount is determined by the `detectlimit` |
| 306 |
option) against this regex, and if any of the lines match, this syntax file's |
| 307 |
filetype will be preferred over other matching filetypes. |
| 308 |
|
| 309 |
For example, to distinguish C++ header files from C and Objective-C header files |
| 310 |
that have the same `.h` extension: |
| 311 |
|
| 312 |
``` |
| 313 |
detect: |
| 314 |
filename: "\\.c(c|pp|xx)$|\\.h(h|pp|xx)?$" |
| 315 |
signature: "namespace|template|public|protected|private" |
| 316 |
``` |
| 317 |
|
| 318 |
### Syntax rules |
| 319 |
|
| 320 |
Next you must provide the syntax highlighting rules. There are two types of |
| 321 |
rules: patterns and regions. A pattern is matched on a single line and usually |
| 322 |
a single word as well. A region highlights between two patterns over multiple |
| 323 |
lines and may have rules of its own inside the region. |
| 324 |
|
| 325 |
Here are some example patterns in Go: |
| 326 |
|
| 327 |
``` |
| 328 |
rules: |
| 329 |
- special: "\\b(break|case|continue|default|go|goto|range|return)\\b" |
| 330 |
- statement: "\\b(else|for|if|switch)\\b" |
| 331 |
- preproc: "\\b(package|import|const|var|type|struct|func|go|defer|iota)\\b" |
| 332 |
``` |
| 333 |
|
| 334 |
The order of patterns does matter as patterns lower in the file will overwrite |
| 335 |
the ones defined above them. |
| 336 |
|
| 337 |
And here are some example regions for Go: |
| 338 |
|
| 339 |
``` |
| 340 |
- constant.string: |
| 341 |
start: "\"" |
| 342 |
end: "\"" |
| 343 |
rules: |
| 344 |
- constant.specialChar: "%." |
| 345 |
- constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]" |
| 346 |
- constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" |
| 347 |
|
| 348 |
- comment: |
| 349 |
start: "//" |
| 350 |
end: "$" |
| 351 |
rules: |
| 352 |
- todo: "(TODO|XXX|FIXME):?" |
| 353 |
|
| 354 |
- comment: |
| 355 |
start: "/\\*" |
| 356 |
end: "\\*/" |
| 357 |
rules: |
| 358 |
- todo: "(TODO|XXX|FIXME):?" |
| 359 |
``` |
| 360 |
|
| 361 |
Notice how the regions may contain rules inside of them. Any inner rules that |
| 362 |
are matched are then skipped when searching for the end of the region. For |
| 363 |
example, when highlighting `"foo \" bar"`, since `\"` is matched by an inner |
| 364 |
rule in the region, it is skipped. Likewise for `"foo \\" bar`, since `\\` is |
| 365 |
matched by an inner rule, it is skipped, and then the `"` is found and the |
| 366 |
string ends at the correct place. |
| 367 |
|
| 368 |
You may also explicitly mark skip regexes if you don't want them to be |
| 369 |
highlighted. For example: |
| 370 |
|
| 371 |
``` |
| 372 |
- constant.string: |
| 373 |
start: "\"" |
| 374 |
end: "\"" |
| 375 |
skip: "\\." |
| 376 |
``` |
| 377 |
|
| 378 |
#### Includes |
| 379 |
|
| 380 |
You may also include rules from other syntax files as embedded languages. For |
| 381 |
example, the following is possible for html: |
| 382 |
|
| 383 |
``` |
| 384 |
- default: |
| 385 |
start: "<script.*?>" |
| 386 |
end: "</script.*?>" |
| 387 |
rules: |
| 388 |
- include: "javascript" |
| 389 |
|
| 390 |
- default: |
| 391 |
start: "<style.*?>" |
| 392 |
end: "</style.*?>" |
| 393 |
rules: |
| 394 |
- include: "css" |
| 395 |
``` |
| 396 |
|
| 397 |
Note that nested include (i.e. including syntax files that include other syntax |
| 398 |
files) is not supported yet. |
| 399 |
|
| 400 |
### Default syntax highlighting |
| 401 |
|
| 402 |
If micro cannot detect the filetype of the file, it falls back to using the |
| 403 |
default syntax highlighting for it, which highlights just the bare minimum: |
| 404 |
email addresses, URLs etc. |
| 405 |
|
| 406 |
Just like in other cases, you can override the default highlighting by adding |
| 407 |
your own custom `default.yaml` file to `~/.config/micro/syntax`. |
| 408 |
|
| 409 |
For example, if you work with various config files that use the `#` sign to mark |
| 410 |
the beginning of a comment, you can use the following custom `default.yaml` to |
| 411 |
highlight those comments by default: |
| 412 |
|
| 413 |
``` |
| 414 |
filetype: unknown |
| 415 |
|
| 416 |
detect: |
| 417 |
filename: "" |
| 418 |
|
| 419 |
rules: |
| 420 |
- comment: "(^|\\s)#.*$" |
| 421 |
``` |