micro
micro copied to clipboard
either automatic default extension, or automatic syntax
Hi, I wondered if it was possible to have micro either add a default extension to all file text it creates, say .md, so by default it gets to highlight or more or less display) markdown hints ? to get some form of rich text in a termlinal... something awfully difficult, even in 2022. Pfff... Either that or could micro open all text files with that syntax mode, unless it sees more specific extensions (or ANY extension since my text files usually have none) ?
thanks for your help
You can enable Markdown syntax for any file ending in *.txt by adding this to ~/.config/micro/settings.json:
"*.txt": {
"filetype": "markdown"
},
But I don't know how to do this for files without an extension. Not surprisingly using "*" overrides all the internal filetypes and "*." only works for files ending in ".".
I'm not sure Micro if can determine a file type based its contents the way file(1) does.
Sorry for the non-answer, but maybe someone else can chime in with a solution.
yours is a fine one, but only if Micro can get to put a default extension after the filename I submitted if it doesn't see a .something .
Based on my experiments (not looking at the code), there seems to be a hacky way to achieve a default syntax highlighting:
- Copy all the syntax files you want micro to use (even the built-in ones) to
~/.config/micro/syntax/ - Create the desired syntax file in that directory (or just duplicate the one you want)
- Set its first line to
filetype: unknown - Remove the whole
detect:part from it - Rename the file to something that is sorted below all the others (e.g.
zzz.yaml). Note that case is important and lowercase comes after uppercase.
This should work based on my tests.
You can also just specify ft:unknown instead of a glob like *.txt in the settings.json:
{
"ft:unknown": {
"filetype": "markdown"
}
}
@zyedidia I tried it right now and it will replace all the filetypes with markdown even if the extension (or header) is not unknown. I'm on the latest release version (from pacman). Does it actually work like that on the master branch? Because I don't think replacing all the filetypes with markdown is what the OP wanted. He just wanted all the unknown filetypes to show markdown syntax highlighting. My solution actually does work that way. It just shows unknown as the filetype. But the syntax highlighting works for everything else too.