Uses nimpretty
to format Nim code while allowing for tab indentation and diff viewing.
Usage: nimpretty_t [options] <path>...
Formatter and diff viewer utilizing nimpretty.
By default, formatted output is written to stdout.
Options:
-w --write Modifies non-conforming files in-place.
-l --list Prints paths of non-conforming files. Exits with an error if any are found.
-d --diff Prints differences of non-conforming files. Exits with an error if any are found.
-i --indentation Sets the indentation used [possible values: 'tabs', 'smart', '<num>'(spaces)].
- tabs: used by default.
- smart: based on the initial indentations in a file.
- <num>: number of spaces.
-L --line-length Sets the max character line length. Default is 100.
--stdin Formats input from stdin.
-h --help Prints this help information.
-v --version Prints version information.
Environment Variables:
NIM_DIFF_CMD Sets a custom diff command that is used with the '-diff' option
E.g.: 'NIM_DIFFCMD="diff --color=always -U 2"'
-
Via nimble
nimble install nimpretty_t
-
Pre-built binaries can be downloaded from the release page.
-
Register
nimpretty_t
innull-ls
/none-ls
local null_ls = require("null-ls") -- ... null_ls.register({ name = "nimpretty_t", method = null_ls.methods.FORMATTING, filetypes = { "nim" }, generator = null_ls.formatter({ command = "nimpretty_t", args = { "-w", "$FILENAME" }, to_temp_file = true, }), })
A complementary tool regarding indentation for neovim is tabs-vs-spaces.nvim
-
Since nimpretty_t is a niche project in the Nim community, it is not yet clear whether it will have a user base that can benefit from its own VS Code extension. To save efforts the extension has not yet been completed. Until then, please use the
Run on Save
extension from emeraldwalk.// settings.json // ... "emeraldwalk.runonsave": { "commands": [ { "match": "\\.nim$", "isAsync": true, "cmd": "nimpretty_t -w ${file}" } ] }