diff --git a/README.md b/README.md index 1157d64..721c82f 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,4 @@ -# Example `nixCats` Configuration +# Gabes `nixCats` Configuration -This directory contains an example of the suggested, idiomatic way to manage a neovim configuration using `nixCats`. It leverages [`lze`](https://github.com/BirdeeHub/lze) for lazy loading, although [`lz.n`](https://github.com/nvim-neorocks/lz.n) can be used instead to similar effect. It also includes a fallback mechanism using `paq` and `mason`, allowing you to load the directory without `nix` if needed. - -This setup serves as a strong starting point for a `Neovim` configuration—think of it as `kickstart.nvim`, but using `nixCats` **instead of** `lazy.nvim` and `mason`, rather than in addition to them. It also follows a modular approach, spreading the configuration across multiple files rather than consolidating everything into one. - -While this is not a "perfect" configuration, nor does it claim to be, it is **a well-structured, recommended way to use `nixCats`**. You are encouraged to customize it to fit your needs. `nixCats` itself is just the `nix`-based package manager, along with its associated [Lua plugin](https://nixcats.org/nixCats_plugin.html). - -## Why Use This Approach? - -Using `nixCats` in this way provides a **simpler, more transparent** experience compared to solutions like `lazy.nvim`, which hijack normal plugin loading. - -It leverages the normal packpath methods of loading plugins both at startup and lazily, allowing you to know what is going on behind the scenes. - -It avoids duplicating functionality between nix and other nvim based download managers, avoiding compatibility issues. - -You can still have a config that works without nix using this method if desired without undue difficulty. - -## Directory Structure - -This configuration primarily uses the following directory structure: - -- The `lua/` directory for core configurations. -- The `after/plugin/` directory to demonstrate compatibility. - -While this structure works well, you are encouraged to further modularize your setup by utilizing any of the runtime directories checked by Neovim: - -- `ftplugin/` for file-type-specific configurations. -- `plugin/` for global plugin configurations. -- Even `pack/*/{start,opt}/` work if you want to make a plugin inside your configuration. -- And so on... - -If you are unfamiliar with the above, refer to the [Neovim runtime path documentation](https://neovim.io/doc/user/options.html#'rtp'). - ---- - -> "Idiomatic" here means: -> -> - This configuration does **not** use `lazy.nvim`, and does not use `mason.nvim` when nix is involved. -> - `nixCats` is responsible for downloading all plugins. -> - Plugins are only loaded if their respective category is enabled. -> - The [Lua utilities template](https://github.com/BirdeeHub/nixCats-nvim/tree/main/templates/luaUtils/lua/nixCatsUtils) is used (see [`:h nixCats.luaUtils`](https://nixcats.org/nixCats_luaUtils.html)). -> - [`lze`](https://github.com/BirdeeHub/lze) or [`lz.n`](https://github.com/nvim-neorocks/lz.n) is used for lazy loading. +My preferred way of setting up neovim. This configuration has organically grown since 2016, +originally as a vimscript config, then as a lua config, then as a nixvim config, and finally a nix/lua hybrid. diff --git a/flake.nix b/flake.nix index 755dacc..1998d07 100644 --- a/flake.nix +++ b/flake.nix @@ -55,7 +55,15 @@ name, mkPlugin, ... - } @ packageDef: { + } @ packageDef: let + colorschemes = with pkgs.vimPlugins; { + "onedark" = onedark-nvim; + "catppuccin" = catppuccin-nvim; + "tokyonight" = tokyonight-nvim; + "nord" = nord-nvim; + "gruvbox" = gruvbox-nvim; + }; + in { # to define and use a new category, simply add a new list to a set here, # and later, you will include categoryname = true; in the set you # provide when you build the package using this builder function. @@ -72,15 +80,13 @@ ripgrep fd fzf - ]; - telescope = [ + lazygit zoxide ]; lsp = { rust = [ rust-analyzer cargo - ]; lua = [ lua-language-server @@ -117,7 +123,7 @@ todo-comments-nvim marks-nvim ]; - lsp={ + lsp = { rust = [ rustaceanvim ]; @@ -132,20 +138,11 @@ nvim-treesitter.withAllGrammars treesj ]; + allcolorschemes = colorschemes; # You can retreive information from the # packageDefinitions of the package this was packaged with. # :help nixCats.flake.outputs.categoryDefinitions.scheme - themer = with pkgs.vimPlugins; ( - builtins.getAttr (categories.colorscheme or "gruvbox") { - # Theme switcher without creating a new category - "onedark" = onedark-nvim; - "catppuccin" = catppuccin-nvim; - "tokyonight" = tokyonight-nvim; - "nord" = nord-nvim; - "gruvbox" = gruvbox-nvim; - "solarized" = solarized-nvim; - } - ); + themer = builtins.getAttr (categories.colorscheme or "gruvbox") colorschemes; # This is obviously a fairly basic usecase for this, but still nice. }; @@ -160,7 +157,6 @@ nvim-dap nvim-dap-ui nvim-dap-virtual-text - telescope-dap-nvim ]; }; lint = [ @@ -189,11 +185,6 @@ gitsigns-nvim nvim-surround leap-nvim - toggleterm-nvim - ]; - tree = [ - nvim-tree-lua - fidget-nvim ]; completion = [ luasnip @@ -203,12 +194,6 @@ blink-compat colorful-menu-nvim ]; - telescope = [ - telescope-ui-select-nvim - telescope-nvim - telescope-zoxide - telescope-file-browser-nvim - ]; extra = [ vim-startuptime ]; @@ -244,11 +229,9 @@ extraCats = { debug = [ ["debug" "default"] - ["telescope"] ]; lsp = [ ["lsp" "default"] - ["telescope"] ]; }; }; @@ -289,11 +272,9 @@ markdown = true; lsp = true; completion = true; - telescope = true; - tree = true; debug = true; lspDebugMode = false; - themer = true; + allcolorschemes = true; colorscheme = "gruvbox"; }; extra = { @@ -317,8 +298,6 @@ always = true; treesitter = true; completion = true; - telescope = true; - tree = true; lspDebugMode = false; themer = true; colorscheme = "gruvbox"; @@ -369,6 +348,8 @@ # and additionally output the original as default. packages = utils.mkAllWithDefault defaultPackage; + formatter = pkgs.alejandra; + # choose your package for devShell # and add whatever else you want in it. devShells = { diff --git a/lua/myLuaConf/LSPs/init.lua b/lua/myLuaConf/LSPs/init.lua index 2e6ce27..f7562ac 100644 --- a/lua/myLuaConf/LSPs/init.lua +++ b/lua/myLuaConf/LSPs/init.lua @@ -2,47 +2,71 @@ local catUtils = require('nixCatsUtils') if (catUtils.isNixCats and nixCats('lspDebugMode')) then vim.lsp.set_log_level("debug") end --- we create a function that lets us more easily define mappings specific --- for LSP related items. It sets the mode, buffer and description for us each time. -local lspmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end +local Snacks = require("snacks") - -- all of our LSP keybindings will be namespaced under l - keys = 'l' .. keys +vim.keymap.set("n", "lI", Snacks.picker.lsp_implementations, { desc = "Goto [I]mplementation" }) +vim.keymap.set("n", "lR", Snacks.picker.lsp_references, { desc = "Goto [R]eferences" }) +vim.keymap.set("n", "li", Snacks.picker.diagnostics, { desc = "D[i]agnostics" }) +vim.keymap.set("n", "ls", Snacks.picker.lsp_symbols, { desc = "Document [S]ymbols" }) +vim.keymap.set("n", "lws", Snacks.picker.lsp_workspace_symbols, { desc = "[W]orkspace [S]ymbols" }) - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) -end +vim.keymap.set("n", "lD", vim.lsp.buf.declaration, { desc = "Goto [D]eclaration" }) +vim.keymap.set("n", "lD", vim.lsp.buf.type_definition, { desc = "Type [D]efinition" }) +vim.keymap.set("n", "la", vim.lsp.buf.code_action, { desc = "[C]ode Action" }) +vim.keymap.set("n", "ld", vim.lsp.buf.definition, { desc = "Goto [D]efinition" }) +vim.keymap.set("n", "lf", vim.lsp.buf.format, { desc = "Format buffer" }) +vim.keymap.set("n", "lh", vim.lsp.buf.hover, { desc = "Hover Documentation" }) +vim.keymap.set("n", "lr", vim.lsp.buf.rename, { desc = "[R]ename" }) +vim.keymap.set("n", "ls", vim.lsp.buf.signature_help, { desc = "Signature Documentation" }) +vim.keymap.set("n", "lwa", vim.lsp.buf.add_workspace_folder, { desc = "[W]orkspace [A]dd Folder" }) +vim.keymap.set("n", "lwl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, + { desc = "[W]orkspace [L]ist Folders" }) +vim.keymap.set("n", "lwr", vim.lsp.buf.remove_workspace_folder, { desc = "[W]orkspace [R]emove Folder" }) -lspmap('r', vim.lsp.buf.rename, '[R]ename') -lspmap('a', vim.lsp.buf.code_action, '[C]ode Action') +-- setup lsp progress notifications +local progress = vim.defaulttable() +vim.api.nvim_create_autocmd("LspProgress", { + callback = function(ev) + local client = vim.lsp.get_client_by_id(ev.data.client_id) + local value = ev.data.params + .value --[[@as {percentage?: number, title?: string, message?: string, kind: "begin" | "report" | "end"}]] + if not client or type(value) ~= "table" then + return + end + local p = progress[client.id] -lspmap('d', vim.lsp.buf.definition, 'Goto [D]efinition') + for i = 1, #p + 1 do + if i == #p + 1 or p[i].token == ev.data.params.token then + p[i] = { + token = ev.data.params.token, + msg = ("[%3d%%] %s%s"):format( + value.kind == "end" and 100 or value.percentage or 100, + value.title or "", + value.message and (" **%s**"):format(value.message) or "" + ), + done = value.kind == "end", + } + break + end + end --- NOTE: why are these functions that call the telescope builtin? --- because otherwise they would load telescope eagerly when this is defined. --- due to us using the on_require handler to make sure it is available. -if nixCats('telescope') then - lspmap('R', function() require('telescope.builtin').lsp_references() end, 'Goto [R]eferences') - lspmap('I', function() require('telescope.builtin').lsp_implementations() end, 'Goto [I]mplementation') - lspmap('s', function() require('telescope.builtin').lsp_document_symbols() end, 'Document [S]ymbols') - lspmap('ws', function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, '[W]orkspace [S]ymbols') -end -- TODO: Investigate whether I can replace these with snacsk.nvim. + local msg = {} ---@type string[] + progress[client.id] = vim.tbl_filter(function(v) + return table.insert(msg, v.msg) or not v.done + end, p) -lspmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') -lspmap('h', vim.lsp.buf.hover, 'Hover Documentation') -lspmap('s', vim.lsp.buf.signature_help, 'Signature Documentation') -lspmap('f', vim.lsp.buf.format, 'Format buffer') - --- Lesser used LSP functionality -lspmap('D', vim.lsp.buf.declaration, 'Goto [D]eclaration') -lspmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') -lspmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') -lspmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) -end, '[W]orkspace [L]ist Folders') + local spinner = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" } + vim.notify(table.concat(msg, "\n"), "info", { + id = "lsp_progress", + title = client.name, + opts = function(notif) + notif.icon = #progress[client.id] == 0 and " " + or spinner[math.floor(vim.uv.hrtime() / (1e6 * 80)) % #spinner + 1] + end, + }) + end, +}) -- NOTE: This file uses lzextras.lsp handler https://github.com/BirdeeHub/lzextras?tab=readme-ov-file#lsp-handler -- This is a slightly more performant fallback function @@ -67,6 +91,8 @@ require('lze').load { "nvim-lspconfig", for_cat = "lsp", on_require = { "lspconfig" }, + -- rustaceanvim and zk-nvim dont require("lspconfig") + ft = { "markdown", "rust" }, -- NOTE: define a function for lsp, -- and it will run for all specs with type(plugin.lsp) == table -- when their filetype trigger loads them @@ -91,7 +117,7 @@ require('lze').load { { -- lazydev makes your lsp way better in your config without needing extra lsp configuration. "lazydev.nvim", - for_cat = "lua", + for_cat = "lsp.lua", cmd = { "LazyDev" }, ft = "lua", after = function(_) @@ -105,7 +131,7 @@ require('lze').load { { -- name of the lsp "lua_ls", - enabled = nixCats('lua'), + enabled = nixCats('lsp.lua'), -- provide a table containing filetypes, -- and then whatever your functions defined in the function type specs expect. -- in our case, it just expects the normal lspconfig setup options, @@ -130,6 +156,16 @@ require('lze').load { }, -- also these are regular specs and you can use before and after and all the other normal fields }, + { + "basedpyright", + enabled = nixCats("lsp.python"), + lsp = {}, + }, + { + "ruff", + enabled = nixCats("lsp.python"), + lsp = {}, + }, { "nixd", enabled = catUtils.isNixCats and nixCats('lsp.nix'), @@ -180,4 +216,23 @@ require('lze').load { "rustaceanvim", for_cat = "lsp.rust", }, + { + "zk-nvim", + for_cat = "lsp.zk", + ft = "markdown", + after = function() + require("zk").setup({ picker = "snacks_picker" }) + + vim.api.nvim_set_keymap("n", "zb", "ZkBackLinks", { desc = "Show [B]acklinkgs" }) + vim.api.nvim_set_keymap("n", "zl", "ZkLinks", { desc = "Show [L]inks" }) + vim.api.nvim_set_keymap("n", "zi", ":'<,'>ZkInsertLink", { desc = "[I]nsert link" }) + vim.api.nvim_set_keymap("n", "zn", "ZkNew { title = vim.fn.input('Title: ') }", + { desc = "[N]ew note" }) + vim.api.nvim_set_keymap("n", "zo", "ZkNotes { sort = { 'modified' } }", { desc = "[O]pen notes" }) + vim.api.nvim_set_keymap("n", "zt", "ZkTags", { desc = "Search [T]ags" }) + vim.api.nvim_set_keymap("v", "zf", ":'<,'>ZkMatch", { desc = "[F]ind note from selection" }) + vim.api.nvim_set_keymap("v", "zn", ":'<,'>ZkNewFromTitleSelection", { desc = + "[N]ew note from selection" }) + end + }, } diff --git a/lua/myLuaConf/debug.lua b/lua/myLuaConf/debug.lua deleted file mode 100644 index 91199b7..0000000 --- a/lua/myLuaConf/debug.lua +++ /dev/null @@ -1,111 +0,0 @@ -require('lze').load { - { - "nvim-dap", - -- NOTE: I dont want to figure out mason tools installer for this, so I only enabled debug if nix loaded config - for_cat = { cat = 'debug', default = false }, - -- cmd = { "" }, - -- event = "", - -- ft = "", - keys = { - { "", desc = "Debug: Start/Continue" }, - { "", desc = "Debug: Step Into" }, - { "", desc = "Debug: Step Over" }, - { "", desc = "Debug: Step Out" }, - { "b", desc = "Debug: Toggle Breakpoint" }, - { "B", desc = "Debug: Set Breakpoint" }, - { "", desc = "Debug: See last session result." }, - }, - load = (require('nixCatsUtils').isNixCats and function(name) - vim.cmd.packadd(name) - vim.cmd.packadd("nvim-dap-ui") - vim.cmd.packadd("nvim-dap-virtual-text") - end) or function(name) - vim.cmd.packadd(name) - vim.cmd.packadd("nvim-dap-ui") - vim.cmd.packadd("nvim-dap-virtual-text") - vim.cmd.packadd("mason-nvim-dap.nvim") - end, - after = function(plugin) - local dap = require 'dap' - local dapui = require 'dapui' - require('telescope').load_extension('dap') - - -- Basic debugging keymaps, feel free to change to your liking! - vim.keymap.set('n', '', dap.continue, { desc = 'Debug: Start/Continue' }) - vim.keymap.set('n', '', dap.step_into, { desc = 'Debug: Step Into' }) - vim.keymap.set('n', '', dap.step_over, { desc = 'Debug: Step Over' }) - vim.keymap.set('n', '', dap.step_out, { desc = 'Debug: Step Out' }) - vim.keymap.set('n', 'b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' }) - vim.keymap.set('n', 'B', function() - dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, { desc = 'Debug: Set Breakpoint' }) - - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - vim.keymap.set('n', '', dapui.toggle, { desc = 'Debug: See last session result.' }) - - dap.listeners.after.event_initialized['dapui_config'] = dapui.open - dap.listeners.before.event_terminated['dapui_config'] = dapui.close - dap.listeners.before.event_exited['dapui_config'] = dapui.close - - -- Dap UI setup - -- For more information, see |:help nvim-dap-ui| - dapui.setup { - -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. - icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - controls = { - icons = { - pause = '⏸', - play = '▶', - step_into = '⏎', - step_over = '⏭', - step_out = '⏮', - step_back = 'b', - run_last = '▶▶', - terminate = '⏹', - disconnect = '⏏', - }, - }, - } - - require("nvim-dap-virtual-text").setup { - enabled = true, -- enable this plugin (the default) - enabled_commands = true, -- create commands DapVirtualTextEnable, DapVirtualTextDisable, DapVirtualTextToggle, (DapVirtualTextForceRefresh for refreshing when debug adapter did not notify its termination) - highlight_changed_variables = true, -- highlight changed values with NvimDapVirtualTextChanged, else always NvimDapVirtualText - highlight_new_as_changed = false, -- highlight new variables in the same way as changed variables (if highlight_changed_variables) - show_stop_reason = true, -- show stop reason when stopped for exceptions - commented = false, -- prefix virtual text with comment string - only_first_definition = true, -- only show virtual text at first definition (if there are multiple) - all_references = false, -- show virtual text on all all references of the variable (not only definitions) - clear_on_continue = false, -- clear virtual text on "continue" (might cause flickering when stepping) - --- A callback that determines how a variable is displayed or whether it should be omitted - --- variable Variable https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable - --- buf number - --- stackframe dap.StackFrame https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame - --- node userdata tree-sitter node identified as variable definition of reference (see `:h tsnode`) - --- options nvim_dap_virtual_text_options Current options for nvim-dap-virtual-text - --- string|nil A text how the virtual text should be displayed or nil, if this variable shouldn't be displayed - display_callback = function(variable, buf, stackframe, node, options) - if options.virt_text_pos == 'inline' then - return ' = ' .. variable.value - else - return variable.name .. ' = ' .. variable.value - end - end, - -- position of virtual text, see `:h nvim_buf_set_extmark()`, default tries to inline the virtual text. Use 'eol' to set to end of line - virt_text_pos = vim.fn.has 'nvim-0.10' == 1 and 'inline' or 'eol', - - -- experimental features: - all_frames = false, -- show virtual text for all stack frames not only current. Only works for debugpy on my machine. - virt_lines = false, -- show virtual lines instead of virtual text (will flicker!) - virt_text_win_col = nil -- position the virtual text at a fixed window column (starting from the first text column) , - -- e.g. 80 to position at column 80, see `:h nvim_buf_set_extmark()` - } - - -- NOTE: Install lang specific config - -- either in here, or in a separate plugin spec as demonstrated for go below. - end, - }, - -} diff --git a/lua/myLuaConf/format.lua b/lua/myLuaConf/format.lua deleted file mode 100644 index 7f7cce2..0000000 --- a/lua/myLuaConf/format.lua +++ /dev/null @@ -1,38 +0,0 @@ -require('lze').load { - { - "conform.nvim", - for_cat = 'format', - -- cmd = { "" }, - -- event = "", - -- ft = "", - keys = { - { "FF", desc = "[F]ormat [F]ile" }, - }, - -- colorscheme = "", - after = function (plugin) - local conform = require("conform") - - conform.setup({ - formatters_by_ft = { - -- NOTE: download some formatters in lspsAndRuntimeDeps - -- and configure them here - -- lua = { "stylua" }, - -- go = { "gofmt", "golint" }, - -- templ = { "templ" }, - -- Conform will run multiple formatters sequentially - -- python = { "isort", "black" }, - -- Use a sub-list to run only the first available formatter - -- javascript = { { "prettierd", "prettier" } }, - }, - }) - - vim.keymap.set({ "n", "v" }, "FF", function() - conform.format({ - lsp_fallback = true, - async = false, - timeout_ms = 1000, - }) - end, { desc = "[F]ormat [F]ile" }) - end, - }, -} diff --git a/lua/myLuaConf/init.lua b/lua/myLuaConf/init.lua index efbe66c..947f610 100644 --- a/lua/myLuaConf/init.lua +++ b/lua/myLuaConf/init.lua @@ -1,4 +1,5 @@ +-- TODO: split up the plugins a bit. -- NOTE: various, non-plugin config require('myLuaConf.opts_and_keys') @@ -16,21 +17,4 @@ require('lze').register_handlers(require('lzextras').lsp) require("myLuaConf.plugins") -- NOTE: obviously, more plugins, but more organized by what they do below - require("myLuaConf.LSPs") - --- NOTE: we even ask nixCats if we included our debug stuff in this setup! (we didnt) --- But we have a good base setup here as an example anyway! -if nixCats('debug') then - require('myLuaConf.debug') -end --- NOTE: we included these though! Or, at least, the category is enabled. --- these contain nvim-lint and conform setups. -if nixCats('lint') then - require('myLuaConf.lint') -end -if nixCats('format') then - require('myLuaConf.format') -end --- NOTE: I didnt actually include any linters or formatters in this configuration, --- but it is enough to serve as an example. diff --git a/lua/myLuaConf/lint.lua b/lua/myLuaConf/lint.lua deleted file mode 100644 index 2a0f86f..0000000 --- a/lua/myLuaConf/lint.lua +++ /dev/null @@ -1,20 +0,0 @@ -require('lze').load { - { - "nvim-lint", - for_cat = 'lint', - -- cmd = { "" }, - event = "FileType", - -- ft = "", - -- keys = "", - -- colorscheme = "", - after = function (plugin) - require('lint').linters_by_ft = { - -- NOTE: download some linters in lspsAndRuntimeDeps - -- and configure them here - -- markdown = {'vale',}, - -- javascript = { 'eslint' }, - -- typescript = { 'eslint' }, - } - end, - }, -} diff --git a/lua/myLuaConf/non_nix_download.lua b/lua/myLuaConf/non_nix_download.lua index 79793ce..42dd53f 100644 --- a/lua/myLuaConf/non_nix_download.lua +++ b/lua/myLuaConf/non_nix_download.lua @@ -1,3 +1,4 @@ +-- TODO: completley out of date -- load the plugins via paq-nvim when not on nix -- YOU are in charge of putting the plugin -- urls and build steps in here, which will only be used when not on nix. diff --git a/lua/myLuaConf/opts_and_keys.lua b/lua/myLuaConf/opts_and_keys.lua index 13e9800..7e75433 100644 --- a/lua/myLuaConf/opts_and_keys.lua +++ b/lua/myLuaConf/opts_and_keys.lua @@ -107,8 +107,7 @@ vim.keymap.set('i', '', '+', -- Diagnostic keymaps vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) +vim.keymap.set('n', 'd', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) -- moving between splits vim.keymap.set('n', '', 'h', { desc = 'move to right split' }) diff --git a/lua/myLuaConf/plugins/init.lua b/lua/myLuaConf/plugins/init.lua index 401258b..2115fa9 100644 --- a/lua/myLuaConf/plugins/init.lua +++ b/lua/myLuaConf/plugins/init.lua @@ -30,7 +30,7 @@ if nixCats('always') then -- didnt seem necessary. vim.g.loaded_netrwPlugin = 1 require("oil").setup({ - default_file_explorer = true, + default_file_explorer = false, view_options = { show_hidden = true }, @@ -63,8 +63,109 @@ if nixCats('always') then vim.keymap.set("n", "-", "Oil .", { noremap = true, desc = 'Open nvim root directory' }) end +if nixCats("always") then + -- Potentially checkout the lazygit module. + local Snacks = require("snacks") + Snacks.setup({ + bufdelete = { enable = true }, + dim = { enable = true }, + git = { enable = true }, + image = { enable = true }, + input = { enable = true }, + lazygit = { enable = true }, + notifier = { enable = true }, + scroll = { enable = true }, + terminal = { enable = true }, + toggle = { enable = true }, + quickfile = { enable = true }, + scope = { enable = true }, + statuscolumn = { enable = true }, + + explorer = { replace_netrw = true }, + picker = { + enabled = true, + ui_select = true, + matcher = { + fuzzy = true, + frecency = true, + }, + previewers = { + diff = { + builtin = true, -- use Neovim for previewing diffs (true) or use an external tool (false) + cmd = { "delta" }, -- example to show a diff with delta + }, + git = { + builtin = true, -- use Neovim for previewing git output (true) or use git (false) + }, + }, + }, + indent = { + enabled = true, + animate = { enabled = false }, + scope = { enabled = true }, + chunk = { enabled = true }, + }, + }) + + -- setup keybinds. + vim.keymap.set("n", "bd", Snacks.bufdelete.delete, { desc = "delete buffer" }) + vim.keymap.set("n", "t", function() Snacks.explorer() end, { desc = "File [T]ree" }) + vim.keymap.set("n", "gb", Snacks.git.blame_line, { desc = "[G]it [B]lame" }) + vim.keymap.set("n", "gl", Snacks.git.blame_line, { desc = "[L]azy[G]it" }) + + -- picker keybinds + vim.keymap.set("n", "fGb", Snacks.picker.grep_buffers, { desc = "[G]rep buffers" }) + vim.keymap.set("n", "fGl", Snacks.picker.lines, { desc = "[L]ines in buffer" }) + vim.keymap.set("n", "fb", Snacks.picker.buffers, { desc = "[B]uffers" }) + vim.keymap.set("n", "ff", Snacks.picker.files, { desc = "[F]iles" }) + vim.keymap.set("n", "fg", Snacks.picker.grep, { desc = "[G]rep all" }) + vim.keymap.set("n", "fh", Snacks.picker.help, { desc = "[H]elp" }) + vim.keymap.set("n", "fi", Snacks.picker.icons, { desc = "[I]cons" }) + vim.keymap.set("n", "fm", Snacks.picker.marks, { desc = "[M]arks" }) + vim.keymap.set("n", "fs", Snacks.picker.spelling, { desc = "[S]pelling" }) + vim.keymap.set("n", "ft", Snacks.picker.treesitter, { desc = "[T]reesitter" }) + vim.keymap.set("n", "fu", Snacks.picker.undo, { desc = "[U]ndo" }) + vim.keymap.set("n", "fz", Snacks.picker.zoxide, { desc = "[Z]oxide" }) + + -- picker git keybinds + vim.keymap.set("n", "gb", Snacks.picker.git_branches, { desc = "[G]it [B]ranch" }) + vim.keymap.set("n", "gl", Snacks.picker.git_log, { desc = "[G]it [L]og" }) + vim.keymap.set("n", "gd", Snacks.picker.git_diff, { desc = "[G]it [D]iff" }) + + -- setup toggles + Snacks.toggle.option("spell", { name = "spelling" }):map("cs") + Snacks.toggle.option("relativenumber", { name = "Relative Numbering" }):map("n") + Snacks.toggle.dim():map("d") + + -- terminal keybinds + vim.keymap.set("n", "s", function() + Snacks.terminal.toggle(nil, { win = { position = "float" } }) + end, { desc = "terminal" }) + + vim.keymap.set("t", "", function(self) + self.esc_timer = self.esc_timer or (vim.uv or vim.loop).new_timer() + if self.esc_timer:is_active() then + self.esc_timer:stop() + vim.cmd("stopinsert") + else + self.esc_timer:start(200, 0, function() end) + return "" + end + end, { expr = true, desc = "Double tap to escape terminal" }) + + -- setup rename autocmds + local prev = { new_name = "", old_name = "" } -- Prevents duplicate events + vim.api.nvim_create_autocmd("User", { + pattern = "OilActionsPost", + callback = function(event) + if event.data.actions.type == "move" then + Snacks.rename.on_rename_file(event.data.actions.src_url, event.data.actions.dest_url) + end + end, + }) +end + require('lze').load { - { import = "myLuaConf.plugins.telescope", }, { import = "myLuaConf.plugins.treesitter", }, { import = "myLuaConf.plugins.completion", }, { @@ -82,7 +183,7 @@ require('lze').load { { "ms", "MarkdownPreviewStop ", mode = { "n" }, noremap = true, desc = "markdown preview stop" }, { "mt", "MarkdownPreviewToggle ", mode = { "n" }, noremap = true, desc = "markdown preview toggle" }, }, - before = function(plugin) + before = function() vim.g.mkdp_auto_close = 0 end, }, @@ -90,7 +191,7 @@ require('lze').load { "leap.nvim", for_cat = 'always', event = "DeferredUIEnter", - after = function(plugin) + after = function() require('leap').set_default_mappings() end, }, @@ -99,14 +200,14 @@ require('lze').load { for_cat = 'always', event = "DeferredUIEnter", -- keys = "", - after = function(plugin) + after = function() require('nvim-surround').setup() end, }, { "marks.nvim", for_cat = "always", - after = function(plugin) + after = function() require('marks').setup({}) end }, @@ -120,42 +221,6 @@ require('lze').load { vim.g.startuptime_exe_path = nixCats.packageBinPath end, }, - { - "fidget.nvim", - for_cat = 'always', - event = "DeferredUIEnter", - -- keys = "", - after = function(plugin) - require('fidget').setup({}) - end, - }, - { - "toggleterm.nvim", - for_cat = "always", - after = function(plugin) - require("toggleterm").setup({ - direction = "horizontal", - insert_mappings = false, - open_mapping = [[]], - terminal_mappings = false, - }) - - local Terminal = require("toggleterm.terminal").Terminal - Floatingterm = Terminal:new({ - hidden = true, - direction = "float", - }) - - vim.keymap.set( - "n", - "s", - function() - Floatingterm:toggle() - end, - { desc = "toggle [S]cratch terminal", } - ) - end - }, { "lualine.nvim", for_cat = 'always', @@ -164,7 +229,7 @@ require('lze').load { -- ft = "", -- keys = "", -- colorscheme = "", - after = function(plugin) + after = function() require('lualine').setup({ options = { alwaysDivideMiddle = true, @@ -207,7 +272,7 @@ require('lze').load { -- ft = "", -- keys = "", -- colorscheme = "", - after = function(plugin) + after = function() require('gitsigns').setup({ -- See `:help gitsigns.txt` signs = { @@ -286,79 +351,20 @@ require('lze').load { { "which-key.nvim", for_cat = 'always', - after = function(plugin) + after = function() require('which-key').setup({ }) require('which-key').add { - { "g", group = "[g]it" }, + { "g", group = "[g]it" }, + { "z", group = "[z]ettelkasten" }, { "gt", group = "[t]oggle" }, - { "m", group = "[m]arkdown" }, - { "f", group = "[f]ind" }, - { "t", group = "[t]ree" }, - { "c", group = "[c]heck" }, - { "l", group = "[l]sp" }, + { "m", group = "[m]arkdown" }, + { "f", group = "[f]ind" }, + { "t", group = "[t]ree" }, + { "c", group = "[c]heck" }, + { "l", group = "[l]sp" }, { "lw", group = "[l]sp [w]orkspace" }, } end, }, - { - "nvim-tree.lua", - for_cat = "tree", - keys = { - { "t", "NvimTreeToggle", desc = "Toggle file tree", }, - }, - after = function(plugin) - require("nvim-tree").setup() - end - }, - { - -- TODO: Replace toggle term and nvim-tree with snacks equivilants? - -- Potentially checkout the lazygit module. Might even be able to replace - -- telescope? - -- if you do replace telescope, the picker module has a *ton* of interesting pickers, such as an undotree. - "snacks.nvim", - for_cat = "always", - priority = 10, - after = function() - local Snacks = require("snacks") - Snacks.setup({ - input = {}, - image = {}, - notifier = {}, - scroll = {}, - picker = { - enabled = true, - ui_select = true, - }, - terminal = {}, - indent = { - animate = { enabled = true }, - scope = { enabled = true }, - chunk = { enabled = true }, - }, - }) - -- setup rename autocmds - local prev = { new_name = "", old_name = "" } -- Prevents duplicate events - vim.api.nvim_create_autocmd("User", { - pattern = "NvimTreeSetup", - callback = function() - local events = require("nvim-tree.api").events - events.subscribe(events.Event.NodeRenamed, function(data) - if prev.new_name ~= data.new_name or prev.old_name ~= data.old_name then - data = data - Snacks.rename.on_rename_file(data.old_name, data.new_name) - end - end) - end, - }) - vim.api.nvim_create_autocmd("User", { - pattern = "OilActionsPost", - callback = function(event) - if event.data.actions.type == "move" then - Snacks.rename.on_rename_file(event.data.actions.src_url, event.data.actions.dest_url) - end - end, - }) - end - }, } diff --git a/lua/myLuaConf/plugins/telescope.lua b/lua/myLuaConf/plugins/telescope.lua deleted file mode 100644 index 14620c3..0000000 --- a/lua/myLuaConf/plugins/telescope.lua +++ /dev/null @@ -1,115 +0,0 @@ --- Telescope is a fuzzy finder that comes with a lot of different things that --- it can fuzzy find! It's more than just a "file finder", it can search --- many different aspects of Neovim, your workspace, LSP, and more! --- --- The easiest way to use telescope, is to start by doing something like: --- :Telescope help_tags --- --- After running this command, a window will open up and you're able to --- type in the prompt window. You'll see a list of help_tags options and --- a corresponding preview of the help. --- --- Two important keymaps to use while in telescope are: --- - Insert mode: --- - Normal mode: ? --- --- This opens a window that shows you all of the keymaps for the current --- telescope picker. This is really useful to discover what Telescope can --- do as well as how to actually do it! - --- [[ Configure Telescope ]] --- See `:help telescope` and `:help telescope.setup()` - --- Telescope live_grep in git root --- Function to find the git root directory based on the current buffer's path -local function find_git_root() - -- Use the current buffer's path as the starting point for the git search - local current_file = vim.api.nvim_buf_get_name(0) - local current_dir - local cwd = vim.fn.getcwd() - -- If the buffer is not associated with a file, return nil - if current_file == "" then - current_dir = cwd - else - -- Extract the directory from the current file's path - current_dir = vim.fn.fnamemodify(current_file, ":h") - end - - -- Find the Git root directory from the current file's path - local git_root = vim.fn.systemlist("git -C " .. vim.fn.escape(current_dir, " ") .. " rev-parse --show-toplevel")[1] - if vim.v.shell_error ~= 0 then - print("Not a git repository. Searching on current working directory") - return cwd - end - return git_root -end - --- Custom live_grep function to search in git root -local function live_grep_git_root() - local git_root = find_git_root() - if git_root then - require('telescope.builtin').live_grep({ - search_dirs = { git_root }, - }) - end -end - -return { - { - "telescope.nvim", - for_cat = 'telescope', - cmd = { "Telescope", "LiveGrepGitRoot" }, - -- NOTE: our on attach function defines keybinds that call telescope. - -- so, the on_require handler will load telescope when we use those. - on_require = { "telescope", }, - -- event = "", - -- ft = "", - keys = { - { "fM", 'Telescope notify', mode = {"n"}, desc = '[F]ind [M]essage', }, - { "fp",live_grep_git_root, mode = {"n"}, desc = '[F]ind git [P]roject root', }, - { "f/", function() - require('telescope.builtin').live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, mode = {"n"}, desc = '[F]ind [/] in Open Files' }, - { "fb", function() return require('telescope.builtin').buffers() end, mode = {"n"}, desc = '[F]ind [B]uffers', }, - { "fr", function() return require('telescope.builtin').resume() end, mode = {"n"}, desc = '[F]ind [R]esume', }, - { "fd", function() return require('telescope.builtin').diagnostics() end, mode = {"n"}, desc = '[F]ind [D]iagnostics', }, - { "fg", function() return require('telescope.builtin').live_grep() end, mode = {"n"}, desc = '[F]ind by [G]rep', }, - { "fs", function() return require('telescope.builtin').builtin() end, mode = {"n"}, desc = '[F]ind [S]elect Telescope', }, - { "ff", function() return require('telescope.builtin').find_files() end, mode = {"n"}, desc = '[F]ind [F]iles', }, - { "fk", function() return require('telescope.builtin').keymaps() end, mode = {"n"}, desc = '[F]ind [K]eymaps', }, - { "fh", function() return require('telescope.builtin').help_tags() end, mode = {"n"}, desc = '[F]ind [H]elp', }, - { "fz", function() require("telescope").extensions.zoxide.list() end, mode = {"n"}, desc = '[F]ind [Z]oxide',}, - { "fi", function() require("telescope").extensions.file_browser.file_browser() end, mode={"n"}, desc = '[F]ind [I]nteractive file browser',}, - }, - load = function (name) - vim.cmd.packadd(name) - vim.cmd.packadd("telescope-ui-select.nvim") - vim.cmd.packadd("telescope-file-browser.nvim") - vim.cmd.packadd("telescope-zoxide") - end, - after = function (plugin) - local telescope = require("telescope") - telescope.setup { - -- You can put your default mappings / updates / etc. in here - -- All the info you're looking for is in `:help telescope.setup()` - -- - -- pickers = {} - extensions = { - ['ui-select'] = { - require('telescope.themes').get_dropdown(), - }, - }, - } - - -- Enable telescope extensions, if they are installed - telescope.load_extension('ui-select') - telescope.load_extension('zoxide') - telescope.load_extension('file_browser') - - vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) - end, - }, -}