nvim: Disable automatic formatting on save

Had to disable automatic formatting since it was messing with my
contributions to other git projects, if they did either not have a
formatter enabled (most of the time) or had different formatters or
those set up differently than this setup (fixable, but I don't think
it's worth the time).

Instead, formatting can be invoked with `<localleader>f`/`F` to format
or format and save respectively.
This commit is contained in:
Marty Oehme 2022-12-08 13:28:00 +01:00
parent ea37793997
commit b33ae09a33
Signed by: Marty
GPG key ID: 73BA40D5AFAF49C9
2 changed files with 14 additions and 7 deletions

View file

@ -184,6 +184,11 @@ map.n.nore.silent['<localleader>q'] = 'gqap'
map.x.nore.silent['<localleader>q'] = 'gq'
map.n.nore.silent['<localleader>Q'] = 'vapJgqap'
-- FORMAT code with
-- PLUGIN: formatter.nvim
map.n.nore.silent['<localleader>f'] = ':FormatLock<cr>'
map.n.nore.silent['<localleader>F'] = ':FormatWriteLock<cr>'
-- Enter distraction free prose mode with F11
map.n.nore.silent['<F11>'] = ':ZenMode<cr>'

View file

@ -52,11 +52,13 @@ local formatters = {
require('formatter').setup({ logging = false, filetype = formatters })
-- Format on save:
-- DISABLED FOR NOW, due to messing with git contributions if they
-- do not use a formatter. Instead, formatting with key mapping used.
-- gather filetypes to autocorrect for each activated formatter above
for k, _ in pairs(formatters) do
vim.api.nvim_create_autocmd({"Filetype " .. k}, {
command = "autocmd BufWritePost <buffer> FormatWrite",
desc = "Automatically format on write",
group = vim.api.nvim_create_augroup('formatonsave', {clear = true})
})
end
-- for k, _ in pairs(formatters) do
-- vim.api.nvim_create_autocmd({"Filetype " .. k}, {
-- command = "autocmd BufWritePost <buffer> FormatWrite",
-- desc = "Automatically format on write",
-- group = vim.api.nvim_create_augroup('formatonsave', {clear = true})
-- })
-- end