diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-04-21 23:05:24 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-04-21 23:14:17 +0200 |
| commit | 7e7d4e7e21bbc28dad1ef0162b4891f290b5ad37 (patch) | |
| tree | d18437dc1381377aa267a42f5318856cc0df3281 /.config/nvim | |
| parent | f9e9fd8237ce0dfe41b39871a79c306afaa23544 (diff) | |
| download | dotfiles-7e7d4e7e21bbc28dad1ef0162b4891f290b5ad37.tar.gz dotfiles-7e7d4e7e21bbc28dad1ef0162b4891f290b5ad37.zip | |
Improved auto formatting
Diffstat (limited to '.config/nvim')
| -rw-r--r-- | .config/nvim/lua/user/mods.lua | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/.config/nvim/lua/user/mods.lua b/.config/nvim/lua/user/mods.lua index 704ffdf..1973868 100644 --- a/.config/nvim/lua/user/mods.lua +++ b/.config/nvim/lua/user/mods.lua @@ -31,20 +31,20 @@ end -- Format on save local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) require("null-ls").setup({ - -- you can reuse a shared lspconfig on_attach callback here - on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead - vim.lsp.buf.formatting_seq_sync() - end, - }) - end - end, + -- you can reuse a shared lspconfig on_attach callback here + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead + vim.lsp.buf.formatting_seq_sync() + end, + }) + end + end, }) @@ -73,7 +73,6 @@ function M.may_create_dir(dir) end end - -------------------------------------------------- --- Toggle cmp completion @@ -122,26 +121,24 @@ function M.add_pack(name) return status end - -------------------------------------------------- --- Toggle autopairs on/off (requires "windwp/nvim-autopairs") function M.Toggle_autopairs() - local ok, autopairs = pcall(require, "nvim-autopairs") - if ok then - if autopairs.state.disabled then - autopairs.enable() - print("autopairs on") - else - autopairs.disable() - print("autopairs off") - end - else - print("autopairs not available") - end + local ok, autopairs = pcall(require, "nvim-autopairs") + if ok then + if autopairs.state.disabled then + autopairs.enable() + print("autopairs on") + else + autopairs.disable() + print("autopairs off") + end + else + print("autopairs not available") + end end - -------------------------------------------------- --- Make vim-rooter message disappear after making it's changes @@ -199,6 +196,7 @@ function M.Set_git_env_vars() end end end + vim.cmd [[augroup my_git_env_vars]] vim.cmd [[ autocmd!]] vim.cmd [[ autocmd BufEnter * lua require('user.mods').Set_git_env_vars()]] @@ -207,4 +205,10 @@ vim.cmd [[augroup END]] -------------------------------------------------- +vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]] +--vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] + +-------------------------------------------------- + + return M |
