neovim: change keymaps, add oil

This commit is contained in:
Dmitriy Pleshevskiy 2024-11-25 23:29:07 +03:00
parent 7c34362bcc
commit 251dfd48fd
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
3 changed files with 132 additions and 14 deletions

View file

@ -299,11 +299,11 @@
]
},
"locked": {
"lastModified": 1731097096,
"narHash": "sha256-hMBcuTUJs1+zQ5nwTA06isLxk/vUd1r5qs95JRJ5L5E=",
"lastModified": 1732551945,
"narHash": "sha256-rMqeUBb2MoEwCT+P6Vn09gPMACf0qes3eW7PoWKKtlY=",
"ref": "refs/heads/main",
"rev": "20bf0c7e51e1e5ebf5f3754332f134a8ca0ce04c",
"revCount": 94,
"rev": "76eba1535350fa2835b12faf042d4a2ccdeee04e",
"revCount": 95,
"type": "git",
"url": "https://git.pleshevski.ru/pleshevskiy/nixeovim"
},

View file

@ -6,7 +6,9 @@ let
in
{
imports = [
"${modulesPath}/profiles/recommended.nix"
"${modulesPath}/profiles/base.nix"
"${modulesPath}/profiles/recommended-plugins.nix"
./keymaps.nix
./snippets.nix
./configs
./plugins
@ -34,9 +36,18 @@ in
# Enable fast navigation between windows
vim.keymap.set = map (k: { mode = "n"; lhs = ctrl k; rhs = "${ctrl "w"}${k}"; }) [ "h" "l" "j" "k" ];
plugin.nvim-web-devicons.enable = true;
plugin.oil-nvim = {
enable = true;
name = "oil";
setupSettings = {
columns = ["icon" "permissions" "size" "mtime"];
};
};
plugin.nvim-surround = {
enable = true;
setupSettings = {};
setupSettings = { };
};
plugin.nvim-treesitter-textobjects.enable = true;
@ -188,14 +199,17 @@ in
};
plugins.navigation = {
nvim-tree.settings = {
renderer = {
group_empty = true;
full_name = true;
};
tab.sync = {
open = true;
close = true;
nvim-tree = {
enable = false;
settings = {
renderer = {
group_empty = true;
full_name = true;
};
tab.sync = {
open = true;
close = true;
};
};
};
telescope.extensions.telescope-live-grep-args-nvim.settings = {

104
neovim/keymaps.nix Normal file
View file

@ -0,0 +1,104 @@
{ config, lib, ... }:
with lib.nix2lua;
let
inherit (lib.mod) space cmd leader localLeader ctrl;
gs = config.plugin.gitsigns-nvim.varName;
in
{
input = {
leader = lib.mkDefault ",";
localLeader = lib.mkDefault "'";
};
plugins.gitsigns.keymap.set = [
rec {
mode = "n";
lhs = "]h";
rhs = lambda0 (ifelse (var "vim.wo.diff")
(call1 "vim.cmd.normal" [ lhs (nf "bang" true) ])
(call1 "${gs}.nav_hunk" "next")
);
}
rec {
mode = "n";
lhs = "[h";
rhs = lambda0 (ifelse (var "vim.wo.diff")
(call1 "vim.cmd.normal" [ lhs (nf "bang" true) ])
(call1 "${gs}.nav_hunk" "prev")
);
}
{ mode = "n"; lhs = localLeader "gs"; rhs = raw "${gs}.stage_hunk"; }
{ mode = "n"; lhs = localLeader "gS"; rhs = raw "${gs}.stage_buffer"; }
{ mode = "n"; lhs = localLeader "gr"; rhs = raw "${gs}.reset_hunk"; }
{ mode = "n"; lhs = localLeader "gR"; rhs = raw "${gs}.reset_buffer"; }
{ mode = "n"; lhs = localLeader "gu"; rhs = raw "${gs}.undo_stage_hunk"; }
{ mode = "n"; lhs = localLeader "gp"; rhs = raw "${gs}.preview_hunk"; }
{ mode = "n"; lhs = localLeader "gb"; rhs = lambda0 (call "${gs}.blame_line" { full = true; }); }
{ mode = "n"; lhs = localLeader "gd"; rhs = raw "${gs}.diffthis"; }
{ mode = "n"; lhs = localLeader "gD"; rhs = lambda0 (call "${gs}.diffthis" "~"); }
{ mode = "n"; lhs = localLeader "gtb"; rhs = raw "${gs}.toggle_current_line_blame"; }
{ mode = "n"; lhs = localLeader "gtd"; rhs = raw "${gs}.toggle_deleted"; }
];
plugins.navigation.hop-nvim.keymap.set = { after, before }: [
{ lhs = space "c"; rhs = cmd "HopChar1"; }
{ lhs = space "w"; rhs = cmd "HopWord"; }
{ lhs = space "p"; rhs = cmd "HopPattern"; }
];
plugins.language-server.lspconfig.keymap.set = [
{ mode = "n"; lhs = "gD"; rhs = raw "vim.lsp.buf.declaration"; }
{ mode = "n"; lhs = "gd"; rhs = raw "vim.lsp.buf.definition"; }
{ mode = "n"; lhs = "K"; rhs = raw "vim.lsp.buf.hover"; }
{ mode = "n"; lhs = "gi"; rhs = raw "vim.lsp.buf.implementation"; }
{ mode = "n"; lhs = "gr"; rhs = raw "vim.lsp.buf.references"; }
{ mode = "n"; lhs = "gy"; rhs = raw "vim.lsp.buf.type_definition"; }
{ mode = "n"; lhs = localLeader "sh"; rhs = raw "vim.lsp.buf.signature_help"; }
{ mode = "n"; lhs = localLeader "n"; rhs = raw "vim.lsp.buf.rename"; }
{ mode = [ "n" "v" ]; lhs = localLeader "a"; rhs = raw "vim.lsp.buf.code_action"; }
];
vim.keymap.set = lib.optionals config.plugins.language-server.lspconfig.enable [
{ mode = "n"; lhs = localLeader "df"; rhs = raw "vim.diagnostic.open_float"; }
{ mode = "n"; lhs = "[d"; rhs = raw "vim.diagnostic.goto_prev"; }
{ mode = "n"; lhs = "]d"; rhs = raw "vim.diagnostic.goto_next"; }
{ mode = "n"; lhs = localLeader "dl"; rhs = raw "vim.diagnostic.setloclist"; }
] ++ lib.optionals config.plugins.navigation.telescope.enable (
[
{ mode = "n"; lhs = space "f"; rhs = cmd "Telescope find_files"; }
{ mode = "n"; lhs = space "b"; rhs = cmd "Telescope buffers"; }
{ mode = "n"; lhs = space "?"; rhs = cmd "Telescope help_tags"; }
] ++ lib.optionals (config.plugins.navigation.telescope.extensions ? telescope-live-grep-args-nvim) [
{
mode = "n";
lhs = space "g";
rhs = lambda0 (pipe [
config.plugin.telescope-nvim.var
"extensions"
"live_grep_args"
(call0 "live_grep_args")
]);
}
]
) ++ lib.optionals config.plugins.snippet.luasnip.enable (
let
ls = pipe1 config.plugin.luasnip.var;
jump = dir: (if' (ls (call "locally_jumpable" dir)) (ls (call "jump" dir)));
in
[
{ mode = "i"; lhs = ctrl "K"; rhs = lambda0 (ls (call0 "expand")); silent = true; }
{ mode = [ "i" "s" ]; lhs = ctrl "L"; rhs = lambda0 (jump 1); silent = true; }
{ mode = [ "i" "s" ]; lhs = ctrl "H"; rhs = lambda0 (jump (-1)); silent = true; }
{
mode = [ "i" "s" ];
lhs = ctrl "E";
rhs = lambda0 (if' (ls (call0 "choice_active")) (ls (call "change_choice" 1)));
silent = true;
}
]
) ++ lib.optionals config.plugin.oil-nvim.enable [
{ mode = "n"; lhs = "-"; rhs = cmd "Oil"; }
];
}