In the world of Linux, the battle of which text editor to use is probably only rivaled by which distro to use. Micro is one text editor that I use because I appreciate the syntax highlighting and some of the “more familiar” key bindings (like, save is ctrl-s).
Micro does (by default) examine the filename that you are editing to determine a default syntax scheme; so, if the filename ends with “.json” (for example), it will apply a json based syntax highlighting. However, I frequently find myself editing files that don’t have an extension but adhere to a schema. One example of this is my /etc/ansible/hosts file which I use the yaml layout in (Ansible supports a few different formats in this file, I use yaml so I can have indentation for grouping and comments).
Today I looked up how to tell Micro “hey, this file is yaml” so that it would syntax highlight correctly and know to have “ctrl /” comment/uncomment the line with the correct syntax (in yaml, prepend the line with a #).
What I was looking for boils down to:
To set the file type,:
- Press Ctrl-E to activate the command bar
- Enter the command
set filetype yaml(or replaceyamlwith whatever the desired type is)- Press the enter key
Since I searched how to do this online, my search results also suggested that I could set it permanently by specifying the filetype in my config file:
~/.config/micro/settings.json
{
"/etc/ansible/hosts": {
"filetype": "yaml"
}
}
NOTE:
Which
~/should I edit if I need tosudoto edit the file?
I found that I had to put this in root’s .config folder for it to take effect when I use sudo micro /etc/ansible/hosts