dotfiles/modules/programs/nvim/plugins/treesitter.nix

70 lines
2.1 KiB
Nix

{ pkgs, ... }:
with builtins;
{
config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [
(
let
parserDir = pkgs.symlinkJoin {
name = "tresitter-grammars-all";
paths = pkgs.vimPlugins.nvim-treesitter.withAllGrammars.dependencies;
};
in
{
plugin = nvim-treesitter;
event = [ "BufReadPost" "BufNewFile" ];
opts = {
sync_install = false;
auto_install = false;
highlight = {
enable = true;
};
textobjects =
{
select =
{
enable = true;
# Automatically jump forward to textobj, similar to targets.vim
lookahead = false;
keymaps = {
# You can use the capture groups defined in textobjects.scm
"af" = {
query = "@function.outer";
desc = "Select outer part of a function region";
};
"if" = {
query = "@function.inner";
desc = "Select inner part of a function region";
};
"ac" = {
query = "@class.outer";
desc = "Select outer part of a class region";
};
"ic" = {
query = "@class.inner";
desc = "Select inner part of a class region";
};
};
};
};
};
conf =
''
local final_opts = vim.tbl_deep_extend("keep", opts, { parser_install_dir = "${parserDir}" })
require('nvim-treesitter.configs').setup(final_opts)
'';
init = ''
vim.opt.runtimepath:prepend("${parserDir}")
'';
priority = 100;
dependencies = [
{ plugin = nvim-treesitter-textobjects; }
{ plugin = nvim-ts-context-commentstring; opts = { }; }
];
}
)
];
}