inital commit,

initalized from nix flake init -t github:BirdeeHub/nixCats-nvim#example.
This commit is contained in:
Gabe Venberg 2025-06-27 21:05:54 +02:00
commit 9a78fd2d53
21 changed files with 2208 additions and 0 deletions

166
lua/myLuaConf/LSPs/init.lua Normal file
View file

@ -0,0 +1,166 @@
local catUtils = require('nixCatsUtils')
if (catUtils.isNixCats and nixCats('lspDebugMode')) then
vim.lsp.set_log_level("debug")
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
-- for when you don't provide a filetype to trigger on yourself.
-- nixCats gives us the paths, which is faster than searching the rtp!
local old_ft_fallback = require('lze').h.lsp.get_ft_fallback()
require('lze').h.lsp.set_ft_fallback(function(name)
local lspcfg = nixCats.pawsible({ "allPlugins", "opt", "nvim-lspconfig" }) or nixCats.pawsible({ "allPlugins", "start", "nvim-lspconfig" })
if lspcfg then
local ok, cfg = pcall(dofile, lspcfg .. "/lsp/" .. name .. ".lua")
if not ok then
ok, cfg = pcall(dofile, lspcfg .. "/lua/lspconfig/configs/" .. name .. ".lua")
end
return (ok and cfg or {}).filetypes or {}
else
return old_ft_fallback(name)
end
end)
require('lze').load {
{
"nvim-lspconfig",
for_cat = "general.core",
on_require = { "lspconfig" },
-- NOTE: define a function for lsp,
-- and it will run for all specs with type(plugin.lsp) == table
-- when their filetype trigger loads them
lsp = function(plugin)
vim.lsp.config(plugin.name, plugin.lsp or {})
vim.lsp.enable(plugin.name)
end,
before = function(_)
vim.lsp.config('*', {
on_attach = require('myLuaConf.LSPs.on_attach'),
})
end,
},
{
"mason.nvim",
-- only run it when not on nix
enabled = not catUtils.isNixCats,
on_plugin = { "nvim-lspconfig" },
load = function(name)
vim.cmd.packadd(name)
vim.cmd.packadd("mason-lspconfig.nvim")
require('mason').setup()
-- auto install will make it install servers when lspconfig is called on them.
require('mason-lspconfig').setup { automatic_installation = true, }
end,
},
{
-- lazydev makes your lsp way better in your config without needing extra lsp configuration.
"lazydev.nvim",
for_cat = "neonixdev",
cmd = { "LazyDev" },
ft = "lua",
after = function(_)
require('lazydev').setup({
library = {
{ words = { "nixCats" }, path = (nixCats.nixCatsPath or "") .. '/lua' },
},
})
end,
},
{
-- name of the lsp
"lua_ls",
enabled = nixCats('lua') or nixCats('neonixdev') or false,
-- 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,
-- but with a default on_attach and capabilities
lsp = {
-- if you provide the filetypes it doesn't ask lspconfig for the filetypes
filetypes = { 'lua' },
settings = {
Lua = {
runtime = { version = 'LuaJIT' },
formatters = {
ignoreComments = true,
},
signatureHelp = { enabled = true },
diagnostics = {
globals = { "nixCats", "vim", },
disable = { 'missing-fields' },
},
telemetry = { enabled = false },
},
},
},
-- also these are regular specs and you can use before and after and all the other normal fields
},
{
"gopls",
for_cat = "go",
-- if you don't provide the filetypes it asks lspconfig for them
lsp = {
filetypes = { "go", "gomod", "gowork", "gotmpl" },
},
},
{
"rnix",
-- mason doesn't have nixd
enabled = not catUtils.isNixCats,
lsp = {
filetypes = { "nix" },
},
},
{
"nil_ls",
-- mason doesn't have nixd
enabled = not catUtils.isNixCats,
lsp = {
filetypes = { "nix" },
},
},
{
"nixd",
enabled = catUtils.isNixCats and (nixCats('nix') or nixCats('neonixdev')) or false,
lsp = {
filetypes = { "nix" },
settings = {
nixd = {
-- nixd requires some configuration.
-- luckily, the nixCats plugin is here to pass whatever we need!
-- we passed this in via the `extra` table in our packageDefinitions
-- for additional configuration options, refer to:
-- https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md
nixpkgs = {
-- in the extras set of your package definition:
-- nixdExtras.nixpkgs = ''import ${pkgs.path} {}''
expr = nixCats.extra("nixdExtras.nixpkgs") or [[import <nixpkgs> {}]],
},
options = {
-- If you integrated with your system flake,
-- you should use inputs.self as the path to your system flake
-- that way it will ALWAYS work, regardless
-- of where your config actually was.
nixos = {
-- nixdExtras.nixos_options = ''(builtins.getFlake "path:${builtins.toString inputs.self.outPath}").nixosConfigurations.configname.options''
expr = nixCats.extra("nixdExtras.nixos_options")
},
-- If you have your config as a separate flake, inputs.self would be referring to the wrong flake.
-- You can override the correct one into your package definition on import in your main configuration,
-- or just put an absolute path to where it usually is and accept the impurity.
["home-manager"] = {
-- nixdExtras.home_manager_options = ''(builtins.getFlake "path:${builtins.toString inputs.self.outPath}").homeConfigurations.configname.options''
expr = nixCats.extra("nixdExtras.home_manager_options")
}
},
formatting = {
command = { "nixfmt" }
},
diagnostic = {
suppress = {
"sema-escaping-with"
}
}
}
},
},
},
}

View file

@ -0,0 +1,47 @@
return function(_, bufnr)
-- 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 nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
end
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
-- 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('general.telescope') then
nmap('gr', function() require('telescope.builtin').lsp_references() end, '[G]oto [R]eferences')
nmap('gI', function() require('telescope.builtin').lsp_implementations() end, '[G]oto [I]mplementation')
nmap('<leader>ds', function() require('telescope.builtin').lsp_document_symbols() end, '[D]ocument [S]ymbols')
nmap('<leader>ws', function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, '[W]orkspace [S]ymbols')
end -- TODO: someone who knows the builtin versions of these to do instead help me out please.
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
-- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' })
end

119
lua/myLuaConf/debug.lua Normal file
View file

@ -0,0 +1,119 @@
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 = {
{ "<F5>", desc = "Debug: Start/Continue" },
{ "<F1>", desc = "Debug: Step Into" },
{ "<F2>", desc = "Debug: Step Over" },
{ "<F3>", desc = "Debug: Step Out" },
{ "<leader>b", desc = "Debug: Toggle Breakpoint" },
{ "<leader>B", desc = "Debug: Set Breakpoint" },
{ "<F7>", desc = "Debug: See last session result." },
},
-- colorscheme = "",
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'
-- Basic debugging keymaps, feel free to change to your liking!
vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug: Start/Continue' })
vim.keymap.set('n', '<F1>', dap.step_into, { desc = 'Debug: Step Into' })
vim.keymap.set('n', '<F2>', dap.step_over, { desc = 'Debug: Step Over' })
vim.keymap.set('n', '<F3>', dap.step_out, { desc = 'Debug: Step Out' })
vim.keymap.set('n', '<leader>b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
vim.keymap.set('n', '<leader>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', '<F7>', 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,
},
{
"nvim-dap-go",
for_cat = { cat = 'debug.go', default = false },
on_plugin = { "nvim-dap", },
after = function(plugin)
require("dap-go").setup()
end,
},
}

38
lua/myLuaConf/format.lua Normal file
View file

@ -0,0 +1,38 @@
require('lze').load {
{
"conform.nvim",
for_cat = 'format',
-- cmd = { "" },
-- event = "",
-- ft = "",
keys = {
{ "<leader>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" }, "<leader>FF", function()
conform.format({
lsp_fallback = true,
async = false,
timeout_ms = 1000,
})
end, { desc = "[F]ormat [F]ile" })
end,
},
}

36
lua/myLuaConf/init.lua Normal file
View file

@ -0,0 +1,36 @@
-- NOTE: various, non-plugin config
require('myLuaConf.opts_and_keys')
-- NOTE: register an extra lze handler with the spec_field 'for_cat'
-- that makes enabling an lze spec for a category slightly nicer
require("lze").register_handlers(require('nixCatsUtils.lzUtils').for_cat)
-- NOTE: Register another one from lzextras. This one makes it so that
-- you can set up lsps within lze specs,
-- and trigger lspconfig setup hooks only on the correct filetypes
require('lze').register_handlers(require('lzextras').lsp)
-- demonstrated in ./LSPs/init.lua
-- NOTE: general plugins
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.

26
lua/myLuaConf/lint.lua Normal file
View file

@ -0,0 +1,26 @@
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' },
}
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
callback = function()
require("lint").try_lint()
end,
})
end,
},
}

View file

@ -0,0 +1,91 @@
-- 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.
-- and you should keep any setup functions OUT of this file
-- again, you dont need this file if you only use nix to load the config,
-- this is a fallback only, and is optional.
require('nixCatsUtils.catPacker').setup({
--[[ ------------------------------------------ ]]
--[[ The way to think of this is, its very ]]
--[[ similar to the main nix file for nixCats ]]
--[[ ]]
--[[ It can be used to download your plugins, ]]
--[[ and it has an opt for optional plugins. ]]
--[[ ]]
--[[ We dont want to handle anything about ]]
--[[ loading those plugins here, so that we can ]]
--[[ use the same loading code that we use for ]]
--[[ our normal nix-loaded config. ]]
--[[ we will do all our loading and configuring ]]
--[[ elsewhere in our configuration, so that ]]
--[[ we dont have to write it twice. ]]
--[[ ------------------------------------------ ]]
{ "BirdeeHub/lze", },
{ "BirdeeHub/lzextras", },
{ "stevearc/oil.nvim", },
{ 'joshdick/onedark.vim', },
{ 'nvim-tree/nvim-web-devicons', },
{ 'nvim-lua/plenary.nvim', },
{ 'tpope/vim-repeat', },
{ 'rcarriga/nvim-notify', },
{ 'nvim-treesitter/nvim-treesitter-textobjects', opt = true, },
{ 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate', opt = true, },
{ 'nvim-telescope/telescope-fzf-native.nvim', build = ':!which make && make', opt = true, },
{ 'nvim-telescope/telescope-ui-select.nvim', opt = true, },
{'nvim-telescope/telescope.nvim', opt = true, },
-- lsp
{ 'williamboman/mason.nvim', opt = true, },
{ 'williamboman/mason-lspconfig.nvim', opt = true, },
{ 'j-hui/fidget.nvim', opt = true, },
{ 'neovim/nvim-lspconfig', opt = true, },
-- NOTE: we take care of lazy loading elsewhere in an autocommand
-- so that we can use the same code on and off nix.
-- so here we just tell it not to auto load it
{ 'folke/lazydev.nvim', opt = true, },
-- completion
{ 'L3MON4D3/LuaSnip', opt = true, as = "luasnip", },
{ 'hrsh7th/cmp-cmdline', opt = true, },
{ 'Saghen/blink.cmp', opt = true, },
{ 'Saghen/blink.compat', opt = true, },
{ 'xzbdmw/colorful-menu.nvim', opt = true, },
-- lint and format
{ 'mfussenegger/nvim-lint', opt = true, },
{ 'stevearc/conform.nvim', opt = true, },
-- dap
{ 'nvim-neotest/nvim-nio', opt = true, },
{ 'rcarriga/nvim-dap-ui', opt = true, },
{ 'theHamsta/nvim-dap-virtual-text', opt = true, },
{ 'jay-babu/mason-nvim-dap.nvim', opt = true, },
{ 'mfussenegger/nvim-dap', opt = true, },
-- { 'm-demare/hlargs.nvim', },
{ 'mbbill/undotree', opt = true, },
{ 'tpope/vim-fugitive', opt = true, },
{ 'tpope/vim-rhubarb', opt = true, },
{ 'tpope/vim-sleuth', opt = true, },
{ 'folke/which-key.nvim', opt = true, },
{ 'lewis6991/gitsigns.nvim', opt = true, },
{ 'nvim-lualine/lualine.nvim', opt = true, },
{ 'lukas-reineke/indent-blankline.nvim', opt = true, },
{ 'numToStr/Comment.nvim', opt = true, as = "comment.nvim", },
{ 'kylechui/nvim-surround', opt = true, },
{
"iamcco/markdown-preview.nvim",
build = ":call mkdp#util#install()",
opt = true,
},
-- all the rest of the setup will be done using the normal setup functions later,
-- thus working regardless of what method loads the plugins.
-- only stuff pertaining to downloading should be added to paq.
})
-- OK, again, that isnt needed if you load this setup via nix, but it is an option.

View file

@ -0,0 +1,136 @@
-- NOTE: These 2 need to be set up before any plugins are loaded.
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- [[ Setting options ]]
-- See `:help vim.o`
-- NOTE: You can change these options as you wish!
-- Sets how neovim will display certain whitespace characters in the editor.
-- See `:help 'list'`
-- and `:help 'listchars'`
vim.opt.list = true
vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '' }
-- Set highlight on search
vim.opt.hlsearch = true
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
-- Preview substitutions live, as you type!
vim.opt.inccommand = 'split'
-- Minimal number of screen lines to keep above and below the cursor.
vim.opt.scrolloff = 10
-- Make line numbers default
vim.wo.number = true
-- Enable mouse mode
vim.o.mouse = 'a'
-- Indent
-- vim.o.smarttab = true
vim.opt.cpoptions:append('I')
vim.o.expandtab = true
-- vim.o.smartindent = true
-- vim.o.autoindent = true
-- vim.o.tabstop = 4
-- vim.o.softtabstop = 4
-- vim.o.shiftwidth = 4
-- stops line wrapping from being confusing
vim.o.breakindent = true
-- Save undo history
vim.o.undofile = true
-- Case-insensitive searching UNLESS \C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
-- Keep signcolumn on by default
vim.wo.signcolumn = 'yes'
vim.wo.relativenumber = true
-- Decrease update time
vim.o.updatetime = 250
vim.o.timeoutlen = 300
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menu,preview,noselect'
-- NOTE: You should make sure your terminal supports this
vim.o.termguicolors = true
-- [[ Disable auto comment on enter ]]
-- See :help formatoptions
vim.api.nvim_create_autocmd("FileType", {
desc = "remove formatoptions",
callback = function()
vim.opt.formatoptions:remove({ "c", "r", "o" })
end,
})
-- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = '*',
})
vim.g.netrw_liststyle=0
vim.g.netrw_banner=0
-- [[ Basic Keymaps ]]
-- Keymaps for better default experience
-- See `:help vim.keymap.set()`
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv", { desc = 'Moves Line Down' })
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv", { desc = 'Moves Line Up' })
vim.keymap.set("n", "<C-d>", "<C-d>zz", { desc = 'Scroll Down' })
vim.keymap.set("n", "<C-u>", "<C-u>zz", { desc = 'Scroll Up' })
vim.keymap.set("n", "n", "nzzzv", { desc = 'Next Search Result' })
vim.keymap.set("n", "N", "Nzzzv", { desc = 'Previous Search Result' })
vim.keymap.set("n", "<leader><leader>[", "<cmd>bprev<CR>", { desc = 'Previous buffer' })
vim.keymap.set("n", "<leader><leader>]", "<cmd>bnext<CR>", { desc = 'Next buffer' })
vim.keymap.set("n", "<leader><leader>l", "<cmd>b#<CR>", { desc = 'Last buffer' })
vim.keymap.set("n", "<leader><leader>d", "<cmd>bdelete<CR>", { desc = 'delete buffer' })
-- see help sticky keys on windows
vim.cmd([[command! W w]])
vim.cmd([[command! Wq wq]])
vim.cmd([[command! WQ wq]])
vim.cmd([[command! Q q]])
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- 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', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
-- kickstart.nvim starts you with this.
-- But it constantly clobbers your system clipboard whenever you delete anything.
-- Sync clipboard between OS and Neovim.
-- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
-- vim.o.clipboard = 'unnamedplus'
-- You should instead use these keybindings so that they are still easy to use, but dont conflict
vim.keymap.set({"v", "x", "n"}, '<leader>y', '"+y', { noremap = true, silent = true, desc = 'Yank to clipboard' })
vim.keymap.set({"n", "v", "x"}, '<leader>Y', '"+yy', { noremap = true, silent = true, desc = 'Yank line to clipboard' })
vim.keymap.set({"n", "v", "x"}, '<C-a>', 'gg0vG$', { noremap = true, silent = true, desc = 'Select all' })
vim.keymap.set({'n', 'v', 'x'}, '<leader>p', '"+p', { noremap = true, silent = true, desc = 'Paste from clipboard' })
vim.keymap.set('i', '<C-p>', '<C-r><C-p>+', { noremap = true, silent = true, desc = 'Paste from clipboard from within insert mode' })
vim.keymap.set("x", "<leader>P", '"_dP', { noremap = true, silent = true, desc = 'Paste over selection without erasing unnamed register' })

View file

@ -0,0 +1,140 @@
local load_w_after = function(name)
vim.cmd.packadd(name)
vim.cmd.packadd(name .. '/after')
end
return {
{
"cmp-cmdline",
for_cat = "general.blink",
on_plugin = { "blink.cmp" },
load = load_w_after,
},
{
"blink.compat",
for_cat = "general.blink",
dep_of = { "cmp-cmdline" },
},
{
"luasnip",
for_cat = "general.blink",
dep_of = { "blink.cmp" },
after = function (_)
local luasnip = require 'luasnip'
require('luasnip.loaders.from_vscode').lazy_load()
luasnip.config.setup {}
local ls = require('luasnip')
vim.keymap.set({ "i", "s" }, "<M-n>", function()
if ls.choice_active() then
ls.change_choice(1)
end
end)
end,
},
{
"colorful-menu.nvim",
for_cat = "general.blink",
on_plugin = { "blink.cmp" },
},
{
"blink.cmp",
for_cat = "general.blink",
event = "DeferredUIEnter",
after = function (_)
require("blink.cmp").setup({
-- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
-- See :h blink-cmp-config-keymap for configuring keymaps
keymap = {
preset = 'default',
},
cmdline = {
enabled = true,
completion = {
menu = {
auto_show = true,
},
},
sources = function()
local type = vim.fn.getcmdtype()
-- Search forward and backward
if type == '/' or type == '?' then return { 'buffer' } end
-- Commands
if type == ':' or type == '@' then return { 'cmdline', 'cmp_cmdline' } end
return {}
end,
},
fuzzy = {
sorts = {
'exact',
-- defaults
'score',
'sort_text',
},
},
signature = {
enabled = true,
window = {
show_documentation = true,
},
},
completion = {
menu = {
draw = {
treesitter = { 'lsp' },
components = {
label = {
text = function(ctx)
return require("colorful-menu").blink_components_text(ctx)
end,
highlight = function(ctx)
return require("colorful-menu").blink_components_highlight(ctx)
end,
},
},
},
},
documentation = {
auto_show = true,
},
},
snippets = {
preset = 'luasnip',
active = function(filter)
local snippet = require "luasnip"
local blink = require "blink.cmp"
if snippet.in_snippet() and not blink.is_visible() then
return true
else
if not snippet.in_snippet() and vim.fn.mode() == "n" then snippet.unlink_current() end
return false
end
end,
},
sources = {
default = { 'lsp', 'path', 'snippets', 'buffer', 'omni' },
providers = {
path = {
score_offset = 50,
},
lsp = {
score_offset = 40,
},
snippets = {
score_offset = 40,
},
cmp_cmdline = {
name = 'cmp_cmdline',
module = 'blink.compat.source',
score_offset = -100,
opts = {
cmp_name = 'cmdline',
},
},
},
},
})
end,
},
}

View file

@ -0,0 +1,315 @@
local colorschemeName = nixCats('colorscheme')
if not require('nixCatsUtils').isNixCats then
colorschemeName = 'onedark'
end
-- Could I lazy load on colorscheme with lze?
-- sure. But I was going to call vim.cmd.colorscheme() during startup anyway
-- this is just an example, feel free to do a better job!
vim.cmd.colorscheme(colorschemeName)
local ok, notify = pcall(require, "notify")
if ok then
notify.setup({
on_open = function(win)
vim.api.nvim_win_set_config(win, { focusable = false })
end,
})
vim.notify = notify
vim.keymap.set("n", "<Esc>", function()
notify.dismiss({ silent = true, })
end, { desc = "dismiss notify popup and clear hlsearch" })
end
-- NOTE: you can check if you included the category with the thing wherever you want.
if nixCats('general.extra') then
-- I didnt want to bother with lazy loading this.
-- I could put it in opt and put it in a spec anyway
-- and then not set any handlers and it would load at startup,
-- but why... I guess I could make it load
-- after the other lze definitions in the next call using priority value?
-- didnt seem necessary.
vim.g.loaded_netrwPlugin = 1
require("oil").setup({
default_file_explorer = true,
view_options = {
show_hidden = true
},
columns = {
"icon",
"permissions",
"size",
-- "mtime",
},
keymaps = {
["g?"] = "actions.show_help",
["<CR>"] = "actions.select",
["<C-s>"] = "actions.select_vsplit",
["<C-h>"] = "actions.select_split",
["<C-t>"] = "actions.select_tab",
["<C-p>"] = "actions.preview",
["<C-c>"] = "actions.close",
["<C-l>"] = "actions.refresh",
["-"] = "actions.parent",
["_"] = "actions.open_cwd",
["`"] = "actions.cd",
["~"] = "actions.tcd",
["gs"] = "actions.change_sort",
["gx"] = "actions.open_external",
["g."] = "actions.toggle_hidden",
["g\\"] = "actions.toggle_trash",
},
})
vim.keymap.set("n", "-", "<cmd>Oil<CR>", { noremap = true, desc = 'Open Parent Directory' })
vim.keymap.set("n", "<leader>-", "<cmd>Oil .<CR>", { noremap = true, desc = 'Open nvim root directory' })
end
require('lze').load {
{ import = "myLuaConf.plugins.telescope", },
{ import = "myLuaConf.plugins.treesitter", },
{ import = "myLuaConf.plugins.completion", },
{
"markdown-preview.nvim",
-- NOTE: for_cat is a custom handler that just sets enabled value for us,
-- based on result of nixCats('cat.name') and allows us to set a different default if we wish
-- it is defined in luaUtils template in lua/nixCatsUtils/lzUtils.lua
-- you could replace this with enabled = nixCats('cat.name') == true
-- if you didnt care to set a different default for when not using nix than the default you already set
for_cat = 'general.markdown',
cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle", },
ft = "markdown",
keys = {
{"<leader>mp", "<cmd>MarkdownPreview <CR>", mode = {"n"}, noremap = true, desc = "markdown preview"},
{"<leader>ms", "<cmd>MarkdownPreviewStop <CR>", mode = {"n"}, noremap = true, desc = "markdown preview stop"},
{"<leader>mt", "<cmd>MarkdownPreviewToggle <CR>", mode = {"n"}, noremap = true, desc = "markdown preview toggle"},
},
before = function(plugin)
vim.g.mkdp_auto_close = 0
end,
},
{
"undotree",
for_cat = 'general.extra',
cmd = { "UndotreeToggle", "UndotreeHide", "UndotreeShow", "UndotreeFocus", "UndotreePersistUndo", },
keys = { { "<leader>U", "<cmd>UndotreeToggle<CR>", mode = { "n" }, desc = "Undo Tree" }, },
before = function(_)
vim.g.undotree_WindowLayout = 1
vim.g.undotree_SplitWidth = 40
end,
},
{
"comment.nvim",
for_cat = 'general.extra',
event = "DeferredUIEnter",
after = function(plugin)
require('Comment').setup()
end,
},
{
"indent-blankline.nvim",
for_cat = 'general.extra',
event = "DeferredUIEnter",
after = function(plugin)
require("ibl").setup()
end,
},
{
"nvim-surround",
for_cat = 'general.always',
event = "DeferredUIEnter",
-- keys = "",
after = function(plugin)
require('nvim-surround').setup()
end,
},
{
"vim-startuptime",
for_cat = 'general.extra',
cmd = { "StartupTime" },
before = function(_)
vim.g.startuptime_event_width = 0
vim.g.startuptime_tries = 10
vim.g.startuptime_exe_path = nixCats.packageBinPath
end,
},
{
"fidget.nvim",
for_cat = 'general.extra',
event = "DeferredUIEnter",
-- keys = "",
after = function(plugin)
require('fidget').setup({})
end,
},
-- {
-- "hlargs",
-- for_cat = 'general.extra',
-- event = "DeferredUIEnter",
-- -- keys = "",
-- dep_of = { "nvim-lspconfig" },
-- after = function(plugin)
-- require('hlargs').setup {
-- color = '#32a88f',
-- }
-- vim.cmd([[hi clear @lsp.type.parameter]])
-- vim.cmd([[hi link @lsp.type.parameter Hlargs]])
-- end,
-- },
{
"lualine.nvim",
for_cat = 'general.always',
-- cmd = { "" },
event = "DeferredUIEnter",
-- ft = "",
-- keys = "",
-- colorscheme = "",
after = function (plugin)
require('lualine').setup({
options = {
icons_enabled = false,
theme = colorschemeName,
component_separators = '|',
section_separators = '',
},
sections = {
lualine_c = {
{
'filename', path = 1, status = true,
},
},
},
inactive_sections = {
lualine_b = {
{
'filename', path = 3, status = true,
},
},
lualine_x = {'filetype'},
},
tabline = {
lualine_a = { 'buffers' },
-- if you use lualine-lsp-progress, I have mine here instead of fidget
-- lualine_b = { 'lsp_progress', },
lualine_z = { 'tabs' }
},
})
end,
},
{
"gitsigns.nvim",
for_cat = 'general.always',
event = "DeferredUIEnter",
-- cmd = { "" },
-- ft = "",
-- keys = "",
-- colorscheme = "",
after = function (plugin)
require('gitsigns').setup({
-- See `:help gitsigns.txt`
signs = {
add = { text = '+' },
change = { text = '~' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
},
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map({ 'n', 'v' }, ']c', function()
if vim.wo.diff then
return ']c'
end
vim.schedule(function()
gs.next_hunk()
end)
return '<Ignore>'
end, { expr = true, desc = 'Jump to next hunk' })
map({ 'n', 'v' }, '[c', function()
if vim.wo.diff then
return '[c'
end
vim.schedule(function()
gs.prev_hunk()
end)
return '<Ignore>'
end, { expr = true, desc = 'Jump to previous hunk' })
-- Actions
-- visual mode
map('v', '<leader>hs', function()
gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' }
end, { desc = 'stage git hunk' })
map('v', '<leader>hr', function()
gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' }
end, { desc = 'reset git hunk' })
-- normal mode
map('n', '<leader>gs', gs.stage_hunk, { desc = 'git stage hunk' })
map('n', '<leader>gr', gs.reset_hunk, { desc = 'git reset hunk' })
map('n', '<leader>gS', gs.stage_buffer, { desc = 'git Stage buffer' })
map('n', '<leader>gu', gs.undo_stage_hunk, { desc = 'undo stage hunk' })
map('n', '<leader>gR', gs.reset_buffer, { desc = 'git Reset buffer' })
map('n', '<leader>gp', gs.preview_hunk, { desc = 'preview git hunk' })
map('n', '<leader>gb', function()
gs.blame_line { full = false }
end, { desc = 'git blame line' })
map('n', '<leader>gd', gs.diffthis, { desc = 'git diff against index' })
map('n', '<leader>gD', function()
gs.diffthis '~'
end, { desc = 'git diff against last commit' })
-- Toggles
map('n', '<leader>gtb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' })
map('n', '<leader>gtd', gs.toggle_deleted, { desc = 'toggle git show deleted' })
-- Text object
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', { desc = 'select git hunk' })
end,
})
vim.cmd([[hi GitSignsAdd guifg=#04de21]])
vim.cmd([[hi GitSignsChange guifg=#83fce6]])
vim.cmd([[hi GitSignsDelete guifg=#fa2525]])
end,
},
{
"which-key.nvim",
for_cat = 'general.extra',
-- cmd = { "" },
event = "DeferredUIEnter",
-- ft = "",
-- keys = "",
-- colorscheme = "",
after = function (plugin)
require('which-key').setup({
})
require('which-key').add {
{ "<leader><leader>", group = "buffer commands" },
{ "<leader><leader>_", hidden = true },
{ "<leader>c", group = "[c]ode" },
{ "<leader>c_", hidden = true },
{ "<leader>d", group = "[d]ocument" },
{ "<leader>d_", hidden = true },
{ "<leader>g", group = "[g]it" },
{ "<leader>g_", hidden = true },
{ "<leader>m", group = "[m]arkdown" },
{ "<leader>m_", hidden = true },
{ "<leader>r", group = "[r]ename" },
{ "<leader>r_", hidden = true },
{ "<leader>s", group = "[s]earch" },
{ "<leader>s_", hidden = true },
{ "<leader>t", group = "[t]oggles" },
{ "<leader>t_", hidden = true },
{ "<leader>w", group = "[w]orkspace" },
{ "<leader>w_", hidden = true },
}
end,
},
}

View file

@ -0,0 +1,126 @@
-- 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: <c-/>
-- - 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 = 'general.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 = {
{ "<leader>sM", '<cmd>Telescope notify<CR>', mode = {"n"}, desc = '[S]earch [M]essage', },
{ "<leader>sp",live_grep_git_root, mode = {"n"}, desc = '[S]earch git [P]roject root', },
{ "<leader>/", function()
-- Slightly advanced example of overriding default behavior and theme
-- You can pass additional configuration to telescope to change theme, layout, etc.
require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
winblend = 10,
previewer = false,
})
end, mode = {"n"}, desc = '[/] Fuzzily search in current buffer', },
{ "<leader>s/", function()
require('telescope.builtin').live_grep {
grep_open_files = true,
prompt_title = 'Live Grep in Open Files',
}
end, mode = {"n"}, desc = '[S]earch [/] in Open Files' },
{ "<leader><leader>s", function() return require('telescope.builtin').buffers() end, mode = {"n"}, desc = '[ ] Find existing buffers', },
{ "<leader>s.", function() return require('telescope.builtin').oldfiles() end, mode = {"n"}, desc = '[S]earch Recent Files ("." for repeat)', },
{ "<leader>sr", function() return require('telescope.builtin').resume() end, mode = {"n"}, desc = '[S]earch [R]esume', },
{ "<leader>sd", function() return require('telescope.builtin').diagnostics() end, mode = {"n"}, desc = '[S]earch [D]iagnostics', },
{ "<leader>sg", function() return require('telescope.builtin').live_grep() end, mode = {"n"}, desc = '[S]earch by [G]rep', },
{ "<leader>sw", function() return require('telescope.builtin').grep_string() end, mode = {"n"}, desc = '[S]earch current [W]ord', },
{ "<leader>ss", function() return require('telescope.builtin').builtin() end, mode = {"n"}, desc = '[S]earch [S]elect Telescope', },
{ "<leader>sf", function() return require('telescope.builtin').find_files() end, mode = {"n"}, desc = '[S]earch [F]iles', },
{ "<leader>sk", function() return require('telescope.builtin').keymaps() end, mode = {"n"}, desc = '[S]earch [K]eymaps', },
{ "<leader>sh", function() return require('telescope.builtin').help_tags() end, mode = {"n"}, desc = '[S]earch [H]elp', },
},
-- colorscheme = "",
load = function (name)
vim.cmd.packadd(name)
vim.cmd.packadd("telescope-fzf-native.nvim")
vim.cmd.packadd("telescope-ui-select.nvim")
end,
after = function (plugin)
require('telescope').setup {
-- You can put your default mappings / updates / etc. in here
-- All the info you're looking for is in `:help telescope.setup()`
--
defaults = {
mappings = {
i = { ['<c-enter>'] = 'to_fuzzy_refine' },
},
},
-- pickers = {}
extensions = {
['ui-select'] = {
require('telescope.themes').get_dropdown(),
},
},
}
-- Enable telescope extensions, if they are installed
pcall(require('telescope').load_extension, 'fzf')
pcall(require('telescope').load_extension, 'ui-select')
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
end,
},
}

View file

@ -0,0 +1,78 @@
-- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter`
return {
{
"nvim-treesitter",
for_cat = 'general.treesitter',
-- cmd = { "" },
event = "DeferredUIEnter",
-- ft = "",
-- keys = "",
-- colorscheme = "",
load = function (name)
vim.cmd.packadd(name)
vim.cmd.packadd("nvim-treesitter-textobjects")
end,
after = function (plugin)
-- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter`
require('nvim-treesitter.configs').setup {
highlight = { enable = true, },
indent = { enable = false, },
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<c-space>',
node_incremental = '<c-space>',
scope_incremental = '<c-s>',
node_decremental = '<M-space>',
},
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
swap = {
enable = true,
swap_next = {
['<leader>a'] = '@parameter.inner',
},
swap_previous = {
['<leader>A'] = '@parameter.inner',
},
},
},
}
end,
},
}