diff --git a/nvim/.config/nvim/lua/plugins/base.lua b/nvim/.config/nvim/lua/plugins/base.lua index 7c7e190..cc70347 100644 --- a/nvim/.config/nvim/lua/plugins/base.lua +++ b/nvim/.config/nvim/lua/plugins/base.lua @@ -210,8 +210,45 @@ return { "echasnovski/mini.nvim", event = { "InsertEnter", "VeryLazy" }, config = function() - -- manually create lazy loading scenarios - require("mini.ai").setup() + local ai = require("mini.ai") + local function ai_buffer(ai_type) + local start_line, end_line = 1, vim.fn.line("$") + if ai_type == "i" then + -- Skip first and last blank lines for `i` textobject + local first_nonblank, last_nonblank = vim.fn.nextnonblank(start_line), vim.fn.prevnonblank(end_line) + -- Do nothing for buffer with all blanks + if first_nonblank == 0 or last_nonblank == 0 then + return { from = { line = start_line, col = 1 } } + end + start_line, end_line = first_nonblank, last_nonblank + end + + local to_col = math.max(vim.fn.getline(end_line):len(), 1) + return { from = { line = start_line, col = 1 }, to = { line = end_line, col = to_col } } + end + ai.setup({ + custom_textobjects = { + c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }), -- class + d = { "%f[%d]%d+" }, -- digits + e = { -- single part of MultiCaseWords + { + "%u[%l%d]+%f[^%l%d]", + "%f[%S][%l%d]+%f[^%l%d]", + "%f[%P][%l%d]+%f[^%l%d]", + "^[%l%d]+%f[^%l%d]", + }, + "^().*()$", + }, + f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }), -- function + g = ai_buffer, -- buffer with or without whitespace + o = ai.gen_spec.treesitter({ -- current 'codeblock' + a = { "@block.outer", "@conditional.outer", "@loop.outer" }, + i = { "@block.inner", "@conditional.inner", "@loop.inner" }, + }), + u = ai.gen_spec.function_call(), -- function [u]sage + U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- function [U]sage of last dot element + }, + }) -- Align tables and other alignable things require("mini.align").setup({})