From 0712e89f57ae108db0ff40892d6124814c874f37 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Fri, 2 May 2025 19:52:17 +0300 Subject: Refactored extra code into autocmds, user commands and extra --- .config/nvim/lua/usrcmds.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .config/nvim/lua/usrcmds.lua (limited to '.config/nvim/lua/usrcmds.lua') diff --git a/.config/nvim/lua/usrcmds.lua b/.config/nvim/lua/usrcmds.lua new file mode 100644 index 0000000..047f0a8 --- /dev/null +++ b/.config/nvim/lua/usrcmds.lua @@ -0,0 +1,41 @@ +vim.api.nvim_create_user_command('Format', function(args) + local range = nil + if args.count ~= -1 then + local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] + range = { + start = { args.line1, 0 }, + ['end'] = { args.line2, end_line:len() }, + } + end + require('conform').format({ async = true, lsp_format = 'fallback', range = range }) +end, { range = true }) + +vim.api.nvim_create_user_command('FormatToggle', function(args) + local is_global = not args.bang + if is_global then + vim.g.disable_autoformat = not vim.g.disable_autoformat + if vim.g.disable_autoformat then + Snacks.notify.info('Autoformat on save disabled globally', { title = 'test' }) + else + Snacks.notify.info('Autoformat on save enabled globally') + end + else + vim.b.disable_autoformat = not vim.b.disable_autoformat + if vim.b.disable_autoformat then + Snacks.notify.info('Autoformat on save disabled for this buffer') + else + Snacks.notify.info('Autoformat on save enabled for this buffer') + end + end +end, { + desc = 'Toggle autoformat on save', + bang = true, +}) + +vim.api.nvim_create_user_command('LspInfo', function() + vim.cmd('checkhealth vim.lsp') +end, {}) + +vim.api.nvim_create_user_command('LspLog', function() + vim.cmd('tabedit ' .. vim.lsp.get_log_path()) +end, {}) -- cgit v1.3.1