From b33ae09a3335f8dfceafadeb379213fc5d9d5523 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 8 Dec 2022 13:28:00 +0100 Subject: [PATCH] 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 `f`/`F` to format or format and save respectively. --- nvim/.config/nvim/lua/maps.lua | 5 +++++ nvim/.config/nvim/lua/plug/_format.lua | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/maps.lua index cc8a371..7c889a0 100644 --- a/nvim/.config/nvim/lua/maps.lua +++ b/nvim/.config/nvim/lua/maps.lua @@ -184,6 +184,11 @@ map.n.nore.silent['q'] = 'gqap' map.x.nore.silent['q'] = 'gq' map.n.nore.silent['Q'] = 'vapJgqap' +-- FORMAT code with +-- PLUGIN: formatter.nvim +map.n.nore.silent['f'] = ':FormatLock' +map.n.nore.silent['F'] = ':FormatWriteLock' + -- Enter distraction free prose mode with F11 map.n.nore.silent[''] = ':ZenMode' diff --git a/nvim/.config/nvim/lua/plug/_format.lua b/nvim/.config/nvim/lua/plug/_format.lua index e4cdeac..88c461b 100644 --- a/nvim/.config/nvim/lua/plug/_format.lua +++ b/nvim/.config/nvim/lua/plug/_format.lua @@ -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 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 FormatWrite", +-- desc = "Automatically format on write", +-- group = vim.api.nvim_create_augroup('formatonsave', {clear = true}) +-- }) +-- end