format command changes the content of the file based on the file type and the formatter command associated with the file type.
- Open
~\.config\micro\init.lua. Create new file when non-existent - Modify
init.lua. Refer toinit.luain this gist. - Update
~\.config\micro\settings.jsonto add the formatters. I've tested only python, lua and html. Others may work 🙏
- For other formatter not listed, refer to the documentation of the cli of the formatter.
- To add the other formatter, open
~\.config\micro\settings.json, add the follwing key, where%frefers to the path of the current file:"formatter.filetype.<target filetype>": "cli formatter and its arguments" - To replace the formatter for a file type, update the existign entry in
settings.jsonor run the commandset formatter.filetype.<target filetype> "cli formatter and its arguments". For an example, to useruffas python formatter, run the following command:set formatter.filetype.python "ruff format %f"
For some reason, micro does not properly reload files that uses dos line ending. You can check the file format by
running this command: show fileformat. Changing the file format to unix fixes the issue. In case there's no problem
with changing the line ending from dos to unix, run command setlocal fileformat unix before running the format
command. If it's not possible to change from dos to unix line ending, you may exit micro and reload. Not ideal though 🥲