refactored keybindings; added search and grep to nvim-tree

This commit is contained in:
Ellis Rahhal 2025-02-14 16:54:21 -08:00
parent e254433f2c
commit 0c6dab5310
9 changed files with 314 additions and 252 deletions

View file

@ -2,23 +2,6 @@
{ {
programs.nixvim = { programs.nixvim = {
keymaps = [ keymaps = [
# -----------------------------------------------------
# nvim-tree
# -----------------------------------------------------
## Go to current buffer's file in nvim-tree
{
mode = [ "n" ];
key = ",n";
action = ":NvimTreeFindFile<CR>";
}
## Toggle nvim-tree visibility
{
mode = [ "n" ];
key = ",m";
action = ":NvimTreeToggle<CR>";
}
# ----------------------------------------------------- # -----------------------------------------------------
# buffer manipulation # buffer manipulation
# ----------------------------------------------------- # -----------------------------------------------------
@ -53,207 +36,6 @@
action = ":tabnew split<CR>"; action = ":tabnew split<CR>";
options = { noremap = true; }; options = { noremap = true; };
} }
# -----------------------------------------------------
# Telescope
# -----------------------------------------------------
## Lists files in your current working directory, respects .gitignore
{
mode = [ "n" ];
key = "<leader>ff";
action = "<cmd>Telescope find_files<cr>";
options = { noremap = true; };
}
## Finds files by filename
{
mode = [ "n" ];
key = "<c-p>";
action = "<cmd>Telescope find_files<cr>";
# action = "<cmd>FzfLua files<cr>";
options = { noremap = true; };
}
# Search for a string in your current working directory and get results live as you type, respects .gitignore. (Requires ripgrep)
{
mode = [ "n" ];
key = "<leader>fg";
action = "<cmd>Telescope live_grep<cr>";
# action = "<cmd>FzfLua live_grep<cr>";
options = { noremap = true; };
}
# Search file contents
{
mode = [ "n" ];
key = "<c-s>";
action = "<cmd>Telescope live_grep<cr>";
# action = "<cmd>FzfLua live_grep<cr>";
options = { noremap = true; };
}
# Lists open buffers in current neovim instance
{
mode = [ "n" ];
key = "<leader>db";
action = "<cmd>Telescope buffers<cr>";
# action = "<cmd>FzfLua buffers<cr>";
options = { noremap = true; };
}
# Lists available help tags and opens a new window with the relevant help info on <cr>
{
mode = [ "n" ];
key = "<leader>fh";
action = "<cmd>Telescope help_tags<cr>";
# action = "<cmd>FzfLua helptags<cr>";
options = { noremap = true; };
}
# Lists manpage entries, opens them in a help window on <cr>
{
mode = [ "n" ];
key = "<leader>fm";
action = "<cmd>Telescope man_pages<cr>";
# action = "<cmd>FzfLua manpages<cr>";
options = { noremap = true; };
}
# Lists previously open files
{
mode = [ "n" ];
key = "<leader>fp";
action = "<cmd>Telescope oldfiles<cr>";
# action = "<cmd>FzfLua oldfiles<cr>";
options = { noremap = true; };
}
# Lists previously open files, Maps to ctrl-/
{
mode = [ "n" ];
key = "<c-_>";
action = "<cmd>Telescope oldfiles<cr>";
# action = "<cmd>FzfLua oldfiles<cr>";
options = { noremap = true; };
}
# Lists spelling suggestions for the current word under the cursor, replaces word with selected suggestion on <cr>
{
mode = [ "n" ];
key = "<leader>fs";
action = "<cmd>Telescope spell_suggest<cr>";
# action = "<cmd>FzfLua spell_suggest<cr>";
options = { noremap = true; };
}
# Lists LSP references for iword under the cursor
{
mode = [ "n" ];
key = "<leader>fr";
action = "<cmd>Telescope lsp_references<cr>";
# action = "<cmd>FzfLua lsp_references<cr>";
options = { noremap = true; };
}
# Lists LSP incoming calls for word under the cursor
{
mode = [ "n" ];
key = "<leader>fi";
action = "<cmd>Telescope lsp_incoming_calls<cr>";
# action = "<cmd>FzfLua lsp_incoming_calls<cr>";
options = { noremap = true; };
}
# Lists LSP outgoing calls for word under the cursor
{
mode = [ "n" ];
key = "<leader>fo";
action = "<cmd>Telescope lsp_outgoing_calls<cr>";
# action = "<cmd>FzfLua lsp_outgoing_calls<cr>";
options = { noremap = true; };
}
# Dynamically Lists LSP for all workspace symbols
{
mode = [ "n" ];
key = "<leader>fw";
action = "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>";
# action = "<cmd>FzfLua lsp_workspace_symbols<cr>";
options = { noremap = true; };
}
# Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
{
mode = [ "n" ];
key = "<leader>fd";
action = "<cmd>Telescope lsp_definitions<cr>";
options = { noremap = true; };
}
# Got to previous error
{
mode = [ "n" ];
key = "[d";
action = "<cmd>lua vim.diagnostic.goto_prev()<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = ",k";
action = "<cmd>lua vim.diagnostic.goto_prev()<CR>";
options = { noremap = true; silent = true; };
}
# Got to next error
{
mode = [ "n" ];
key = "]d";
action = "<cmd>lua vim.diagnostic.goto_next()<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = ",j";
action = "<cmd>lua vim.diagnostic.goto_next()<CR>";
options = { noremap = true; silent = true; };
}
## Other Telescope options:
## git_files search only files in git, respects .gitignore
## oldfiles previously opened files
## command_history
## search_history
## man_pages
## resume lists the results including multi-selections of the previous
## picker
# -----------------------------------------------------
# Diff
# -----------------------------------------------------
{
mode = [ "n" ];
key = ",d";
## @TODO: This doesn't work
action = ''
function()
if next(require('diffview.lib').views) == nil then
vim.cmd('DiffviewOpen origin')
else
vim.cmd('DiffviewClose')
end
end
'';
options = { noremap = true; };
}
# -----------------------------------------------------
# Bufferline
# -----------------------------------------------------
{
mode = [ "n" ];
key = "<A-h>";
action = ":BufferLineCyclePrev<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = "<A-l>";
action = ":BufferLineCycleNex<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = "<A-c>";
action = ":bdelete!<CR>";
options = { noremap = true; silent = true; };
}
]; ];
}; };
} }

View file

@ -34,7 +34,7 @@
cursorline = true; # Highlight line cursor sits on cursorline = true; # Highlight line cursor sits on
## @TODO Review these ## @TODO Review these
completeopt = ""; # Completion options completeopt = "menuone,noselect";
hidden = true; # Enable modified buffers in background hidden = true; # Enable modified buffers in background
inccommand = "nosplit"; # Show effects of a command incrementally inccommand = "nosplit"; # Show effects of a command incrementally
joinspaces = false; # No double spaces with join after a dot joinspaces = false; # No double spaces with join after a dot

View file

@ -1,6 +1,27 @@
{ ... }: { ... }:
{ {
programs.nixvim = { programs.nixvim = {
keymaps = [
{
mode = [ "n" ];
key = "<A-h>";
action = ":BufferLineCyclePrev<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = "<A-l>";
action = ":BufferLineCycleNex<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = "<A-c>";
action = ":bdelete!<CR>";
options = { noremap = true; silent = true; };
}
];
plugins.bufferline = { plugins.bufferline = {
enable = true; enable = true;
# extraOptions = { # extraOptions = {

View file

@ -81,8 +81,7 @@
}; };
completion = { completion = {
# completeopt = "menuone,noselect"; completeopt = "menuone,noselect";
completeopt = "";
}; };
autoEnableSources = true; autoEnableSources = true;
@ -117,7 +116,7 @@
"<C-b>" = "cmp.mapping.scroll_docs(-4)"; "<C-b>" = "cmp.mapping.scroll_docs(-4)";
"<C-f>" = "cmp.mapping.scroll_docs(4)"; "<C-f>" = "cmp.mapping.scroll_docs(4)";
"<C-c>" = "cmp.mapping.complete()"; "<C-c>" = "cmp.mapping.complete()";
"<Tab>" = "cmp.mapping.confirm({ select = true })"; "<Tab>" = "cmp.mapping.confirm({ select = false })";
# "<Tab>" = '' # "<Tab>" = ''
# cmp.mapping(function(fallback) # cmp.mapping(function(fallback)
# -- local context = require("cmp.config.context") # -- local context = require("cmp.config.context")

View file

@ -10,6 +10,7 @@
./cmp.nix ./cmp.nix
./codecompanion.nix ./codecompanion.nix
./copilot.nix ./copilot.nix
./diffview.nix
./fzf-lua.nix ./fzf-lua.nix
./lazydev.nix ./lazydev.nix
./lsp.nix ./lsp.nix
@ -21,11 +22,10 @@
programs.nixvim.plugins = { programs.nixvim.plugins = {
comment.enable = true; comment.enable = true;
diffview.enable = true;
fugitive.enable = true; fugitive.enable = true;
gitsigns.enable = true; gitsigns.enable = true;
indent-blankline.enable = true; indent-blankline.enable = true;
lightline.enable = true; lightline.enable = false;
lsp-signature.enable = true; lsp-signature.enable = true;
# config = '' # config = ''
# lua << EOF # lua << EOF

24
plugins/diffview.nix Normal file
View file

@ -0,0 +1,24 @@
{ ... }:
{
programs.nixvim = {
keymaps = [
{
mode = [ "n" ];
key = ",d";
## @TODO: This doesn't work
action = ''
function()
if next(require('diffview.lib').views) == nil then
vim.cmd('DiffviewOpen origin')
else
vim.cmd('DiffviewClose')
end
end
'';
options = { noremap = true; };
}
];
plugins.diffview.enable = true;
};
}

View file

@ -1,12 +1,46 @@
{ ... }: { ... }:
{ {
programs.nixvim = { programs.nixvim = {
extraFiles = {
"lua/treeutils.lua" = {
source = ./treeutils.lua;
};
};
keymaps = [
## Go to current buffer's file in nvim-tree
{
mode = [ "n" ];
key = ",n";
action = ":NvimTreeFindFile<CR>";
}
## Toggle nvim-tree visibility
{
mode = [ "n" ];
key = ",m";
action = ":NvimTreeToggle<CR>";
}
## Search current path
{
mode = [ "n" ];
key = "<c-f>";
action = "<cmd>lua require('treeutils').launch_find_files()<CR>";
options = { noremap = true; };
}
{
mode = [ "n" ];
key = "<c-g>";
action = "<cmd>lua require('treeutils').launch_live_grep()<CR>";
options = { noremap = true; };
}
];
plugins.nvim-tree = { plugins.nvim-tree = {
enable = true; enable = true;
extraOptions = {
actions = { actions = {
remove_file = { removeFile = {
close_window = false; closeWindow = false;
}; };
}; };
## Keep tree open if already open when opening a tab ## Keep tree open if already open when opening a tab
@ -20,7 +54,7 @@
width = 30; width = 30;
}; };
renderer = { renderer = {
group_empty = true; groupEmpty = true;
}; };
git = { git = {
enable = true; enable = true;
@ -29,5 +63,4 @@
}; };
}; };
}; };
};
} }

View file

@ -1,6 +1,163 @@
{ ... }: { ... }:
{ {
programs.nixvim = { programs.nixvim = {
keymaps = [
## Lists files in your current working directory, respects .gitignore
{
mode = [ "n" ];
key = "<leader>ff";
action = "<cmd>Telescope find_files<cr>";
options = { noremap = true; };
}
## Finds files by filename
{
mode = [ "n" ];
key = "<c-p>";
action = "<cmd>Telescope find_files<cr>";
# action = "<cmd>FzfLua files<cr>";
options = { noremap = true; };
}
# Search for a string in your current working directory and get results live as you type, respects .gitignore. (Requires ripgrep)
{
mode = [ "n" ];
key = "<leader>fg";
action = "<cmd>Telescope live_grep<cr>";
# action = "<cmd>FzfLua live_grep<cr>";
options = { noremap = true; };
}
# Search file contents
{
mode = [ "n" ];
key = "<c-s>";
action = "<cmd>Telescope live_grep<cr>";
# action = "<cmd>FzfLua live_grep<cr>";
options = { noremap = true; };
}
# Lists open buffers in current neovim instance
{
mode = [ "n" ];
key = "<leader>db";
action = "<cmd>Telescope buffers<cr>";
# action = "<cmd>FzfLua buffers<cr>";
options = { noremap = true; };
}
# Lists available help tags and opens a new window with the relevant help info on <cr>
{
mode = [ "n" ];
key = "<leader>fh";
action = "<cmd>Telescope help_tags<cr>";
# action = "<cmd>FzfLua helptags<cr>";
options = { noremap = true; };
}
# Lists manpage entries, opens them in a help window on <cr>
{
mode = [ "n" ];
key = "<leader>fm";
action = "<cmd>Telescope man_pages<cr>";
# action = "<cmd>FzfLua manpages<cr>";
options = { noremap = true; };
}
# Lists previously open files
{
mode = [ "n" ];
key = "<leader>fp";
action = "<cmd>Telescope oldfiles<cr>";
# action = "<cmd>FzfLua oldfiles<cr>";
options = { noremap = true; };
}
# Lists previously open files, Maps to ctrl-/
{
mode = [ "n" ];
key = "<c-_>";
action = "<cmd>Telescope oldfiles<cr>";
# action = "<cmd>FzfLua oldfiles<cr>";
options = { noremap = true; };
}
## Binding currently used by nvim-tree
## Lists spelling suggestions for the current word under the cursor, replaces word with selected suggestion on <cr>
# {
# mode = [ "n" ];
# key = "<leader>fs";
# action = "<cmd>Telescope spell_suggest<cr>";
# # action = "<cmd>FzfLua spell_suggest<cr>";
# options = { noremap = true; };
# }
# Lists LSP references for iword under the cursor
{
mode = [ "n" ];
key = "<leader>fr";
action = "<cmd>Telescope lsp_references<cr>";
# action = "<cmd>FzfLua lsp_references<cr>";
options = { noremap = true; };
}
# Lists LSP incoming calls for word under the cursor
{
mode = [ "n" ];
key = "<leader>fi";
action = "<cmd>Telescope lsp_incoming_calls<cr>";
# action = "<cmd>FzfLua lsp_incoming_calls<cr>";
options = { noremap = true; };
}
# Lists LSP outgoing calls for word under the cursor
{
mode = [ "n" ];
key = "<leader>fo";
action = "<cmd>Telescope lsp_outgoing_calls<cr>";
# action = "<cmd>FzfLua lsp_outgoing_calls<cr>";
options = { noremap = true; };
}
# Dynamically Lists LSP for all workspace symbols
{
mode = [ "n" ];
key = "<leader>fw";
action = "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>";
# action = "<cmd>FzfLua lsp_workspace_symbols<cr>";
options = { noremap = true; };
}
# Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
{
mode = [ "n" ];
key = "<leader>fd";
action = "<cmd>Telescope lsp_definitions<cr>";
options = { noremap = true; };
}
# Got to previous error
{
mode = [ "n" ];
key = "[d";
action = "<cmd>lua vim.diagnostic.goto_prev()<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = ",k";
action = "<cmd>lua vim.diagnostic.goto_prev()<CR>";
options = { noremap = true; silent = true; };
}
# Got to next error
{
mode = [ "n" ];
key = "]d";
action = "<cmd>lua vim.diagnostic.goto_next()<CR>";
options = { noremap = true; silent = true; };
}
{
mode = [ "n" ];
key = ",j";
action = "<cmd>lua vim.diagnostic.goto_next()<CR>";
options = { noremap = true; silent = true; };
}
## Other Telescope options:
## git_files search only files in git, respects .gitignore
## oldfiles previously opened files
## command_history
## search_history
## man_pages
## resume lists the results including multi-selections of the previous
## picker
];
plugins.telescope = { plugins.telescope = {
enable = true; enable = true;
extensions.ui-select.enable = true; extensions.ui-select.enable = true;
@ -16,14 +173,14 @@
"<c-e>" = { "<c-e>" = {
__raw = "require('telescope.actions').to_fuzzy_refine"; __raw = "require('telescope.actions').to_fuzzy_refine";
}; };
# "<c-o>" = { "<c-o>" = {
# __raw = "require('trouble.sources.telescope').open"; __raw = "require('trouble.sources.telescope').open";
# }; };
}; };
n = { n = {
# "<c-o>" = { "<c-o>" = {
# __raw = "require('trouble.sources.telescope').open"; __raw = "require('trouble.sources.telescope').open";
# }; };
}; };
}; };
}; };

46
plugins/treeutils.lua Normal file
View file

@ -0,0 +1,46 @@
local api = require("nvim-tree.api")
local openfile = require'nvim-tree.actions.node.open-file'
local actions = require'telescope.actions'
local action_state = require'telescope.actions.state'
local M = {}
local view_selection = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
local filename = selection.filename
if (filename == nil) then
filename = selection[1]
end
openfile.fn('preview', filename)
end)
return true
end
function M.launch_live_grep(opts)
return M.launch_telescope("live_grep", opts)
end
function M.launch_find_files(opts)
return M.launch_telescope("find_files", opts)
end
function M.launch_telescope(func_name, opts)
local telescope_status_ok, _ = pcall(require, "telescope")
if not telescope_status_ok then
return
end
local node = api.tree.get_node_under_cursor()
local is_folder = node.fs_stat and node.fs_stat.type == 'directory' or false
local basedir = is_folder and node.absolute_path or vim.fn.fnamemodify(node.absolute_path, ":h")
if (node.name == '..' and TreeExplorer ~= nil) then
basedir = TreeExplorer.cwd
end
opts = opts or {}
opts.cwd = basedir
opts.search_dirs = { basedir }
opts.attach_mappings = view_selection
return require("telescope.builtin")[func_name](opts)
end
return M