syntax highlighting missing for conf and config files
Description of the problem or steps to reproduce
Unlike nano, micro seems to be missing syntax highlighting for .conf and config files among other file types. If it wasn't for this, I'd move over from nano in a heartbeat. Thanks.
Specifications
Commit hash: micro 2.0.10-1 OS: Arch Linux Terminal: kitty, alacritty
You can create your own custom syntax highlighting files for Micro. Here's a rough attempt I wrote for .conf files. It's based on the syntax highlighting for Apache config files and so assumes comments begin with #.
Save it to ~/.config/micro/syntax/conf.yaml
filetype: conf
detect:
filename: "(\\.(conf)$|\\.(cfg)$)"
rules:
- constant.string:
start: "\""
end: "\""
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."
- comment:
start: "#"
end: "$"
rules:
- todo: "(TODO|XXX|FIXME):?"
Someone could open a pull request to add built-in syntax highlighting for .conf files :slightly_smiling_face:
@zoomosis Thanks!
Bump for this issue. Possibly an easy fix to do ourselves, but it would be nice as default!
In general, it would be nice if micro just let me associate filetypes with an existing syntax highlighting. There has never been a time I opened an "unknown" filetype and was glad it was uncolored. The "ini" syntax highlighting is an extremely sane default.
A general space/tab/comma/etc delimited syntax would be a nice addition as well for "wall of text" files like fstab and logs. The rainbow csv vscode extension does this and its so nice for quick readability. When I was a linux noob and barely was able to use CLI to begin with, rainbow mode would have been a blessing, I didn't even know what syntax highlighting was at first. I say this because micro kinda has the de facto title of being the most accessible CLI editor.
I would either: 1. Make "ini" the default, or create a setting for default/fallback syntax 2. Have a quick setting to associate a file extension or just specific file to a syntax file and remember it. 3. Go the extra mile for beginner users and make a dumb-fire/catchall rainbow syntax.
examples that accomplish this:
set filetype.override conf ini
set filetype.default ini
"Rainbow mode" as fallback highlighting
set rainbow [on|off|all]
set rainbow.delimter ' ' OR set rainbow.delimiter ','
@kernkraft235
Make "ini" the default, or create a setting for default/fallback syntax
Default syntax highlighting was discussed and implemented in #2933 (not in the latest release yet so you need to build from git to get the feature). The default doesn't include .ini syntax but you may provide your own ~/.config/micro/syntax/default.yaml.
Have a quick setting to associate a file extension or just specific file to a syntax file and remember it.
You can achieve this by having the following in your ~/.config/micro/settings.json:
{
"*.conf": {
"filetype": "ini"
},
}
Go the extra mile for beginner users and make a dumb-fire/catchall rainbow syntax.
This is a separate issue (you should probably open a separate issue for discussion if you feel strongly about it) but I think it would be rather tricky to implement with the current regex-based syntax highlighting system.
Something I don't understand is that on Debian 11 (current oldstable) with micro v2.0.8, set filetype conf does produce a result (i.e. lines starting with # are greyed out), while on Arch with v2.0.13 it doesn't.
Does it mean micro used to have a definition syntax for conf files that was removed in a later release?
Edit: I found it, it was commit 975e78d9c0 which removed the conf syntax highlighting definition (too many conflicts apparently)
You can create your own custom syntax highlighting files for Micro. Here's a rough attempt I wrote for .conf files. It's based on the syntax highlighting for Apache config files and so assumes comments begin with #.
Save it to ~/.config/micro/syntax/conf.yaml
filetype: conf
detect: filename: "(\.(conf)$|\.(cfg)$)"
rules: - constant.string: start: """ end: """ skip: "\\." rules: - constant.specialChar: "\\."
- comment: start: "#" end: "$" rules: - todo: "(TODO|XXX|FIXME):?"
Can you please mention where the documentation on how to write these configs can be found?
@tushinski It's under help colors. You may also want to look at the built-in syntax files for inspiration.
@tushinski It's under
help colors. You may also want to look at the built-in syntax files for inspiration.
thank you!