dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 131eca02714a445b338811ed84062bdcfec689e7
parent 6a3b649a41fe63f3f1f1fb17562add11b078af06
Author: Alex Balgavy <alexander.balgavy@spaceapplications.com>
Date:   Mon, 16 Jun 2025 21:18:16 +0200

nvim: simplify config

Diffstat:
Mnvim/init.lua | 76++++++++++++++++++----------------------------------------------------------
Mnvim/lazy-lock.json | 55++++++++++++++++++-------------------------------------
Dnvim/lua/config/lsp-inlayhints.lua | 14--------------
Dnvim/lua/config/mason-lspconfig.lua | 147-------------------------------------------------------------------------------
Dnvim/lua/config/nvim-cmp.lua | 45---------------------------------------------
Dnvim/lua/config/nvim-dap-ui.lua | 7-------
Dnvim/lua/config/nvim-dap.lua | 37-------------------------------------
Dnvim/lua/config/nvim-treesitter.lua | 61-------------------------------------------------------------
Dnvim/lua/config/telescope.lua | 49-------------------------------------------------
Anvim/lua/highlight_on_yank.lua | 7+++++++
Dnvim/lua/llm.lua | 123-------------------------------------------------------------------------------
Anvim/lua/mappings.lua | 27+++++++++++++++++++++++++++
Dnvim/lua/plugins.lua | 481-------------------------------------------------------------------------------
Anvim/lua/plugins/aerial.lua | 17+++++++++++++++++
Anvim/lua/plugins/completion.lua | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Anvim/lua/plugins/formatting.lua | 48++++++++++++++++++++++++++++++++++++++++++++++++
Anvim/lua/plugins/gitsigns.lua | 21+++++++++++++++++++++
Anvim/lua/plugins/init.lua | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anvim/lua/plugins/lsp.lua | 209+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anvim/lua/plugins/telescope.lua | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anvim/lua/plugins/treesitter.lua | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anvim/lua/plugins/trouble.lua | 38++++++++++++++++++++++++++++++++++++++
22 files changed, 725 insertions(+), 1059 deletions(-)

diff --git a/nvim/init.lua b/nvim/init.lua @@ -1,3 +1,4 @@ +-- Load my vim config vim.cmd([[ set runtimepath^=~/.vim runtimepath+=~/.vim/after let &packpath = &runtimepath @@ -5,21 +6,24 @@ call setenv("MYOLDVIMRC", "~/.vim/vimrc") source $MYOLDVIMRC ]]) +-- Set <space> as the leader key +-- See `:help mapleader` +-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) +vim.g.mapleader = ' ' +vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) + -- Install Lazy -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.uv.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) +local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = 'https://github.com/folke/lazy.nvim.git' + local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } + if vim.v.shell_error ~= 0 then + error('Error cloning lazy.nvim:\n' .. out) + end end - vim.opt.rtp:prepend(lazypath) +-- Load everything from ./lua/plugins.lua, ./lua/plugins/*.lua require('lazy').setup('plugins', { performance = { rtp = { @@ -31,59 +35,15 @@ require('lazy').setup('plugins', { -- Set completeopt to have a better completion experience vim.o.completeopt = 'menuone,noselect' --- [[ Basic Keymaps ]] --- Set <space> as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -vim.g.mapleader = ' ' - --- Keymaps for better default experience --- See `:help vim.keymap.set()` -vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) - --- [[ 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 = '*', -}) - - --- Diagnostic keymaps -vim.keymap.set('n', '[d', function() vim.diagnostic.jump({ count = -1, float = true }) end) -vim.keymap.set('n', ']d', function() vim.diagnostic.jump({ count = 1, float = true }) end) -vim.keymap.set('n', ']e', - function() vim.diagnostic.jump({ count = 1, float = true, severity = vim.diagnostic.severity.ERROR }) end) -vim.keymap.set('n', '[e', - function() vim.diagnostic.jump({ count = -1, float = true, severity = vim.diagnostic.severity.ERROR }) end) -vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float) -vim.keymap.set('n', '<leader>q', function() vim.diagnostic.setloclist({ severity = vim.diagnostic.severity.ERROR }) end) - --- 'i' that indents correctly on empty lines -vim.keymap.set('n', 'i', function() - if #vim.fn.getline(".") == 0 then - return [["_cc]] - else - return "i" - end -end, { expr = true }) - -require('llm') +require('highlight_on_yank') +require('mappings') require('netrw_target') -vim.cmd([[ -nnoremap <leader><C-e><C-u> :<c-u>exe "vsplit ~/.vim/snippets/"..&filetype..".snippets"<CR> -]]) - vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function(ev) local client = vim.lsp.get_client_by_id(ev.data.client_id) - if client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then + if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then vim.lsp.inlay_hint.enable(true, { bufnr = ev.buf }) end end, diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json @@ -1,47 +1,28 @@ { "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, - "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, - "aerial.nvim": { "branch": "master", "commit": "3284a2cb858ba009c79da87d5e010ccee3c99c4d" }, + "aerial.nvim": { "branch": "master", "commit": "5c0df1679bf7c814c924dc6646cc5291daca8363" }, "baleia.nvim": { "branch": "main", "commit": "880e97c02edf3148ba2bdc6305ac03eb3c3711e0" }, + "blink.cmp": { "branch": "main", "commit": "022521a8910a5543b0251b21c9e1a1e989745796" }, "cellular-automaton.nvim": { "branch": "main", "commit": "1606e9d5d04ff254023c3f3c62842d065708d6d3" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, - "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "colortils.nvim": { "branch": "main", "commit": "948d4eddbd20c3e9eac79368dc50c7929d4fb823" }, - "conform.nvim": { "branch": "master", "commit": "a6f5bdb78caa305496357d17e962bbc4c0b392e2" }, - "diagflow.nvim": { "branch": "main", "commit": "9a05fda174038d349845efc70422bda4ce86b185" }, + "conform.nvim": { "branch": "master", "commit": "0e93e0d12d2f7ebdea9e3e444dfaff0050cefbe6" }, "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, - "flash.nvim": { "branch": "main", "commit": "3c942666f115e2811e959eabbdd361a025db8b63" }, - "formatter.nvim": { "branch": "master", "commit": "eb89a1f3e079f1b9680bc7293b75fffccb5e1598" }, - "gitsigns.nvim": { "branch": "main", "commit": "4c40357994f386e72be92a46f41fc1664c84c87d" }, - "indent-blankline.nvim": { "branch": "master", "commit": "e10626f7fcd51ccd56d7ffc00883ba7e0aa28f78" }, - "lazy.nvim": { "branch": "main", "commit": "e5e9bf48211a13d9ee6c1077c88327c49c1ab4a0" }, - "lsp_signature.nvim": { "branch": "master", "commit": "5b64964ed02098c85613ee3d20f96bed1dfb64cc" }, - "markview.nvim": { "branch": "main", "commit": "f1e2a57388b61fff8e9d7519ce05cee27a59a57e" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" }, - "mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" }, - "mini.ai": { "branch": "main", "commit": "6e01c0e5a15554852546fac9853960780ac52ed4" }, - "mini.align": { "branch": "main", "commit": "3bdf6f0b91b31db5300a7b04f53f296a7fb150c1" }, - "mini.animate": { "branch": "main", "commit": "13e170c13030b043aa8ad4311012ec0eaba0d5c7" }, - "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, - "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, - "nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" }, - "nvim-cmp-lsp-rs": { "branch": "main", "commit": "57f29333e6d2b655d5b0edb999b0006d49fde0ca" }, - "nvim-dap": { "branch": "master", "commit": "6e0e8ab4d8ed520076971465a4388dfe54a91d83" }, - "nvim-dap-python": { "branch": "master", "commit": "34282820bb713b9a5fdb120ae8dd85c2b3f49b51" }, - "nvim-dap-ui": { "branch": "master", "commit": "bc81f8d3440aede116f821114547a476b082b319" }, - "nvim-dap-virtual-text": { "branch": "master", "commit": "df66808cd78b5a97576bbaeee95ed5ca385a9750" }, - "nvim-lspconfig": { "branch": "master", "commit": "6b63bdf2399b9bedf93297d98419550523a9ad68" }, - "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, - "nvim-treesitter": { "branch": "master", "commit": "5774e7d3da4f681296a87fcd85d17779ad362a4f" }, - "nvim-treesitter-context": { "branch": "master", "commit": "198720b4016af04c9590f375d714d5bf8afecc1a" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "ad8f0a472148c3e0ae9851e26a722ee4e29b1595" }, - "nvim-web-devicons": { "branch": "master", "commit": "1020869742ecb191f260818234517f4a1515cfe8" }, + "gitsigns.nvim": { "branch": "main", "commit": "d0f90ef51d4be86b824b012ec52ed715b5622e51" }, + "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, + "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "mini.ai": { "branch": "main", "commit": "5225f16eacf4dce2cb7204ca345123ef54e209d6" }, + "mini.align": { "branch": "main", "commit": "969bdcdf9b88e30bda9cb8ad6f56afed208778ad" }, + "mini.animate": { "branch": "main", "commit": "9b518c39c0e25b7b5e4e61db3f1407f7b4889f4e" }, + "nvim-lspconfig": { "branch": "master", "commit": "036885e8e5456d3907626b634693234f628afef6" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "nvim-treesitter-context": { "branch": "master", "commit": "464a443b5a6657f39772b20baa95d02ffe97b268" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "0f051e9813a36481f48ca1f833897210dbcfffde" }, + "nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, - "smear-cursor.nvim": { "branch": "main", "commit": "4b7334a09cd2434e73588cc0ea63e71177251249" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "2a5ceff981501cff8f46871d5402cd3378a8ab6a" }, - "telescope-undo.nvim": { "branch": "main", "commit": "928d0c2dc9606e01e2cc547196f48d2eaecf58e5" }, - "telescope.nvim": { "branch": "master", "commit": "589910694bafe3975d0f025a750dcabc09824126" }, - "trouble.nvim": { "branch": "dev", "commit": "8a0394ce7c38d961b355160dfc1e4ab77b9a38d7" }, + "smear-cursor.nvim": { "branch": "main", "commit": "aff844fc1483fd673f721a41affcd7e2fcb885f5" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, + "telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" }, + "trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" }, "which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" } } diff --git a/nvim/lua/config/lsp-inlayhints.lua b/nvim/lua/config/lsp-inlayhints.lua @@ -1,14 +0,0 @@ -require('lsp-inlayhints').setup() -vim.api.nvim_create_augroup("LspAttach_inlayhints", {}) -vim.api.nvim_create_autocmd("LspAttach", { - group = "LspAttach_inlayhints", - callback = function(args) - if not (args.data and args.data.client_id) then - return - end - - local bufnr = args.buf - local client = vim.lsp.get_client_by_id(args.data.client_id) - require("lsp-inlayhints").on_attach(client, bufnr) - end, -}) diff --git a/nvim/lua/config/mason-lspconfig.lua b/nvim/lua/config/mason-lspconfig.lua @@ -1,147 +0,0 @@ -local mason_lspconfig = require 'mason-lspconfig' --- Enable the following language servers --- Feel free to add/remove any LSPs that you want here. They will automatically be installed. --- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/doc/server-mapping.md --- Add any additional override configuration in the following tables. They will be passed to --- the `settings` field of the server config. You must look up that documentation yourself. -local rust_clippy = { - command = "clippy", - workspace = true, - extraArgs = { - "--no-deps", - "--", - "-D", "clippy::pedantic", - "-D", "clippy::nursery", - "-D", "clippy::restriction", - "-A", "clippy::blanket_clippy_restriction_lints", - "-A", "clippy::missing_docs_in_private_items", - "-A", "clippy::implicit_return", - "-A", "clippy::question_mark_used", - "-A", "clippy::min_ident_chars", - "-A", "clippy::pattern_type_mismatch", - "-A", "clippy::single_call_fn", - "-A", "clippy::as_conversions", - "-A", "clippy::pub_with_shorthand", - "-A", "clippy::shadow_reuse", - "-A", "clippy::separated_literal_suffix", - "-A", "clippy::float_arithmetic", - "-A", "clippy::pub_use", - "-A", "clippy::single_char_lifetime_names", - "-A", "clippy::missing_trait_methods", - -- "-A", "clippy::multiple_unsafe_ops_per_block", -- broken on 0.1.74 - "-A", "clippy::mod_module_files", - "-A", "clippy::std_instead_of_alloc", - "-A", "clippy::integer_division_remainder_used", - "-D", "rust_2018_idioms", - "-D", "missing_docs", - "-D", "warnings", - "-A", "clippy::too_many_lines", - "-A", "clippy::arbitrary_source_item_ordering", - }, -} -local servers = { - ansiblels = {}, - lua_ls = { - ['Lua'] = { - runtime = { - -- Tell the language server which version of Lua you're using - -- (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { - 'vim', - 'require' - }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - } - }, - docker_compose_language_service = {}, - rust_analyzer = { - ['rust-analyzer'] = { - check = rust_clippy, - }, - checkOnSave = { enable = false }, - diagnostics = { enable = false }, - }, - rubocop = {}, - -- solargraph = {}, - -- bashls = {}, - -- jdtls = {}, - -- jsonls = {}, - -- texlab = {}, - -- clangd = {}, - -- perlnavigator = {}, -} - - -mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), -} - --- LSP settings. --- This function gets run when an LSP connects to a particular buffer. -local on_attach = function(_, bufnr) - -- NOTE: Remember that lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself - -- many times. - -- - -- In this case, 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>ra', vim.lsp.buf.code_action, '[C]ode [A]ction') - vim.keymap.set('v', '<leader>ra', vim.lsp.buf.code_action, { buffer = bufnr, desc = '[C]ode [A]ction' }) - - nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') - nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') - nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - - -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('<leader>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 - -mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()), - on_attach = on_attach, - settings = servers[server_name], - } - end, -} -require('lspconfig').bacon_ls.setup({}) -require('lspconfig').pyright.setup({}) diff --git a/nvim/lua/config/nvim-cmp.lua b/nvim/lua/config/nvim-cmp.lua @@ -1,45 +0,0 @@ -local cmp = require 'cmp' -require("luasnip.loaders.from_snipmate").lazy_load({paths="~/.dotfiles/vim/snippets"}) -local luasnip = require 'luasnip' -luasnip.setup({ - history = false -}) - -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert { - ['<C-d>'] = cmp.mapping.scroll_docs(-4), - ['<C-f>'] = cmp.mapping.scroll_docs(4), - ['<C-Space>'] = cmp.mapping.complete(), - ['<CR>'] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - ['<Tab>'] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - ['<S-Tab>'] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'i', 's' }), - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} diff --git a/nvim/lua/config/nvim-dap-ui.lua b/nvim/lua/config/nvim-dap-ui.lua @@ -1,7 +0,0 @@ -require('dapui').setup() -vim.keymap.set({'n', 'v'}, '<localleader>dh', function() - require('dapui').eval(nil, {}) -end, { desc = 'Eval current expression' }) -vim.keymap.set('n', '<localleader>do', function() - require('dapui').toggle() -end, { desc = '[D]ebug toggle UI' }) diff --git a/nvim/lua/config/nvim-dap.lua b/nvim/lua/config/nvim-dap.lua @@ -1,37 +0,0 @@ -local dap = require('dap') -dap.adapters.codelldb = { - type = 'server', - port = "${port}", - executable = { - -- CHANGE THIS to your path! - command = 'codelldb', - args = {"--port", "${port}"}, - - -- On windows you may have to uncomment this: - -- detached = false, - } -} -dap.configurations.rust = { - { - name = "Launch file", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') - end, - cwd = '${workspaceFolder}', - stopOnEntry = false, - }, -} -vim.keymap.set('n', '<localleader>dc', function() require('dap').continue() end, { desc = '[D]ebug [c]ontinue' }) -vim.keymap.set('n', '<localleader>dn', function() require('dap').step_over() end, { desc = '[D]ebug [n]ext' }) -vim.keymap.set('n', '<localleader>di', function() require('dap').step_into() end, { desc = '[D]ebug [i]n' }) -vim.keymap.set('n', '<localleader>df', function() require('dap').step_out() end, { desc = '[D]ebug [f]inish' }) -vim.keymap.set('n', '<localleader>db', function() require('dap').toggle_breakpoint() end, { desc = '[D]ebug [b]reak toggle' }) -vim.keymap.set('n', '<localleader>dB', function() require('dap').set_breakpoint() end, { desc = '[D]ebug [B]reak set' }) -vim.keymap.set('n', '<localleader>dm', function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) end, { desc = '[D]ebug [m]essage' }) -vim.keymap.set('n', '<localleader>dr', function() require('dap').repl.open() end, { desc = '[D]ebug [r]epl' }) -vim.keymap.set('n', '<localleader>dC', function() require('dap').run_last() end, { desc = '[D]ebug last' }) -vim.keymap.set('n', '<localleader>dj', function() require('dap').focus_frame() end, { desc = '[D]ebug [j]ump to frame' }) -vim.keymap.set('n', '<localleader>dH', function() require('dap').goto_(nil) end, { desc = '[D]ebug [H]ere' }) -vim.keymap.set('n', '<localleader>dS', function() require('dap').close() end, { desc = '[D]ebug [S]top' }) diff --git a/nvim/lua/config/nvim-treesitter.lua b/nvim/lua/config/nvim-treesitter.lua @@ -1,61 +0,0 @@ -require('nvim-treesitter.configs').setup { - -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'vim', 'vimdoc', 'bash', 'ledger', 'ruby', - 'python', 'java', 'sql', 'markdown_inline', 'html'}, - - highlight = { enable = true }, - indent = { enable = true, disable = { 'python' } }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '<c-space>', - node_incremental = '<c-space>', - scope_incremental = '<c-s>', - node_decremental = '<c-+>', - }, - }, - 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', - }, - }, - }, -} diff --git a/nvim/lua/config/telescope.lua b/nvim/lua/config/telescope.lua @@ -1,49 +0,0 @@ -pcall(require('telescope').load_extension, 'fzf') -require('telescope').setup { - defaults = { - mappings = { - i = { - ['<C-u>'] = false, - ['<C-d>'] = false, - }, - }, - }, -} --- Disable folding in Telescope's result window. -vim.api.nvim_create_autocmd("FileType", - { pattern = "TelescopeResults", command = [[setlocal nofoldenable foldlevelstart=99]] }) - -vim.keymap.set('n', '<leader>sp', require('telescope.builtin').oldfiles, { desc = '[S]earch [p]reviously opened files' }) -vim.keymap.set('n', '<leader>b', require('telescope.builtin').buffers, { desc = 'Find existing buffers' }) -vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) -vim.keymap.set('n', '<leader>cv', - function() require('telescope.builtin').find_files({ cwd = vim.env.DOTFILES .. '/nvim' }) end, - { desc = 'Neovim configs' }) -vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) -vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) -vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) -vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) -vim.keymap.set('n', '<leader>sr', require('telescope.builtin').lsp_references, { desc = '[S]earch [R]eferences' }) -vim.keymap.set('n', '<leader>s<', require('telescope.builtin').lsp_incoming_calls, { desc = '[S]earch [I]ncoming calls' }) -vim.keymap.set('n', '<leader>s>', require('telescope.builtin').lsp_outgoing_calls, { desc = '[S]earch [O]utgoing calls' }) -vim.keymap.set('n', '<leader>st', require('telescope.builtin').current_buffer_fuzzy_find, - { desc = '[Search] [T]his buffer' }) -vim.keymap.set('n', '<leader>sI', require('telescope.builtin').lsp_implementations, - { desc = '[S]earch [i]mplementations' }) -vim.keymap.set('n', '<leader>ss', function() - local server_ready = not not vim.lsp.buf_notify(0, '$/progress', {}) - if server_ready then - require('telescope.builtin').lsp_dynamic_workspace_symbols() - else - require('telescope.builtin').treesitter() - end -end, { desc = '[S]earch [S]ymbols' }) -vim.keymap.set('n', '<leader>sj', require('telescope.builtin').jumplist, { desc = '[S]earch [J]umplist' }) -vim.keymap.set('n', '<leader>sb', function() - local server_ready = not not vim.lsp.buf_notify(0, '$/progress', {}) - if server_ready then - require('telescope.builtin').lsp_document_symbols() - else - require('telescope.builtin').tags() - end -end, { desc = 'Telescope [T]ags' }) diff --git a/nvim/lua/highlight_on_yank.lua b/nvim/lua/highlight_on_yank.lua @@ -0,0 +1,7 @@ +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }), + callback = function() + vim.hl.on_yank() + end, +}) diff --git a/nvim/lua/llm.lua b/nvim/lua/llm.lua @@ -1,123 +0,0 @@ -local ESC_FEEDKEY = vim.api.nvim_replace_termcodes("<ESC>", true, false, true) -local ollama = { - - --- @param model string - --- @param context string - --- @param prompt string - --- @param buf_nr number - --- @param max_width number - --- @return number - run = function(model, context, prompt, buf_nr, max_width) - local cmd = ("ollama run $model $prompt") - :gsub("$model", model) - :gsub("$prompt", vim.fn.shellescape(context .. "\n" .. prompt)) - local header = vim.split(prompt, "\n") - table.insert(header, "----------------------------------------") - vim.api.nvim_buf_set_lines(buf_nr, 0, -1, false, header) - local line = vim.tbl_count(header) - local line_char_count = 0 - local words = {} - return vim.fn.jobstart(cmd, { - on_stdout = function(_, data, _) - for i, token in ipairs(data) do - if i > 1 or (string.match(token, "^%s") and line_char_count > max_width) then -- if returned data array has more than one element, a line break occured. - line = line + 1 - words = {} - line_char_count = 0 - end - line_char_count = line_char_count + #token - table.insert(words, token) - vim.api.nvim_buf_set_lines(buf_nr, line, line + 1, false, { table.concat(words, "") }) - end - end, - }) - end, - - --- @return string - get_visual_lines = function(bufnr) - vim.api.nvim_feedkeys(ESC_FEEDKEY, "n", true) - vim.api.nvim_feedkeys("gv", "x", false) - vim.api.nvim_feedkeys(ESC_FEEDKEY, "n", true) - - local start_row, start_col = unpack(vim.api.nvim_buf_get_mark(bufnr, "<")) - local end_row, end_col = unpack(vim.api.nvim_buf_get_mark(bufnr, ">")) - local lines = vim.api.nvim_buf_get_lines(bufnr, start_row - 1, end_row, false) - - if start_row == 0 then - lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) - start_row = 1 - start_col = 0 - end_row = #lines - end_col = #lines[#lines] - end - - start_col = start_col + 1 - end_col = math.min(end_col, #lines[#lines] - 1) + 1 - - lines[#lines] = lines[#lines]:sub(1, end_col) - lines[1] = lines[1]:sub(start_col) - - return table.concat(lines, "\n") - end -} -local plen = require("plenary.window.float") --- define some styles and spawn a scratch buffer -local win_options = { - winblend = 10, - border = "rounded", - bufnr = vim.api.nvim_create_buf(false, true) -} - -vim.keymap.set("n", "<leader>cc", function() - local prompt = vim.fn.input("Prompt: ") - if prompt == "" then - return - end - plen.clear(win_options.bufnr) - local float = plen.percentage_range_window(0.8, 0.8, win_options) - local win_width = vim.api.nvim_win_get_width(float.win_id) - 5 - ollama.run("mistral:instruct", "", prompt, float.bufnr, win_width) -end, { silent = true, desc = "Mistral" }) - -vim.keymap.set("v", "<leader>cp", function() - local prompt = ollama.get_visual_lines(0) - plen.clear(win_options.bufnr) - local float = plen.percentage_range_window(0.8, 0.8, win_options) - local win_width = vim.api.nvim_win_get_width(float.win_id) - 5 - ollama.run("mistral:instruct", "", prompt, float.bufnr, win_width) -end, { silent = true, desc = "Mistral" }) - ------------------------------------------------------------------- --- coding -vim.keymap.set("v", "<leader>cc", function() - local context = vim.fn.input("Prompt: ") - if context == "" then - return - end - local prompt = ollama.get_visual_lines(0) - plen.clear(win_options.bufnr) - local float = plen.percentage_range_window(0.8, 0.8, win_options) - local win_width = vim.api.nvim_win_get_width(float.win_id) - 5 - ollama.run("codellama:7b", context, prompt, float.bufnr, win_width) -end, { silent = true, desc = "Codellama" }) - ------------------------------------------------------------------- --- general purpose math & logic questions -vim.keymap.set("n", "<leader>cm", function() - local prompt = vim.fn.input("Prompt: ") - if prompt == "" then - return - end - plen.clear(win_options.bufnr) - local float = plen.percentage_range_window(0.8, 0.8, win_options) - local win_width = vim.api.nvim_win_get_width(float.win_id) - 5 - ollama.run("wizard-math", "", prompt, float.bufnr, win_width) -end, { silent = true, desc = "Math" }) - -vim.keymap.set("v", "<leader>cm", function() - local prompt = ollama.get_visual_lines(0) - plen.clear(win_options.bufnr) - local float = plen.percentage_range_window(0.8, 0.8, win_options) - local win_width = vim.api.nvim_win_get_width(float.win_id) - 5 - ollama.run("wizard-math", "", prompt, float.bufnr, win_width) -end, { silent = true, desc = "Math" }) diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua @@ -0,0 +1,27 @@ +local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { desc = desc }) +end +local diag = vim.diagnostic +-- Diagnostic keymaps +map('[d', function() diag.jump({ count = -1, float = true }) end, 'Previous diagnostic') +map(']d', function() diag.jump({ count = 1, float = true }) end, 'Next diagnostic') + +map('[e', function() + diag.jump({ count = -1, float = true, severity = diag.severity.ERROR }) +end, 'Previous error') +map(']e', function() + diag.jump({ count = 1, float = true, severity = diag.severity.ERROR }) +end, 'Next error') + +map('<leader>e', diag.open_float, 'Show errors') +map('<leader>q', function() diag.setloclist({ severity = diag.severity.ERROR }) end, 'Errors to quickfix') + +-- 'i' that indents correctly on empty lines +vim.keymap.set('n', 'i', function() + if #vim.fn.getline(".") == 0 then + return [["_cc]] + else + return "i" + end +end, { expr = true }) diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua @@ -1,481 +0,0 @@ -return { - { - 'stevearc/dressing.nvim', - opts = {}, - }, - { - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs to stdpath for neovim - { - 'williamboman/mason.nvim', - opts = {}, - }, - { - 'williamboman/mason-lspconfig.nvim', - config = function() - require 'config.mason-lspconfig' - - -- Workaround: https://github.com/neovim/neovim/issues/30985 - -- if vim.fn.has('nvim-0.11.0-dev') ~= 1 then - -- error("Check if you still need this LSP workaround") - -- end - for _, method in ipairs({ 'textDocument/diagnostic', 'workspace/diagnostic' }) do - local default_diagnostic_handler = vim.lsp.handlers[method] - vim.lsp.handlers[method] = function(err, result, context, config) - if err ~= nil and err.code == -32802 then - return - end - return default_diagnostic_handler(err, result, context, config) - end - end - end, - }, - - -- Useful status updates for LSP - { - 'j-hui/fidget.nvim', - opts = {}, - }, - - -- Additional lua configuration, makes nvim stuff amazing - { - 'folke/neodev.nvim', - opts = { - library = { plugins = { "nvim-dap-ui" }, types = true }, - }, - } - }, - }, - - { - 'jose-elias-alvarez/null-ls.nvim', - config = function() - local null_ls = require('null-ls') - null_ls.setup { sources = { - null_ls.builtins.diagnostics.shellcheck, - null_ls.builtins.code_actions.shellcheck, - null_ls.builtins.diagnostics.phpcs, - -- null_ls.builtins.diagnostics.vacuum, - null_ls.builtins.diagnostics.yamllint.with({ - extra_args = { - "-d", [[{ - extends: default, - rules: { - line-length: {max: 160}, - document-start: disable, - comments: { - min-spaces-from-content: 1, - }, - } - }]] - } - }), - null_ls.builtins.diagnostics.checkmake, - null_ls.builtins.diagnostics.flake8.with({ - extra_args = { "--max-line-length", "130" }, - }), - -- null_ls.builtins.diagnostics.pylint, - null_ls.builtins.diagnostics.ansiblelint, - } } - end, - }, - - { -- Autocompletion - 'hrsh7th/nvim-cmp', - config = function() - require 'config.nvim-cmp' - end, - dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'zjp-CN/nvim-cmp-lsp-rs' }, - }, - - { -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - build = function() - pcall(require('nvim-treesitter.install').update { with_sync = true }) - end, - config = function() - require 'config.nvim-treesitter' - end, - }, - - -- Additional text objects via treesitter - 'nvim-treesitter/nvim-treesitter-textobjects', - - { - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - on_attach = function() - vim.keymap.set('n', ']c', function() require('gitsigns').next_hunk() end, { buffer = true }) - vim.keymap.set('n', '[c', function() require('gitsigns').prev_hunk() end, { buffer = true }) - vim.keymap.set('n', ']=', function() require('gitsigns').toggle_deleted() end, { buffer = true }) - vim.keymap.set('n', ']~', function() require('gitsigns').diffthis() end, { buffer = true }) - vim.keymap.set('n', ']-', function() require('gitsigns').preview_hunk() end, { buffer = true }) - vim.keymap.set('n', ']+', function() require('gitsigns').select_hunk() end, { buffer = true }) - end, - }, - }, - - - { -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - main = 'ibl', - opts = { - indent = { - char = '┊', - }, - } - }, - - { - 'numToStr/Comment.nvim', -- "gc" to comment visual regions/lines - opts = {} - }, - - -- Fuzzy Finder (files, lsp, etc) - { - 'nvim-telescope/telescope.nvim', - dependencies = { 'nvim-lua/plenary.nvim' }, - config = function() - require 'config.telescope' - end, - }, - - -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available - { - 'nvim-telescope/telescope-fzf-native.nvim', - build = 'make', - cond = vim.fn.executable 'make' == 1 - }, - - { - "debugloop/telescope-undo.nvim", - dependencies = { -- note how they're inverted to above example - { - "nvim-telescope/telescope.nvim", - dependencies = { "nvim-lua/plenary.nvim" }, - }, - }, - keys = { - { -- lazy style key map - "<leader>U", - "<cmd>Telescope undo<cr>", - desc = "undo history", - }, - }, - opts = { - -- don't use `defaults = { }` here, do this in the main telescope spec - extensions = { - undo = { - mappings = { - i = { - ["<cr>"] = function(bufnr) - return require("telescope-undo.actions").restore(bufnr) - end, - ["<C-y>"] = function(bufnr) - return require("telescope-undo.actions").yank_additions(bufnr) - end, - }, - n = { - ["<cr>"] = function(bufnr) - return require("telescope-undo.actions").restore(bufnr) - end, - ["y"] = function(bufnr) - return require("telescope-undo.actions").yank_additions(bufnr) - end, - }, - }, - }, - -- no other extensions here, they can have their own spec too - }, - }, - config = function(_, opts) - -- Calling telescope's setup from multiple specs does not hurt, it will happily merge the - -- configs for us. We won't use data, as everything is in it's own namespace (telescope - -- defaults, as well as each extension). - require("telescope").setup(opts) - require("telescope").load_extension("undo") - end, - }, - - { - "folke/which-key.nvim", - config = function() - vim.o.timeout = true - vim.o.timeoutlen = 300 - require("which-key").setup() - end - }, - - -- DAP: debugging - { - 'mfussenegger/nvim-dap', - config = function() - require 'config.nvim-dap' - end - }, - { - 'mfussenegger/nvim-dap-python', - config = function() - require('dap-python').setup(vim.fn.stdpath("data") .. "/mason/packages/debugpy/venv/bin/python") - end - }, - { - "rcarriga/nvim-dap-ui", - dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" }, - config = function() - require 'config.nvim-dap-ui' - end - }, - - { - 'theHamsta/nvim-dap-virtual-text', - dependencies = { "mfussenegger/nvim-dap", "nvim-treesitter/nvim-treesitter" }, - config = function() - require("nvim-dap-virtual-text").setup() - end - }, - - { - 'Eandrju/cellular-automaton.nvim', - config = function() - vim.keymap.set('n', 'q:', '<cmd>CellularAutomaton make_it_rain<CR>') - end - }, - - { - "folke/flash.nvim", - event = "VeryLazy", - ---@type Flash.Config - opts = { - search = { - trigger = "\\", - } - }, - -- stylua: ignore - keys = { - { "<leader><leader>s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, - { "<leader>S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, - { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, - { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, - { "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, - }, - }, - - { - 'mhartington/formatter.nvim', - config = function() - require("formatter").setup { - filetype = { yaml = { require("formatter.filetypes.yaml").yamlfmt } } - } - end, - }, - - { - "ray-x/lsp_signature.nvim", - event = "VeryLazy", - opts = {}, - config = function(_, opts) require 'lsp_signature'.setup(opts) end - }, - - -- LSP diagnostics at your corner. - -- Messes up visual selection.. - -- { 'RaafatTurki/corn.nvim', - -- opts = {}, - -- }, - { - 'dgagn/diagflow.nvim', - opts = {}, - event = "VeryLazy", - }, - - { - 'stevearc/aerial.nvim', - opts = { - backends = { "lsp", "treesitter", "markdown", "man" }, - filter_kind = false, - }, - -- Optional dependencies - dependencies = { - "nvim-treesitter/nvim-treesitter", - "nvim-tree/nvim-web-devicons" - }, - keys = { - { "<leader>tt", "<cmd>AerialToggle!<cr>", desc = "Toggle tagbar" }, - { "<leader>to", "<cmd>AerialOpen<cr>", desc = "Open and jump to tagbar" }, - }, - }, - { - "nvim-treesitter/nvim-treesitter-context", - dependencies = { "nvim-treesitter/nvim-treesitter" }, - opts = { - enable = false, - }, - keys = { - { "<leader>^", function() require('treesitter-context').toggle() end, desc = "Context" }, - }, - }, - - -- diagnostics - { - "folke/trouble.nvim", - branch = "dev", -- IMPORTANT! - keys = { - { - "<leader>xx", - "<cmd>Trouble diagnostics toggle<cr>", - desc = "Diagnostics (Trouble)", - }, - { - "<leader>xb", - "<cmd>Trouble diagnostics toggle filter.buf=0<cr>", - desc = "Buffer Diagnostics (Trouble)", - }, - { - "<leader>xs", - "<cmd>Trouble symbols toggle focus=false<cr>", - desc = "Symbols (Trouble)", - }, - { - "<leader>xd", - "<cmd>Trouble lsp toggle focus=false win.position=right<cr>", - desc = "LSP Definitions / references / ... (Trouble)", - }, - { - "<leader>xl", - "<cmd>Trouble loclist toggle<cr>", - desc = "Location List (Trouble)", - }, - { - "<leader>xq", - "<cmd>Trouble qflist toggle<cr>", - desc = "Quickfix List (Trouble)", - }, - }, - opts = {}, -- for default options, refer to the configuration section for custom setup. - }, - { - "echasnovski/mini.align", - opts = { - mappings = { - start_with_preview = 'ga', - }, - }, - }, - { - "echasnovski/mini.ai", - opts = {}, - event = "VeryLazy", - }, - { - "echasnovski/mini.animate", - config = function() - local animate = require('mini.animate') - animate.setup({ - cursor = { - enable = false, - }, - scroll = { - enable = true, - timing = animate.gen_timing.linear({ duration = 50, unit = 'total' }), - }, - resize = { - enable = false, - }, - open = { - enable = false, - }, - close = { - enable = false, - }, - }) - end, - version = false, - }, - { - "m00qek/baleia.nvim", - version = "*", - config = function() - vim.g.baleia = require("baleia").setup({}) - - -- Command to colorize the current buffer - vim.api.nvim_create_user_command("BaleiaColorize", function() - vim.g.baleia.once(vim.api.nvim_get_current_buf()) - end, { bang = true }) - - -- Command to show logs - vim.api.nvim_create_user_command("BaleiaLogs", vim.g.baleia.logger.show, { bang = true }) - end, - }, - { -- Autoformat - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - keys = { - { - 'gQ', - function() - require('conform').format { async = true, lsp_fallback = true } - end, - mode = '', - desc = '[F]ormat buffer', - }, - }, - opts = { - notify_on_error = false, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } - return { - timeout_ms = 500, - lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], - } - end, - formatters = { - ruff_format = { - inherit = true, - append_args = { "--config", "~/Documents/cdmi/automation/meta-files/ruff.toml" }, - }, - }, - formatters_by_ft = { - rust = { "rustfmt", lsp_format = "fallback" }, - ruby = { "rubyfmt", lsp_format = "fallback" }, - python = { "ruff_format", "ruff_organize_imports", lsp_format = "fallback" }, - lua = { "stylua" }, - -- python = { "black", lsp_format = "fallback" }, - -- -- lua = { 'stylua' }, - -- -- Conform can also run multiple formatters sequentially - -- -- python = { "isort", "black" }, - -- -- - -- -- You can use 'stop_after_first' to run the first available formatter from the list - -- -- javascript = { "prettierd", "prettier", stop_after_first = true }, - }, - }, - }, - { - 'sphamba/smear-cursor.nvim', - opts = { - cursor_color = '#a4a4a4', - legacy_computing_symbols_support = true, - stiffness = 0.8, -- 0.6 [0, 1] - trailing_stiffness = 0.5, -- 0.3 [0, 1] - distance_stop_animating = 0.5, -- 0.1 > 0 - }, - }, - { - 'max397574/colortils.nvim', - event = "VeryLazy", - opts = { - register = "0", - }, - }, -} diff --git a/nvim/lua/plugins/aerial.lua b/nvim/lua/plugins/aerial.lua @@ -0,0 +1,17 @@ +-- Code outline +return { + 'stevearc/aerial.nvim', + opts = { + backends = { "lsp", "treesitter", "markdown", "man" }, + filter_kind = false, + }, + -- Optional dependencies + dependencies = { + "nvim-treesitter/nvim-treesitter", + "nvim-tree/nvim-web-devicons" + }, + keys = { + { "<leader>tt", "<cmd>AerialToggle!<cr>", desc = "Toggle tagbar" }, + { "<leader>to", "<cmd>AerialOpen<cr>", desc = "Open and jump to tagbar" }, + }, +} diff --git a/nvim/lua/plugins/completion.lua b/nvim/lua/plugins/completion.lua @@ -0,0 +1,53 @@ +return { + 'saghen/blink.cmp', + -- optional: provides snippets for the snippet source + -- dependencies = { 'rafamadriz/friendly-snippets' }, + + -- use a release tag to download pre-built binaries + version = '1.*', + + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept) + -- 'super-tab' for mappings similar to vscode (tab to accept) + -- 'enter' for enter to accept + -- 'none' for no mappings + -- + -- All presets have the following mappings: + -- C-space: Open menu or open docs if already open + -- C-n/C-p or Up/Down: Select next/previous item + -- C-e: Hide menu + -- C-k: Toggle signature help (if signature.enabled = true) + -- + -- See :h blink-cmp-config-keymap for defining your own keymap + keymap = { preset = 'enter' }, + + appearance = { + -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = 'mono' + }, + + -- (Default) Only show the documentation popup when manually triggered + completion = { documentation = { auto_show = false } }, + + -- Default list of enabled providers defined so that you can extend it + -- elsewhere in your config, without redefining it, due to `opts_extend` + sources = { + default = { 'lsp', 'path', 'snippets', 'buffer' }, + }, + + signature = { + enabled = true + }, + + -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance + -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation, + -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"` + -- + -- See the fuzzy documentation for more information + fuzzy = { implementation = "prefer_rust_with_warning" } + }, + opts_extend = { "sources.default" } +} diff --git a/nvim/lua/plugins/formatting.lua b/nvim/lua/plugins/formatting.lua @@ -0,0 +1,48 @@ +-- Autoformat +return { + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { + 'gQ', + function() + require('conform').format { async = true, lsp_fallback = true } + end, + mode = '', + desc = '[F]ormat buffer', + }, + }, + opts = { + notify_on_error = false, + format_on_save = function(bufnr) + -- Disable "format_on_save lsp_fallback" for languages that don't + -- have a well standardized coding style. You can add additional + -- languages here or re-enable it for the disabled ones. + local disable_filetypes = { c = true, cpp = true } + return { + timeout_ms = 500, + lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], + } + end, + formatters = { + ruff_format = { + inherit = true, + append_args = { "--config", "~/Documents/cdmi/automation/meta-files/ruff.toml" }, + }, + }, + formatters_by_ft = { + rust = { "rustfmt", lsp_format = "fallback" }, + ruby = { "rubyfmt", lsp_format = "fallback" }, + python = { "ruff_format", "ruff_organize_imports", lsp_format = "fallback" }, + lua = { "stylua" }, + -- python = { "black", lsp_format = "fallback" }, + -- -- lua = { 'stylua' }, + -- -- Conform can also run multiple formatters sequentially + -- -- python = { "isort", "black" }, + -- -- + -- -- You can use 'stop_after_first' to run the first available formatter from the list + -- -- javascript = { "prettierd", "prettier", stop_after_first = true }, + }, + }, +} diff --git a/nvim/lua/plugins/gitsigns.lua b/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1,21 @@ +return +{ + 'lewis6991/gitsigns.nvim', + opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + on_attach = function() + vim.keymap.set('n', ']c', function() require('gitsigns').next_hunk() end, { buffer = true }) + vim.keymap.set('n', '[c', function() require('gitsigns').prev_hunk() end, { buffer = true }) + vim.keymap.set('n', ']=', function() require('gitsigns').toggle_deleted() end, { buffer = true }) + vim.keymap.set('n', ']~', function() require('gitsigns').diffthis() end, { buffer = true }) + vim.keymap.set('n', ']-', function() require('gitsigns').preview_hunk() end, { buffer = true }) + vim.keymap.set('n', ']+', function() require('gitsigns').select_hunk() end, { buffer = true }) + end, + }, +} diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua @@ -0,0 +1,108 @@ +return { + { + 'stevearc/dressing.nvim', + opts = {}, + }, + + + + { -- Add indentation guides even on blank lines + 'lukas-reineke/indent-blankline.nvim', + main = 'ibl', + opts = { + indent = { + char = '┊', + }, + } + }, + + 'numToStr/Comment.nvim', -- "gc" to comment visual regions/lines + + { + "folke/which-key.nvim", + config = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + require("which-key").setup() + end + }, + + + { + 'Eandrju/cellular-automaton.nvim', + config = function() + vim.keymap.set('n', 'q:', '<cmd>CellularAutomaton make_it_rain<CR>') + end + }, + + { + "echasnovski/mini.align", + opts = { + mappings = { + start_with_preview = 'ga', + }, + }, + }, + { + "echasnovski/mini.ai", + opts = {}, + event = "VeryLazy", + }, + { + "echasnovski/mini.animate", + config = function() + local animate = require('mini.animate') + animate.setup({ + cursor = { + enable = false, + }, + scroll = { + enable = true, + timing = animate.gen_timing.linear({ duration = 50, unit = 'total' }), + }, + resize = { + enable = false, + }, + open = { + enable = false, + }, + close = { + enable = false, + }, + }) + end, + version = false, + }, + { + "m00qek/baleia.nvim", + version = "*", + config = function() + vim.g.baleia = require("baleia").setup({}) + + -- Command to colorize the current buffer + vim.api.nvim_create_user_command("BaleiaColorize", function() + vim.g.baleia.once(vim.api.nvim_get_current_buf()) + end, { bang = true }) + + -- Command to show logs + vim.api.nvim_create_user_command("BaleiaLogs", vim.g.baleia.logger.show, { bang = true }) + end, + }, + { + 'sphamba/smear-cursor.nvim', + opts = { + cursor_color = '#a4a4a4', + legacy_computing_symbols_support = true, + stiffness = 0.8, -- 0.6 [0, 1] + trailing_stiffness = 0.5, -- 0.3 [0, 1] + distance_stop_animating = 0.5, -- 0.1 > 0 + }, + }, + { + 'max397574/colortils.nvim', + event = "VeryLazy", + opts = { + register = "0", + }, + }, +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,209 @@ +-- LSP settings. +-- This function gets run when an LSP connects to a particular buffer. +local on_attach = function(_, bufnr) + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, 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>ra', vim.lsp.buf.code_action, '[C]ode [A]ction') + vim.keymap.set('v', '<leader>ra', vim.lsp.buf.code_action, { buffer = bufnr, desc = '[C]ode [A]ction' }) + + nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') + nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') + nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') + nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + + -- See `:help K` for why this keymap + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('<leader>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' }) + + vim.api.nvim_buf_create_user_command(bufnr, 'LspInspect', function(_) + vim.ui.input({ prompt = 'Enter LSP Client name: ' }, function(client_name) + if client_name then + local client = vim.lsp.get_clients { name = client_name } + + if #client == 0 then + vim.notify('No active LSP clients found with this name: ' .. client_name, vim.log.levels.WARN) + return + end + + -- Create a temporary buffer to show the configuration + local buf = vim.api.nvim_create_buf(false, true) + local win = vim.api.nvim_open_win(buf, true, { + relative = 'editor', + width = math.floor(vim.o.columns * 0.75), + height = math.floor(vim.o.lines * 0.90), + col = math.floor(vim.o.columns * 0.125), + row = math.floor(vim.o.lines * 0.05), + style = 'minimal', + border = 'rounded', + title = ' ' .. (client_name:gsub('^%l', string.upper)) .. ': LSP Configuration ', + title_pos = 'center', + }) + + local lines = {} + for i, this_client in ipairs(client) do + if i > 1 then + table.insert(lines, string.rep('-', 80)) + end + table.insert(lines, 'Client: ' .. this_client.name) + table.insert(lines, 'ID: ' .. this_client.id) + table.insert(lines, '') + table.insert(lines, 'Configuration:') + + local config_lines = vim.split(vim.inspect(this_client.config), '\n') + vim.list_extend(lines, config_lines) + end + + -- Set the lines in the buffer + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) + + -- Set buffer options + vim.bo[buf].modifiable = false + vim.bo[buf].filetype = 'lua' + vim.bo[buf].bh = 'delete' + + vim.api.nvim_buf_set_keymap(buf, 'n', 'q', ':q<CR>', { noremap = true, silent = true }) + end + end) + end, { desc = 'Inspect LSP config' }) +end + +-- :h lspconfig-all +local config = function() + vim.lsp.config('rust_analyzer', { + on_attach = on_attach, + settings = { + ['rust-analyzer'] = { + check = { + command = "clippy", + features = "all", + extraArgs = { + "--", + "-D", "clippy::pedantic", + "-D", "clippy::nursery", + "-D", "clippy::restriction", + "-A", "clippy::blanket_clippy_restriction_lints", + "-A", "clippy::missing_docs_in_private_items", + "-A", "clippy::implicit_return", + "-A", "clippy::question_mark_used", + "-A", "clippy::min_ident_chars", + "-A", "clippy::pattern_type_mismatch", + "-A", "clippy::single_call_fn", + "-A", "clippy::as_conversions", + "-A", "clippy::pub_with_shorthand", + "-A", "clippy::shadow_reuse", + "-A", "clippy::separated_literal_suffix", + "-A", "clippy::float_arithmetic", + "-A", "clippy::pub_use", + "-A", "clippy::single_char_lifetime_names", + "-A", "clippy::missing_trait_methods", + "-A", "clippy::multiple_unsafe_ops_per_block", -- broken on 0.1.74 + "-A", "clippy::mod_module_files", + "-A", "clippy::std_instead_of_alloc", + "-A", "clippy::integer_division_remainder_used", + "-D", "rust_2018_idioms", + "-D", "missing_docs", + "-D", "warnings", + "-A", "clippy::too_many_lines", + "-A", "clippy::arbitrary_source_item_ordering", + }, + } + } + }, + }) + vim.lsp.enable('rust_analyzer') + + vim.lsp.config('bacon_ls', { + on_attach = on_attach, + init_options = { + updateOnSave = true, + updateOnSaveWaitMillis = 3000, + updateOnChange = true, + }, + }) + --[[ + Some issues I found: + - bacon-ls kept running after vim closed + - diagnostics did not update, the old ones showed, I had to :e to refresh + --]] + -- vim.lsp.enable('bacon_ls') + + vim.lsp.config('yamlls', { on_attach = on_attach }) + vim.lsp.enable('yamlls') + + vim.lsp.config('nixd', { on_attach = on_attach }) + vim.lsp.enable('nixd') + + vim.lsp.config('lua_ls', { + on_attach = on_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + 'vim', + 'require' + }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + } + } + }) + vim.lsp.enable('lua_ls') + + vim.lsp.enable('basedpyright') + + vim.lsp.config('vue_ls', { + -- add filetypes for typescript, javascript and vue + filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, + }) + vim.lsp.enable('vue_ls') +end + +return { + 'neovim/nvim-lspconfig', + config = config, + dependencies = { + -- Useful status updates for LSP. + { 'j-hui/fidget.nvim', opts = {} }, + } +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,72 @@ +-- Fuzzy Finder (files, lsp, etc) +local configure_telescope = function() + require('telescope').setup { + defaults = { + mappings = { + i = { + ['<C-u>'] = false, + ['<C-d>'] = false, + }, + }, + }, + } + -- Call this after telescope's setup + pcall(require('telescope').load_extension, 'fzf') + + -- Disable folding in Telescope's result window. + vim.api.nvim_create_autocmd("FileType", + { pattern = "TelescopeResults", command = [[setlocal nofoldenable foldlevelstart=99]] }) + + local map = function(keys, desc, func, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { desc = desc }) + end + local tsbuiltin = require 'telescope.builtin' + + map('<leader>sp', '[S]earch [p]reviously opened files', require('telescope.builtin').oldfiles) + map('<leader>b', 'Find existing buffers', require('telescope.builtin').buffers) + map('<leader>sf', '[S]earch [F]iles', require('telescope.builtin').find_files) + map('<leader>cv', 'Neovim configs', + function() require('telescope.builtin').find_files({ cwd = vim.env.DOTFILES .. '/nvim' }) end) + map('<leader>sh', '[S]earch [H]elp', require('telescope.builtin').help_tags) + map('<leader>sw', '[S]earch current [W]ord', require('telescope.builtin').grep_string) + map('<leader>sg', '[S]earch by [G]rep', require('telescope.builtin').live_grep) + map('<leader>sd', '[S]earch [D]iagnostics', require('telescope.builtin').diagnostics) + map('<leader>sr', '[S]earch [R]eferences', require('telescope.builtin').lsp_references) + map('<leader>s<', '[S]earch [I]ncoming calls', require('telescope.builtin').lsp_incoming_calls) + map('<leader>s>', '[S]earch [O]utgoing calls', require('telescope.builtin').lsp_outgoing_calls) + map('<leader>st', '[Search] [T]his buffer', require('telescope.builtin').current_buffer_fuzzy_find) + map('<leader>sI', '[S]earch [i]mplementations', require('telescope.builtin').lsp_implementations) + map('<leader>sj', '[S]earch [J]umplist', require('telescope.builtin').jumplist) + map('<leader>ss', '[S]earch [S]ymbols', function() + local server_ready = not not vim.lsp.buf_notify(0, '$/progress', {}) + if server_ready then + require('telescope.builtin').lsp_dynamic_workspace_symbols() + else + require('telescope.builtin').treesitter() + end + end) + map('<leader>sb', 'Telescope [T]ags', function() + local server_ready = not not vim.lsp.buf_notify(0, '$/progress', {}) + if server_ready then + require('telescope.builtin').lsp_document_symbols() + else + require('telescope.builtin').tags() + end + end) +end + +return { + { + 'nvim-telescope/telescope.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = configure_telescope, + }, + -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'make', + cond = vim.fn.executable 'make' == 1 + }, + +} diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,89 @@ +-- Highlight, edit, and navigate code +local config = function() + require('nvim-treesitter.configs').setup { + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'vim', 'vimdoc', 'bash', 'ledger', 'ruby', + 'python', 'java', 'sql', 'markdown_inline', 'html' }, + + highlight = { enable = true }, + indent = { enable = true, disable = { 'python' } }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '<c-space>', + node_incremental = '<c-space>', + scope_incremental = '<c-s>', + node_decremental = '<c-+>', + }, + }, + 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 +return { + { + 'nvim-treesitter/nvim-treesitter', + branch = 'master', + build = ":TSUpdate", + config = config, + lazy = false, + }, + + -- Additional text objects via treesitter + 'nvim-treesitter/nvim-treesitter-textobjects', + + -- Show context + { + "nvim-treesitter/nvim-treesitter-context", + dependencies = { "nvim-treesitter/nvim-treesitter" }, + -- opts = { + -- enable = false, + -- }, + -- keys = { + -- { "<leader>^", require('treesitter-context').toggle, desc = "Context" }, + -- }, + }, + +} diff --git a/nvim/lua/plugins/trouble.lua b/nvim/lua/plugins/trouble.lua @@ -0,0 +1,38 @@ +-- diagnostics +return { + "folke/trouble.nvim", + opts = {}, -- for default options, refer to the configuration section for custom setup. + cmd = "Trouble", + keys = { + { + "<leader>xx", + "<cmd>Trouble diagnostics toggle<cr>", + desc = "Diagnostics (Trouble)", + }, + { + "<leader>xb", + "<cmd>Trouble diagnostics toggle filter.buf=0<cr>", + desc = "Buffer Diagnostics (Trouble)", + }, + { + "<leader>xs", + "<cmd>Trouble symbols toggle focus=false<cr>", + desc = "Symbols (Trouble)", + }, + { + "<leader>xd", + "<cmd>Trouble lsp toggle focus=false win.position=right<cr>", + desc = "LSP Definitions / references / ... (Trouble)", + }, + { + "<leader>xl", + "<cmd>Trouble loclist toggle<cr>", + desc = "Location List (Trouble)", + }, + { + "<leader>xq", + "<cmd>Trouble qflist toggle<cr>", + desc = "Quickfix List (Trouble)", + }, + }, +}