nvim: add separate config files for most plugins
This commit is contained in:
parent
9db80c9673
commit
04dacde028
25 changed files with 294 additions and 291 deletions
71
modules/programs/nvim/plugins/formatter-nvim.lua
Normal file
71
modules/programs/nvim/plugins/formatter-nvim.lua
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
|
||||
require("formatter").setup({
|
||||
-- Enable or disable logging
|
||||
logging = true,
|
||||
-- Set the log level
|
||||
log_level = vim.log.levels.WARN,
|
||||
-- All formatter configurations are opt-in
|
||||
filetype = {
|
||||
json = {
|
||||
require("formatter.filetypes.json").jq,
|
||||
},
|
||||
lua = {
|
||||
require("formatter.filetypes.lua").stylua,
|
||||
},
|
||||
nix = {
|
||||
require("formatter.filetypes.nix").nixpkgs_fmt,
|
||||
},
|
||||
python = {
|
||||
require("formatter.filetypes.python").black,
|
||||
},
|
||||
rust = {
|
||||
require("formatter.filetypes.rust").rustfmt,
|
||||
},
|
||||
sh = {
|
||||
require("formatter.filetypes.sh").shfmt,
|
||||
},
|
||||
toml = {
|
||||
require("formatter.filetypes.toml").taplo,
|
||||
},
|
||||
yaml = {
|
||||
require("formatter.filetypes.yaml").yamlfmt,
|
||||
},
|
||||
|
||||
-- HACK to use specific formatters only when specified
|
||||
alejandra = {
|
||||
require("formatter.filetypes.nix").alejandra,
|
||||
},
|
||||
isort = {
|
||||
require("formatter.filetypes.python").isort,
|
||||
},
|
||||
|
||||
-- Use the special "*" filetype for defining formatter configurations on
|
||||
-- any filetype
|
||||
["*"] = {
|
||||
-- "formatter.filetypes.any" defines default configurations for any
|
||||
-- filetype
|
||||
require("formatter.filetypes.any").remove_trailing_whitespace,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("Fmt", function(opts)
|
||||
local params = vim.split(opts.args, "%s+", { trimempty = true })
|
||||
local filetype = vim.bo.filetype
|
||||
vim.cmd("set filetype=" .. params[1]) -- fake filetype
|
||||
vim.cmd(":Format")
|
||||
vim.cmd("set filetype=" .. filetype) -- restore original filetype
|
||||
end, {
|
||||
nargs = 1,
|
||||
complete = function()
|
||||
local languages = {
|
||||
nix = { "alejandra" },
|
||||
python = { "isort" },
|
||||
}
|
||||
return languages[vim.bo.filetype] or {}
|
||||
end,
|
||||
})
|
||||
|
||||
require("which-key").register({
|
||||
["="] = { "<cmd>Format<cr>", "format (formatter)" },
|
||||
}, { noremap = true, silent = true })
|
||||
Loading…
Add table
Add a link
Reference in a new issue