neovim: add incremental selection

This commit is contained in:
Dmitriy Pleshevskiy 2024-11-24 15:47:42 +03:00
parent 4ef6aacaed
commit 04c505a149
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2

View file

@ -1,7 +1,7 @@
{ modulesPath, lib, pkgs, ... }: { modulesPath, lib, pkgs, ... }:
let let
inherit (lib.mod) ctrl; inherit (lib.mod) ctrl localLeader Bs;
inherit (lib.nix2lua) pipe1 require call0 nf var; inherit (lib.nix2lua) pipe1 require call0 nf var;
in in
{ {
@ -34,6 +34,8 @@ in
# Enable fast navigation between windows # Enable fast navigation between windows
vim.keymap.set = map (k: { mode = "n"; lhs = ctrl k; rhs = "${ctrl "w"}${k}"; }) [ "h" "l" "j" "k" ]; vim.keymap.set = map (k: { mode = "n"; lhs = ctrl k; rhs = "${ctrl "w"}${k}"; }) [ "h" "l" "j" "k" ];
plugin.nvim-treesitter-textobjects.enable = true;
plugins.style.nvim-treesitter = { plugins.style.nvim-treesitter = {
extraGrammars = { extraGrammars = {
tree-sitter-d2 = rec { tree-sitter-d2 = rec {
@ -65,6 +67,114 @@ in
(#set! injection.language "${lang}") (#set! injection.language "${lang}")
) )
''; '';
settings = {
incremental_selection = {
enable = true;
keymaps = {
init_selection = ctrl "s";
node_incremental = ctrl "s";
scope_incremental = "grs";
node_decremental = Bs;
};
};
textobjects =
let
inner = v: "${v}.inner";
outer = v: "${v}.outer";
any' = v: "${v}.*";
# 1 @assignment.inner
# 2 @assignment.lhs
# 3 @assignment.outer
# 4 @assignment.rhs
ass = "@assignment";
#-5 @attribute.inner
#-6 @attribute.outer
att = "@attribute";
# 7 @block.inner
# 8 @block.outer
blo = "@block";
# 9 @call.inner
# 10 @call.outer
cal = "@call";
# 11 @class.inner
# 12 @class.outer
cla = "@class";
#-13 @comment.inner
# 14 @comment.outer
com = "@comment";
# 15 @conditional.inner
# 16 @conditional.outer
con = "@conditional";
#-17 @frame.inner
#-18 @frame.outer
fra = "@frame";
# 19 @function.inner
# 20 @function.outer
fun = "@function";
# 21 @loop.inner
# 22 @loop.outer
loo = "@loop";
# 23 @number.inner
num = "@number";
# 24 @parameter.inner
# 25 @parameter.outer
par = "@parameter";
# 26 @regex.inner
# 27 @regex.outer
reg = "@regex";
# 28 @return.inner
# 29 @return.outer
ret = "@return";
#-30 @scopename.inner
# 31 @statement.outer
sta = "@statement";
in
{
select = {
enable = true;
lookahead = true;
selection_modes = {
"@parameter.outer" = "v"; # charwise
"@function.outer" = "V"; # linewise
"@class.outer" = ctrl "v"; # blockwise
};
};
swap = {
enable = true;
swap_next = {
"${localLeader "a"}" = {
query = [
(inner par)
(outer fun)
];
};
"${localLeader "f"}" = any' fun;
};
swap_previous = {
"${localLeader "A"}" = {
query = [
(inner par)
(outer fun)
];
};
"${localLeader "F"}" = any' fun;
};
};
move = {
enable = true;
set_jumps = true;
goto_next = {
"]q" = { query = map outer [ cla fun con loo ]; };
};
goto_previous = {
"[q" = { query = map outer [ cla fun con loo ]; };
};
};
};
};
}; };
plugins.style.neoformat.autoformat = { plugins.style.neoformat.autoformat = {