From 356686202df175e9e61acce41ec8190422a959b8 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sun, 8 Dec 2024 11:59:54 -0800 Subject: [PATCH] feat: nvim-treesitter --- nix/neovim-overlay.nix | 33 +++++++++++ nvim/lua/plugins/treesitter/init.lua | 5 ++ .../plugins/treesitter/nvim-treesitter.lua | 55 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 nvim/lua/plugins/treesitter/init.lua create mode 100644 nvim/lua/plugins/treesitter/nvim-treesitter.lua diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index f1b22a7..add07f5 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -55,6 +55,39 @@ with final.pkgs.lib; let flash-nvim which-key-nvim gitsigns-nvim + + # Treesitter + (nvim-treesitter.withPlugins ( + plugins: + with plugins; [ + bash + diff + html + gitignore + javascript + jsdoc + json + jsonc + just + lua + luadoc + markdown + markdown_inline + nix + just + printf + python + query + regex + toml + tsx + typescript + vim + vimdoc + xml + yaml + ] + )) ]; extraPackages = with pkgs; [ diff --git a/nvim/lua/plugins/treesitter/init.lua b/nvim/lua/plugins/treesitter/init.lua new file mode 100644 index 0000000..1470c19 --- /dev/null +++ b/nvim/lua/plugins/treesitter/init.lua @@ -0,0 +1,5 @@ +local req = MarleyVim.local_require('plugins.treesitter') + +return { + req('nvim-treesitter'), +} diff --git a/nvim/lua/plugins/treesitter/nvim-treesitter.lua b/nvim/lua/plugins/treesitter/nvim-treesitter.lua new file mode 100644 index 0000000..6a23e8c --- /dev/null +++ b/nvim/lua/plugins/treesitter/nvim-treesitter.lua @@ -0,0 +1,55 @@ +return { + event = { 'BufReadPost', 'BufWritePost', 'BufNewFile', 'DeferredUIEnter' }, + keys = { + { '', desc = 'increment selection' }, + { '', desc = 'decrement selection', mode = 'x' }, + }, + before = function() + require('lz.n').trigger_load('which-key.nvim') + end, + after = function() + require('nvim-treesitter.configs').setup({ + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = false, + node_decremental = '', + }, + }, + textobjects = { + move = { + enable = true, + goto_next_start = { + [']f'] = '@function.outer', + [']c'] = '@class.outer', + [']a'] = '@parameter.inner', + }, + goto_next_end = { + [']F'] = '@function.outer', + [']C'] = '@class.outer', + [']A'] = '@parameter.inner', + }, + goto_previous_start = { + ['[f'] = '@function.outer', + ['[c'] = '@class.outer', + ['[a'] = '@parameter.inner', + }, + goto_previous_end = { + ['[F'] = '@function.outer', + ['[C'] = '@class.outer', + ['[A'] = '@parameter.inner', + }, + }, + }, + }) + + require('which-key').add({ + { '', desc = 'decrement selection', mode = 'x' }, + { '', desc = 'increment selection', mode = { 'x', 'n' } }, + }) + end, +}