Wasted way too much time on hydra.nvim shit
This commit is contained in:
parent
fe3c267ca9
commit
8a54d25b3b
17 changed files with 540 additions and 80 deletions
dotfiles/neovim/lua/my/plugins
42
dotfiles/neovim/lua/my/plugins/format-nvim.lua
Normal file
42
dotfiles/neovim/lua/my/plugins/format-nvim.lua
Normal file
|
@ -0,0 +1,42 @@
|
|||
local env = require("my.helpers.env")
|
||||
local K = require("my.keymaps")
|
||||
|
||||
local M = {
|
||||
"mhartington/formatter.nvim",
|
||||
event = "BufReadPre",
|
||||
cond = env.vscode.not_active(),
|
||||
}
|
||||
|
||||
function M.config()
|
||||
local any = require("formatter.filetypes.any")
|
||||
local formatters = {
|
||||
markdown = {
|
||||
require("formatter.filetypes.markdown").prettierd,
|
||||
},
|
||||
lua = {
|
||||
require("formatter.filetypes.lua").stylua,
|
||||
},
|
||||
["*"] = {
|
||||
any.remove_trailing_whitespace,
|
||||
},
|
||||
}
|
||||
|
||||
require("formatter").setup({ filetype = formatters })
|
||||
|
||||
local format = function()
|
||||
if formatters[vim.bo.filetype] ~= nil then
|
||||
vim.cmd([[Format]])
|
||||
elseif next(vim.lsp.get_active_clients({ bufnr = 0 })) == nil then
|
||||
vim.lsp.buf.format()
|
||||
end
|
||||
end
|
||||
|
||||
K.nmap("<leader>F", format, "[F]ormat file")
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = vim.api.nvim_create_augroup("Formatting", { clear = false }),
|
||||
callback = format,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue