feat: add nvimtree keybindings

This commit is contained in:
n3oney 2023-04-12 17:17:23 +02:00
parent 15185f9ad6
commit f1f0144c62
No known key found for this signature in database
GPG key ID: C786693DE727850E
3 changed files with 36 additions and 14 deletions

View file

@ -1,30 +1,29 @@
{ {
config, config,
lib, lib,
pkgs,
... ...
}: }:
with lib; with lib;
with builtins; let with builtins; let
cfg = config.vim.filetree.nvimTreeLua; cfg = config.vim.filetree.nvimTreeLua;
self = import ./nvimtree-lua.nix {
inherit pkgs;
lib = lib;
};
mappings = self.options.vim.filetree.nvimTreeLua.mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["nvim-tree-lua"]; vim.startPlugins = ["nvim-tree-lua"];
# vim.nnoremap = { vim.maps.normal = mkMerge [
# "<C-n>" = ":NvimTreeToggle<CR>"; (mkBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
# "<leader>tr" = ":NvimTreeRefresh<CR>"; (mkBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
# "<leader>tg" = ":NvimTreeFindFile<CR>"; (mkBinding cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
# "<leader>tf" = ":NvimTreeFocus<CR>"; (mkBinding cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
# }; ];
vim.luaConfigRC.nvimtreelua = nvim.dag.entryAnywhere '' vim.luaConfigRC.nvimtreelua = nvim.dag.entryAnywhere ''
local opts = { silent = true, noremap = true }
vim.api.nvim_set_keymap("n", "<C-n>", ":NvimTreeToggle<cr>", opts)
vim.api.nvim_set_keymap("n", "<leader>tr", ":NvimTreeRefresh<cr>", opts)
vim.api.nvim_set_keymap("n", "<leader>tg", ":NvimTreeFindFile<cr>", opts)
vim.api.nvim_set_keymap("n", "<leader>tf", ":NvimTreeFocus<cr>", opts)
local function open_nvim_tree(data) local function open_nvim_tree(data)
local IGNORED_FT = { local IGNORED_FT = {
"markdown", "markdown",

View file

@ -1,6 +1,5 @@
{ {
pkgs, pkgs,
config,
lib, lib,
... ...
}: }:
@ -13,6 +12,29 @@ with builtins; {
description = "Enable nvim-tree-lua"; description = "Enable nvim-tree-lua";
}; };
mappings = {
toggle = mkOption {
type = types.nullOr types.str;
default = "<C-n>";
description = "Toggle NvimTree";
};
refresh = mkOption {
type = types.nullOr types.str;
default = "<leader>tr";
description = "Refresh NvimTree";
};
findFile = mkOption {
type = types.nullOr types.str;
default = "<leader>tg";
description = "Find file in NvimTree";
};
focus = mkOption {
type = types.nullOr types.str;
default = "<leader>tf";
description = "Focus NvimTree";
};
};
sortBy = mkOption { sortBy = mkOption {
default = "name"; default = "name";
description = "Sort by name or extension"; description = "Sort by name or extension";

View file

@ -88,6 +88,7 @@ in {
} }
${ ${
# TODO: This probably will need to be reworked for custom-keybinds
if config.vim.filetree.nvimTreeLua.enable if config.vim.filetree.nvimTreeLua.enable
then '' then ''
-- NvimTree -- NvimTree