From d5618c9b5f9813d60e2c948e51a4c5bec8f6309c Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Sat, 9 Nov 2024 19:49:21 +0200 Subject: [PATCH] chore(config): tweaks to nvim config, autogroups --- config/nvim/lua/autogroups.lua | 17 ++++++ config/nvim/lua/plugins/conform.lua | 82 ++++++++++++++------------- config/nvim/lua/plugins/ufo.lua | 10 +++- config/nvim/lua/plugins/ui.lua | 62 +++++++++++++++----- config/nvim/lua/plugins/which-key.lua | 6 +- 5 files changed, 119 insertions(+), 58 deletions(-) diff --git a/config/nvim/lua/autogroups.lua b/config/nvim/lua/autogroups.lua index a7b77d7..046c7ff 100644 --- a/config/nvim/lua/autogroups.lua +++ b/config/nvim/lua/autogroups.lua @@ -51,4 +51,21 @@ autocmd('FileType', { callback = function(event) vim.bo[event.buf].buflisted = false end, }) +-- ── wrap and check for spell in text filetypes ────────────────────── +vim.api.nvim_create_autocmd('FileType', { + group = augroup('wrap_spell', { clear = true }), + pattern = { 'text', 'plaintex', 'typst', 'gitcommit', 'markdown' }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, +}) + +-- ── Fix conceallevel for json files ───────────────────────────────── +vim.api.nvim_create_autocmd({ 'FileType' }, { + group = augroup('json_conceal', { clear = true }), + pattern = { 'json', 'jsonc', 'json5' }, + callback = function() vim.opt_local.conceallevel = 0 end, +}) + -- vim: ts=2 sts=2 sw=2 et diff --git a/config/nvim/lua/plugins/conform.lua b/config/nvim/lua/plugins/conform.lua index e25edaa..48cb9b9 100644 --- a/config/nvim/lua/plugins/conform.lua +++ b/config/nvim/lua/plugins/conform.lua @@ -1,49 +1,45 @@ -- ── Formatting ────────────────────────────────────────────────────── -- Lightweight yet powerful formatter plugin for Neovim -- https://github.com/stevearc/conform.nvim -return { - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - config = function() - -- Select first conform formatter that is available - ---@param bufnr integer - ---@param ... string - ---@return string - local function first(bufnr, ...) - local conform = require 'conform' - for i = 1, select('#', ...) do - local formatter = select(i, ...) - if conform.get_formatter_info(formatter, bufnr).available then - return formatter - end - end - return select(1, ...) - end - require('conform').setup { +return { + { + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + opts = { -- Enable or disable logging - notify_on_error = true, + notify_on_error = false, -- Set the default formatter for all filetypes default_formatter = 'injected', -- Set the default formatter for all filetypes default_formatter_opts = { lsp_format = 'fallback', -- Set the default formatter for all filetypes - -- formatter = 'injected', + formatter = 'injected', -- Set the default formatter for all filetypes -- formatter_opts = {}, }, + -- The options you set here will be merged with the builtin formatters. + -- You can also define any custom formatters here. + formatters = { + injected = { options = { ignore_errors = true } }, + -- # Example of using dprint only when a dprint.json file is present + -- dprint = { + -- condition = function(ctx) + -- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1] + -- end, + -- }, + -- + -- # Example of using shfmt with extra args + -- shfmt = { + -- prepend_args = { "-i", "2", "-ci" }, + -- }, + }, formatters_by_ft = { - markdown = function(bufnr) - return { first(bufnr, 'prettierd', 'prettier'), 'injected' } - end, - javascript = function(bufnr) - return { first(bufnr, 'prettier', 'eslint'), 'injected' } - end, lua = { 'stylua' }, -- Conform will run multiple formatters sequentially - -- python = { 'isort', 'black', lsp_format = 'fallback' }, + go = { 'goimports', 'gofmt' }, -- You can customize some of the format options for the filetype (:help conform.format) -- rust = { 'rustfmt', lsp_format = 'fallback' }, }, @@ -59,9 +55,7 @@ return { return end -- Disable with a global or buffer-local variable - if - vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat - then + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then return end -- Disable autoformat for files in a certain path @@ -73,12 +67,20 @@ return { return { timeout_ms = 500, lsp_format = 'fallback' } end, - } - end, - init = function() - -- If you want the formatexpr, here is the place to set it - vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" - end, - - + }, + init = function() + -- If you want the formatexpr, here is the place to set it + vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + end, + }, + -- Automatically install formatters registered with conform.nvim via mason.nvim + -- https://github.com/zapling/mason-conform.nvim + { + 'zapling/mason-conform.nvim', + depends = { + 'stevearc/conform.nvim', + 'williamboman/mason.nvim', + }, + opts = {}, + }, } diff --git a/config/nvim/lua/plugins/ufo.lua b/config/nvim/lua/plugins/ufo.lua index a6480e7..920039c 100644 --- a/config/nvim/lua/plugins/ufo.lua +++ b/config/nvim/lua/plugins/ufo.lua @@ -41,7 +41,7 @@ return { config = function() local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.foldingRange = { - dynamicRegistration = false, + dynamicRegistration = true, lineFoldingOnly = true, } local language_servers = require('lspconfig').util.available_servers() -- or list servers manually like {'gopls', 'clangd'} @@ -84,7 +84,13 @@ return { ---@param width number The width of the window. ---@param truncate function Truncate function ---@return table - fold_virt_text_handler = function(virtText, lnum, endLnum, width, truncate) + fold_virt_text_handler = function( + virtText, + lnum, + endLnum, + width, + truncate + ) local newVirtText = {} local suffix = (' 󰁂 %d '):format(endLnum - lnum) local sufWidth = vim.fn.strdisplaywidth(suffix) diff --git a/config/nvim/lua/plugins/ui.lua b/config/nvim/lua/plugins/ui.lua index da9840f..1b561e3 100644 --- a/config/nvim/lua/plugins/ui.lua +++ b/config/nvim/lua/plugins/ui.lua @@ -27,9 +27,9 @@ return { }, }, - -- Extensible Neovim Scrollbar - -- https://github.com/petertriho/nvim-scrollbar - { 'petertriho/nvim-scrollbar', opts = {} }, + -- A neovim plugin that shows colorcolumn dynamically + -- https://github.com/Bekaboo/deadcolumn.nvim + { 'Bekaboo/deadcolumn.nvim' }, -- vim dashboard -- https://github.com/nvimdev/dashboard-nvim @@ -110,25 +110,60 @@ return { { 'lukas-reineke/indent-blankline.nvim', main = 'ibl', - config = function() - require('ibl').setup { - indent = { - char = '│', + opts = { + scope = { show_start = false, show_end = false }, + indent = { + char = '│', + tab_char = '│', + }, + exclude = { + filetypes = { + 'Trouble', + 'alpha', + 'dashboard', + 'help', + 'lazy', + 'lazyterm', + 'mason', + 'neo-tree', + 'notify', + 'terminal', + 'toggleterm', + 'trouble', }, - exclude = { - filetypes = { 'terminal', 'dashboard' }, - buftypes = { 'dashboard' }, - }, - } + buftypes = { 'dashboard' }, + }, + }, + }, + + -- icons + { + 'echasnovski/mini.icons', + opts = { + file = { + ['.keep'] = { glyph = '󰊢', hl = 'MiniIconsGrey' }, + ['devcontainer.json'] = { glyph = '', hl = 'MiniIconsAzure' }, + }, + filetype = { + dotenv = { glyph = '', hl = 'MiniIconsYellow' }, + }, + }, + init = function() + package.preload['nvim-web-devicons'] = function() + require('mini.icons').mock_nvim_web_devicons() + return package.loaded['nvim-web-devicons'] + end end, }, + -- ui components + { 'MunifTanjim/nui.nvim', lazy = true }, + -- Git integration for buffers -- https://github.com/lewis6991/gitsigns.nvim { 'lewis6991/gitsigns.nvim', version = false, - lazy = false, opts = { signs = { add = { text = '+' }, @@ -174,6 +209,7 @@ return { 'TmuxNavigateRight', 'TmuxNavigatePrevious', }, + opts = {}, }, -- Cloak allows you to overlay *'s over defined patterns in defined files. diff --git a/config/nvim/lua/plugins/which-key.lua b/config/nvim/lua/plugins/which-key.lua index eeee1d3..0b139ca 100644 --- a/config/nvim/lua/plugins/which-key.lua +++ b/config/nvim/lua/plugins/which-key.lua @@ -141,8 +141,8 @@ return { { 'cf', 'lua require("conform").format({ async = true, lsp_fallback = true })', - mode = { 'n', 'v' }, - desc = 'Format buffer', + mode = {}, + desc = 'Format buffer with Conform', }, { 'ci', @@ -509,7 +509,7 @@ return { }, -- ── Old habits ────────────────────────────────────────────────────── - { '', 'w', desc = 'Save file' }, + { '', 'w!', desc = 'Save file' }, -- ── Text manipulation in visual mode ──────────────────────────────── {