feat: add treesitter keybindings

This commit is contained in:
n3oney 2023-05-03 00:15:05 +02:00
parent 201a337a0d
commit 320cb8007c
No known key found for this signature in database
GPG key ID: C786693DE727850E
2 changed files with 30 additions and 17 deletions

View file

@ -1,5 +1,4 @@
{
pkgs,
config,
lib,
...
@ -8,6 +7,11 @@ with lib;
with builtins; let
cfg = config.vim.treesitter;
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
self = import ./treesitter.nix {inherit lib;};
mappingDefinitions = self.options.vim.treesitter.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in {
config = mkIf cfg.enable {
vim.startPlugins =
@ -16,6 +20,16 @@ in {
vim.autocomplete.sources = {"treesitter" = "[Treesitter]";};
# For some reason, using mkSetLuaBinding and putting the lua code does not work. It just selects the whole file.
# This works though, and if it ain't broke, don't fix it.
vim.maps.normal = mkSetBinding mappings.incrementalSelection.init ":lua require('nvim-treesitter.incremental_selection').init_selection()<CR>";
vim.maps.visualOnly = mkMerge [
(mkSetBinding mappings.incrementalSelection.incrementByNode ":lua require('nvim-treesitter.incremental_selection').node_incremental()<CR>")
(mkSetBinding mappings.incrementalSelection.incrementByScope ":lua require('nvim-treesitter.incremental_selection').scope_incremental()<CR>")
(mkSetBinding mappings.incrementalSelection.decrementByNode ":lua require('nvim-treesitter.incremental_selection').node_decremental()<CR>")
];
# For some reason treesitter highlighting does not work on start if this is set before syntax on
vim.configRC.treesitter-fold = mkIf cfg.fold (nvim.dag.entryBefore ["basic"] ''
set foldmethod=expr
@ -36,10 +50,10 @@ in {
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
init_selection = false,
node_incremental = false,
scope_incremental = false,
node_decremental = false,
},
},
}

View file

@ -1,14 +1,5 @@
{
pkgs,
config,
lib,
...
}:
with lib;
with builtins; let
cfg = config.vim.treesitter;
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
in {
{lib, ...}:
with lib; {
options.vim.treesitter = {
enable = mkEnableOption "treesitter, also enabled automatically through language options";
@ -16,13 +7,21 @@ in {
autotagHtml = mkEnableOption "autoclose and rename html tag";
mappings = {
incrementalSelection = {
init = mkMappingOption "Init selection [treesitter]" "gnn";
incrementByNode = mkMappingOption "Increment selection by node [treesitter]" "grn";
incrementByScope = mkMappingOption "Increment selection by scope [treesitter]" "grc";
decrementByNode = mkMappingOption "Decrement selection by node [treesitter]" "grm";
};
};
grammars = mkOption {
type = with types; listOf package;
default = [];
description = nvim.nmd.asciiDoc ''
List of treesitter grammars to install. For supported languages
use the `vim.language.<lang>.treesitter` option
'';
};
};