From cdeb64a7e4a0d437830739d01cc871a0f4dab555 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Wed, 6 Nov 2024 20:43:59 +0100 Subject: [PATCH] nvim: mini + tree-sitter setup --- home/common/nvim/default.nix | 46 ++++++- home/common/nvim/mini.lua | 257 +++++++++++++++++++---------------- 2 files changed, 181 insertions(+), 122 deletions(-) diff --git a/home/common/nvim/default.nix b/home/common/nvim/default.nix index 9f1679a..3f61773 100644 --- a/home/common/nvim/default.nix +++ b/home/common/nvim/default.nix @@ -25,18 +25,39 @@ nodePackages.typescript-language-server nodePackages.bash-language-server rust-analyzer + rustfmt shellcheck shfmt stylua tree-sitter tree-sitter-grammars.tree-sitter-bash - tree-sitter-grammars.tree-sitter-yaml + tree-sitter-grammars.tree-sitter-c + tree-sitter-grammars.tree-sitter-comment + tree-sitter-grammars.tree-sitter-css + tree-sitter-grammars.tree-sitter-cue + tree-sitter-grammars.tree-sitter-fish + tree-sitter-grammars.tree-sitter-gdscript tree-sitter-grammars.tree-sitter-go - tree-sitter-grammars.tree-sitter-markdown - tree-sitter-grammars.tree-sitter-lua + tree-sitter-grammars.tree-sitter-gomod + tree-sitter-grammars.tree-sitter-hcl tree-sitter-grammars.tree-sitter-html - tree-sitter-grammars.tree-sitter-vim + tree-sitter-grammars.tree-sitter-javascript + tree-sitter-grammars.tree-sitter-json + tree-sitter-grammars.tree-sitter-lua + tree-sitter-grammars.tree-sitter-markdown tree-sitter-grammars.tree-sitter-nix + tree-sitter-grammars.tree-sitter-proto + tree-sitter-grammars.tree-sitter-rego + tree-sitter-grammars.tree-sitter-rust + tree-sitter-grammars.tree-sitter-scss + tree-sitter-grammars.tree-sitter-sql + tree-sitter-grammars.tree-sitter-svelte + tree-sitter-grammars.tree-sitter-toml + tree-sitter-grammars.tree-sitter-tsx + tree-sitter-grammars.tree-sitter-typescript + tree-sitter-grammars.tree-sitter-vim + tree-sitter-grammars.tree-sitter-yaml + tree-sitter-grammars.tree-sitter-zig vscode-langservers-extracted ]; @@ -45,6 +66,7 @@ go-nvim rustaceanvim targets-vim + ts-comments-nvim { plugin = pkgs.vimUtils.buildVimPlugin { @@ -85,12 +107,26 @@ } { - plugin = nvim-treesitter.withAllGrammars; # Treesitter + plugin = nvim-treesitter-context; + type = "lua"; + config = '' + vim.keymap.set('n', 'ut', "TSContextToggle", {noremap = true, silent = true, desc = "TS Context"}) + ''; + } + + { + plugin = nvim-treesitter.withAllGrammars; type = "lua"; config = '' require'nvim-treesitter.configs'.setup { highlight = { enable = true, }, indent = { enable = true }, + textobjects = { + select = { + enable = true, + lookahead = true, + }, + }, } ''; } diff --git a/home/common/nvim/mini.lua b/home/common/nvim/mini.lua index 02b594b..379794f 100644 --- a/home/common/nvim/mini.lua +++ b/home/common/nvim/mini.lua @@ -1,133 +1,156 @@ - local opts = function(label) - return {noremap = true, silent = true, desc = label} - end - require('mini.ai').setup() - require('mini.align').setup() - require('mini.bracketed').setup() - require('mini.completion').setup() - require('mini.diff').setup() - require('mini.extra').setup() - require('mini.icons').setup() - require('mini.jump').setup() - require('mini.surround').setup() - require('mini.splitjoin').setup() +local opts = function(label) + return { noremap = true, silent = true, desc = label } +end +require('mini.ai').setup() +require('mini.align').setup() +require('mini.bracketed').setup() +require('mini.comment').setup() +require('mini.completion').setup() +require('mini.diff').setup() +require('mini.extra').setup() +require('mini.icons').setup() +require('mini.jump').setup() +require('mini.surround').setup() +require('mini.splitjoin').setup() +require('mini.trailspace').setup() - -- require('mini.bufremove').setup() - local bufremove = require('mini.bufremove') - bufremove.setup() - vim.keymap.set('n', 'bd', bufremove.delete, opts("Delete")) +local bufremove = require('mini.bufremove') +bufremove.setup() +vim.keymap.set('n', 'bd', bufremove.delete, opts("Delete")) - require('mini.files').setup() - local oil_style = function() - if not MiniFiles.close() then - MiniFiles.open(vim.api.nvim_buf_get_name(0)) - MiniFiles.reveal_cwd() - end - end - vim.keymap.set('n', '-', oil_style, opts("File Explorer")); +require('mini.cursorword').setup({ + delay = 800 +}) - local hipatterns = require('mini.hipatterns') - hipatterns.setup({ -- highlight strings and colors - highlighters = { - -- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE' - fixme = { pattern = '%f[%w]()FIXME()%f[%W]', group = 'MiniHipatternsFixme' }, - hack = { pattern = '%f[%w]()HACK()%f[%W]', group = 'MiniHipatternsHack' }, - todo = { pattern = '%f[%w]()TODO()%f[%W]', group = 'MiniHipatternsTodo' }, - note = { pattern = '%f[%w]()NOTE()%f[%W]', group = 'MiniHipatternsNote' }, +local hipatterns = require('mini.hipatterns') +hipatterns.setup({ -- highlight strings and colors + highlighters = { + -- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE' + fixme = { pattern = '%f[%w]()FIXME()%f[%W]', group = 'MiniHipatternsFixme' }, + hack = { pattern = '%f[%w]()HACK()%f[%W]', group = 'MiniHipatternsHack' }, + todo = { pattern = '%f[%w]()TODO()%f[%W]', group = 'MiniHipatternsTodo' }, + note = { pattern = '%f[%w]()NOTE()%f[%W]', group = 'MiniHipatternsNote' }, - -- Highlight hex color strings (`#rrggbb`) using that color - hex_color = hipatterns.gen_highlighter.hex_color(), - } - }) + -- Highlight hex color strings (`#rrggbb`) using that color + hex_color = hipatterns.gen_highlighter.hex_color(), + } +}) - require('mini.jump2d').setup({ - mappings = { - start_jumping = 'gw' - } - }) +local indentscope = require('mini.indentscope') +indentscope.setup({ + draw = { + delay = 10, + animation = indentscope.gen_animation.none(), + }, + symbol = '│', +}) - require('mini.pick').setup({ - mappings = { - move_down = '' - }, - options = { - use_cache = true - } - }) - MiniPick.registry.files_root = function(local_opts) - local root_patterns = { ".jj", ".git" } - local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1]) - local opts = { source = { cwd = root_dir, tool = "ripgrep"} } - local_opts.cwd = root_dir - local_opts.tool = "rg" - return MiniPick.builtin.files(local_opts, opts) - end - MiniPick.registry.grep_live_root = function(local_opts) - local root_patterns = { ".jj", ".git" } - local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1]) - local opts = { source = { cwd = root_dir } } - local_opts.cwd = root_dir - return MiniPick.builtin.grep_live(local_opts, opts) - end - vim.keymap.set('n', '/', "Pick grep_live_root", opts("Live Grep")) - vim.keymap.set('n', 'F', "Pick files", opts("Find in CWD")) - vim.keymap.set('n', 'ff', "Pick files_root", opts("Find")) - vim.keymap.set('n', 'fr', "Pick oldfiles", opts("Recent")) - vim.keymap.set('n', 'bb', "Pick buffers", opts("Switch")) - vim.keymap.set('n', 'd', "Pick diagnostics", opts("Diagnostics")) - vim.keymap.set('n', '', "Pick buffers include_current=false", opts("Buffers")) - vim.keymap.set('n', "'", "Pick resume", opts("Last Picker")) - vim.keymap.set('n', "g", "Pick git_commits", opts("Git Commits")) +require('mini.jump2d').setup({ + mappings = { + start_jumping = 'gw' + } +}) + +require('mini.pick').setup({ + mappings = { + move_down = '' + }, + options = { + use_cache = true + } +}) +MiniPick.registry.files_root = function(local_opts) + local root_patterns = { ".jj", ".git" } + local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1]) + local_opts.cwd = root_dir + local_opts.tool = "rg" + return MiniPick.builtin.files(local_opts, { source = { cwd = root_dir, tool = "ripgrep" } }) +end +MiniPick.registry.grep_live_root = function(local_opts) + local root_patterns = { ".jj", ".git" } + local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1]) + local_opts.cwd = root_dir + return MiniPick.builtin.grep_live(local_opts, { source = { cwd = root_dir } }) +end +vim.keymap.set('n', '/', "Pick grep_live_root", opts("Live Grep")) +vim.keymap.set('n', 'fF', "Pick files", opts("FindCWD")) +vim.keymap.set('n', 'ff', "Pick files_root", opts("Find")) +vim.keymap.set('n', 'fr', "Pick oldfiles", opts("Recent")) +vim.keymap.set('n', 'bb', "Pick buffers", opts("Switch")) +vim.keymap.set('n', 'd', "Pick diagnostics", opts("Diagnostics")) +vim.keymap.set('n', '', "Pick buffers include_current=false", opts("Buffers")) - local miniclue = require('mini.clue') - miniclue.setup({ -- cute prompts about bindings - triggers = { - { mode = 'n', keys = '' }, - { mode = 'x', keys = '' }, - { mode = 'n', keys = '' }, - { mode = 'x', keys = '' }, +local miniclue = require('mini.clue') +miniclue.setup({ -- cute prompts about bindings + triggers = { + { mode = 'n', keys = '' }, + { mode = 'x', keys = '' }, + { mode = 'n', keys = '' }, + { mode = 'x', keys = '' }, - -- Built-in completion - { mode = 'i', keys = '' }, + -- Built-in completion + { mode = 'i', keys = '' }, - -- `g` key - { mode = 'n', keys = 'g' }, - { mode = 'x', keys = 'g' }, + -- `g` key + { mode = 'n', keys = 'g' }, + { mode = 'x', keys = 'g' }, - -- Marks - { mode = 'n', keys = "'" }, - { mode = 'n', keys = '`' }, - { mode = 'x', keys = "'" }, - { mode = 'x', keys = '`' }, + -- Marks + { mode = 'n', keys = "'" }, + { mode = 'n', keys = '`' }, + { mode = 'x', keys = "'" }, + { mode = 'x', keys = '`' }, - -- Registers - { mode = 'n', keys = '"' }, - { mode = 'x', keys = '"' }, - { mode = 'i', keys = '' }, - { mode = 'c', keys = '' }, + -- Registers + { mode = 'n', keys = '"' }, + { mode = 'x', keys = '"' }, + { mode = 'i', keys = '' }, + { mode = 'c', keys = '' }, - -- Window commands - { mode = 'n', keys = '' }, + -- Window commands + { mode = 'n', keys = '' }, - -- `z` key - { mode = 'n', keys = 'z' }, - { mode = 'x', keys = 'z' }, + -- `z` key + { mode = 'n', keys = 'z' }, + { mode = 'x', keys = 'z' }, - -- Bracketed - { mode = 'n', keys = '[' }, - { mode = 'n', keys = ']' }, - }, - clues = { - miniclue.gen_clues.builtin_completion(), - miniclue.gen_clues.g(), - miniclue.gen_clues.marks(), - miniclue.gen_clues.registers(), - miniclue.gen_clues.windows(), - miniclue.gen_clues.z(), - }, - window = { - delay = 15, - } - }) + -- Bracketed + { mode = 'n', keys = '[' }, + { mode = 'n', keys = ']' }, + }, + clues = { + miniclue.gen_clues.builtin_completion(), + miniclue.gen_clues.g(), + miniclue.gen_clues.marks(), + miniclue.gen_clues.registers(), + miniclue.gen_clues.windows(), + miniclue.gen_clues.z(), + }, + window = { + delay = 15, + } +}) +local notify_win_config = function() + local has_statusline = vim.o.laststatus > 0 + local pad = vim.o.cmdheight + (has_statusline and 1 or 0) + return { anchor = 'SE', border = 'rounded', col = vim.o.columns, row = vim.o.lines - pad } +end +require('mini.notify').setup({ + window = { + config = notify_win_config, + winblend = 0, + }, +}) + +require('mini.starter').setup({ + header = + [[ ______ _ +(_____ \ _ (_) + _____) )___| |_ ____ ____ _ ____ +| ____/ _ | _)/ _ |/ _ | |/ _ | +| | ( ( | | |_( ( | ( ( | | ( ( | | +|_| \_||_|\___)_||_|\_|| |_|\_||_| + (_____|]] +})