From 5381e06eb9bfa0b71d26a4439312076b7ea93412 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 19 Oct 2023 09:42:48 +0200 Subject: [PATCH] Introduce autocommand for formatting Now, before a file is saved, we call the vim api format() function which formats the content of the file. --- lua/myworkflow/autocommands.lua | 5 +++++ lua/myworkflow/init.lua | 1 + 2 files changed, 6 insertions(+) create mode 100644 lua/myworkflow/autocommands.lua diff --git a/lua/myworkflow/autocommands.lua b/lua/myworkflow/autocommands.lua new file mode 100644 index 0000000..fbca73b --- /dev/null +++ b/lua/myworkflow/autocommands.lua @@ -0,0 +1,5 @@ +vim.api.nvim_create_autocmd('BufWritePre', { + callback = function() + vim.lsp.buf.format { async = false } + end +}) diff --git a/lua/myworkflow/init.lua b/lua/myworkflow/init.lua index 1321594..68169b0 100644 --- a/lua/myworkflow/init.lua +++ b/lua/myworkflow/init.lua @@ -1,3 +1,4 @@ require("myworkflow.remap") require("myworkflow.set") require("myworkflow.packer") +require("myworkflow.autocommands")