From 8c56556c8683c928f2070fe81e7c8f9812da693f Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Sun, 15 Sep 2024 11:21:15 -0400 Subject: [PATCH] moved ftplugins, and fixed some plugins --- .stylua.toml | 1 - ftplugin/lua.lua | 6 +- ftplugin/markdown.lua | 88 +++++++++++++ ftplugin/tex.lua | 98 +++++++++++++-- lua/config/autocmds.lua | 31 +---- lua/config/mappings.lua | 6 +- lua/config/options.lua | 26 ++-- lua/custom/plugins/auto-dark-mode.lua | 11 +- lua/custom/plugins/autopairs.lua | 1 - lua/custom/plugins/cmp.lua | 152 +++++++++++++--------- lua/custom/plugins/comments.lua | 1 - lua/custom/plugins/copilot.lua | 1 - lua/custom/plugins/dadbod.lua | 15 ++- lua/custom/plugins/dap.lua | 160 ++++++++++++++++-------- lua/custom/plugins/formatting.lua | 56 ++++++--- lua/custom/plugins/gitsigns.lua | 4 +- lua/custom/plugins/linting.lua | 17 +-- lua/custom/plugins/lsp-config.lua | 28 +++-- lua/custom/plugins/markdown-preview.lua | 4 - lua/custom/plugins/neogen.lua | 17 ++- lua/custom/plugins/solarized.lua | 3 +- lua/custom/plugins/todo-notes.lua | 7 ++ lua/custom/plugins/which-key.lua | 89 ++++++++++--- 23 files changed, 578 insertions(+), 244 deletions(-) create mode 100644 ftplugin/markdown.lua delete mode 100644 lua/custom/plugins/markdown-preview.lua create mode 100644 lua/custom/plugins/todo-notes.lua diff --git a/.stylua.toml b/.stylua.toml index b14df1da..77c3370a 100755 --- a/.stylua.toml +++ b/.stylua.toml @@ -8,4 +8,3 @@ collapse_simple_statement = "Never" [sort_requires] enabled = false - diff --git a/ftplugin/lua.lua b/ftplugin/lua.lua index de7c1ff5..5278e6f1 100644 --- a/ftplugin/lua.lua +++ b/ftplugin/lua.lua @@ -1,7 +1,7 @@ vim.opt.expandtab = true -vim.opt.shiftwidth = 4 -vim.opt.tabstop = 4 -vim.opt.expandtab = true +vim.opt.shiftwidth = 2 +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 vim.opt_local.formatoptions:remove('o') diff --git a/ftplugin/markdown.lua b/ftplugin/markdown.lua new file mode 100644 index 00000000..d0e32fa2 --- /dev/null +++ b/ftplugin/markdown.lua @@ -0,0 +1,88 @@ +-- markdown.lua + +-- Update PATH to include TeX binaries +vim.env.PATH = vim.env.PATH .. ':/Library/TeX/texbin' + +-- Utility function to create directories if they do not exist +local function ensure_directory_exists(path) + if not vim.fn.isdirectory(path) then + vim.fn.mkdir(path, 'p') + end +end + +-- Generate the PDF target directory and file paths +local function generate_pdf_paths(filename) + local base_dir = vim.fn.fnamemodify(filename, ':h') + local target_dir = base_dir:gsub('/src$', '/pdf') + local output_file = vim.fn.fnamemodify(filename, ':t:r') .. '.pdf' + local output_path = target_dir .. '/' .. output_file + + -- Ensure the target directory exists + ensure_directory_exists(target_dir) + + return target_dir, output_file, output_path +end + +-- Build PDF using the buildnote script +local function build_pdf(filename, output_path) + local command = string.format('buildnote %s %s', vim.fn.shellescape(filename), vim.fn.shellescape(output_path)) + return vim.fn.systemlist(command) +end + +-- Check if Zathura is running and open it if not +local function open_pdf_in_zathura(pdf_path) + local zathura_running = vim.fn.systemlist('pgrep -f "zathura ' .. vim.fn.shellescape(pdf_path) .. '"') + + if #zathura_running == 0 then + vim.fn.jobstart({ 'zathura', pdf_path }, { detach = true, stdout = 'null', stderr = 'null' }) + print('Opening PDF in Zathura: ' .. pdf_path) + else + print('Zathura is already running for this file.') + end +end + +-- Keybinding to build the PDF and view it in Zathura +vim.keymap.set('n', 'lv', function() + local filename = vim.fn.expand('%:p') + local _, _, output_path = generate_pdf_paths(filename) + + -- Build the PDF + local result = build_pdf(filename, output_path) + + if #result == 0 then + print('Error: Could not generate PDF.') + return + end + + -- Open the PDF in Zathura + open_pdf_in_zathura(output_path) +end, { + desc = 'View output PDF in Zathura', + noremap = true, + silent = true, +}) + +-- Autocmd to close all Zathura instances related to the current file when exiting Neovim +vim.api.nvim_create_autocmd('VimLeavePre', { + callback = function() + local _, _, output_path = generate_pdf_paths(vim.fn.expand('%:p')) + vim.fn.system({ 'pkill', '-f', 'zathura ' .. output_path }) + end, +}) + +-- Auto-run `buildnote` for files matching `*note-*.md` on save +vim.api.nvim_create_autocmd('BufWritePost', { + pattern = '*note-*.md', + callback = function() + local filename = vim.fn.expand('%:p') + local _, _, output_path = generate_pdf_paths(filename) + + if vim.fn.filereadable(filename) == 1 then + -- Execute the buildnote script to generate the PDF + local command = string.format('buildnote %s %s', vim.fn.shellescape(filename), vim.fn.shellescape(output_path)) + vim.cmd('silent !' .. command) + else + print('Error: File ' .. filename .. ' does not exist.') + end + end, +}) diff --git a/ftplugin/tex.lua b/ftplugin/tex.lua index bcdde064..ca034529 100644 --- a/ftplugin/tex.lua +++ b/ftplugin/tex.lua @@ -1,21 +1,103 @@ +-- LaTeX keybindings and Zathura management + -- Keybinding to compile LaTeX to PDF using xelatex with latexmk and output to the "output" directory -vim.keymap.set('n', 'll', ':!mkdir -p output && latexmk -pdf -xelatex -output-directory=output -synctex=1 %', +vim.keymap.set( + 'n', + 'll', + ':!mkdir -p output && latexmk -pdf -xelatex -output-directory=output -synctex=1 %', { desc = 'Compile LaTeX to PDF using xelatex with SyncTeX in the output directory', noremap = true, - silent = true - }) + silent = true, + } +) -- Keybinding to view the compiled PDF in Zathura from the output directory vim.keymap.set('n', 'lv', function() - local pdf_path = vim.fn.expand('%:p:h') .. '/output/' .. vim.fn.expand('%:t:r') .. '.pdf' - vim.cmd(':silent !nohup zathura ' .. pdf_path .. ' >/dev/null 2>&1 &') + local pdf_path = vim.fn.expand('%:p:h/output/%:t:r.pdf') + + -- Check if Zathura is already running for this PDF + local zathura_running = vim.fn.systemlist('pgrep -f "zathura ' .. pdf_path .. '"') + + if #zathura_running == 0 then + -- Start Zathura if it's not already running for this PDF + vim.fn.jobstart({ 'zathura', pdf_path }, { detach = true, stdout = 'null', stderr = 'null' }) + else + print('Zathura is already running for this file.') + end end, { desc = 'View PDF in Zathura from the output directory', noremap = true, - silent = true + silent = true, }) --- Custom surroundings for LaTeX -vim.g.surround_110 = "\\begin{\r}\n\\end{\r}" -- map `yssn` for \begin{} \end{} +-- Function to close the Zathura instance for the current PDF +local function close_zathura() + local pdf_path = vim.fn.expand('%:p:h') .. '/output/' .. vim.fn.expand('%:t:r') .. '.pdf' + -- Terminate Zathura process associated with the PDF + vim.fn.system({ 'pkill', '-f', 'zathura ' .. pdf_path }) +end +-- Keybinding to close Zathura for the current PDF +vim.keymap.set( + 'n', + 'lc', -- Replace with your preferred key combination + close_zathura, + { + desc = 'Close Zathura instance for the current PDF', + noremap = true, + silent = true, + } +) + +-- Prevent multiple Zathura instances and add cooldown period +local last_open_time = 0 +local cooldown_period = 5 -- Cooldown period in seconds +local max_instances = 5 +local zathura_pids = {} +local auto_close_min = 180 + +-- Function to schedule Zathura closure after a delay in minutes +local function schedule_close_zathura(minutes) + local delay_ms = minutes * 60 * 1000 -- Convert minutes to milliseconds + vim.defer_fn(close_zathura, delay_ms) +end + +-- Autocmd to automatically open the PDF in Zathura when a .tex file is opened +vim.api.nvim_create_autocmd('BufEnter', { + pattern = '*.tex', + callback = function() + local current_time = vim.fn.reltimefloat(vim.fn.reltime()) + if current_time - last_open_time < cooldown_period then + print('Cooldown active, skipping Zathura launch.') + return + end + + last_open_time = current_time + + if #zathura_pids >= max_instances then + print('Maximum number of Zathura instances reached.') + return + end + + local pdf_path = vim.fn.expand('%:p:h') .. '/output/' .. vim.fn.expand('%:t:r') .. '.pdf' + local zathura_running = vim.fn.systemlist('pgrep -f "zathura ' .. pdf_path .. '"') + + if #zathura_running == 0 and vim.fn.filereadable(pdf_path) == 1 then + local job_id = vim.fn.jobstart({ 'zathura', pdf_path }, { detach = true }) + table.insert(zathura_pids, job_id) + -- Schedule the closure of Zathura after 180 minutes (3 hours) + schedule_close_zathura(auto_close_min) + else + print('Zathura is already running for this file or PDF not found.') + end + end, +}) + +-- Autocmd to close all Zathura instances related to the current file when exiting Neovim +vim.api.nvim_create_autocmd('VimLeavePre', { + callback = function() + local pdf_path = vim.fn.expand('%:p:h') .. '/output/' .. vim.fn.expand('%:t:r') .. '.pdf' + vim.fn.system({ 'pkill', '-f', 'zathura ' .. pdf_path }) + end, +}) diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index 7f7c33f9..f40f0425 100755 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -1,10 +1,10 @@ -- Auto-format on save -vim.cmd [[ +vim.cmd([[ augroup FormatOnSave autocmd! autocmd BufWritePre * lua vim.lsp.buf.format({ async = false }) augroup END -]] +]]) -- Augroup for Highlight on yank vim.cmd([[ @@ -63,30 +63,3 @@ vim.cmd([[ autocmd TermOpen * normal! G autocmd TermOpen * tnoremap ]]) - --- Open PDF in the background when a .tex file is opened -vim.api.nvim_create_autocmd("BufEnter", { - pattern = "*.tex", - callback = function() - -- Construct an absolute path to the PDF file - local pdf_path = vim.fn.expand('%:p:h') .. "/output/" .. vim.fn.expand('%:t:r') .. '.pdf' - if vim.fn.filereadable(pdf_path) == 1 then - -- Start Zathura asynchronously in the background with an absolute path - vim.fn.jobstart({ 'nohup', 'zathura', pdf_path, '>/dev/null', '2>&1', '&' }, { detach = true }) - else - print("PDF file not found: " .. pdf_path) - end - end, -}) - --- Close Zathura gracefully when leaving Neovim -vim.api.nvim_create_autocmd("VimLeavePre", { - callback = function() - -- Attempt to terminate Zathura gracefully with a grace period - vim.fn.system({ 'pkill', '-TERM', '-f', 'zathura' }) - vim.defer_fn(function() - vim.fn.system({ 'pkill', '-KILL', '-f', 'zathura' }) - end, 2000) -- Wait for 2 seconds before force killing if necessary - end, -}) - diff --git a/lua/config/mappings.lua b/lua/config/mappings.lua index 349f8837..837d663e 100755 --- a/lua/config/mappings.lua +++ b/lua/config/mappings.lua @@ -6,6 +6,7 @@ local utils = require('config.utils') vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) -- vim.keymap.set('n', 'pv', vim.cmd.Ex, { desc = "[P]roject [V]iew" }) vim.keymap.set('n', '', '', { silent = true }) +vim.keymap.set('n', '', 'nohlsearch', { silent = true }) -- Remap for dealing with word wrap vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) @@ -21,8 +22,8 @@ vim.keymap.set('n', '<', '', 'zz', { desc = 'Half Page Jumping Up' }) vim.keymap.set('n', '', 'zz', { desc = 'Half Page Jumping Down' }) -vim.keymap.set('n', 'n', 'nzzzv', { silent = true }) -vim.keymap.set('n', 'N', 'Nzzzv', { silent = true }) +vim.keymap.set('n', 'n', 'nzzzv', { noremap = true, silent = true }) +vim.keymap.set('n', 'N', 'Nzzzv', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', 'gp', '', { noremap = true, silent = true }) vim.keymap.set('n', '', 'cnextzz') vim.keymap.set('n', '', 'cprevzz') @@ -133,4 +134,3 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnos -- { noremap = true, silent = true, expr = false, desc = "Extract Block" }) -- vim.keymap.set({ "n" }, "rbf", [[lua require('refactoring').refactor('Extract Block To File')]], -- { noremap = true, silent = true, expr = false, desc = "Extract Block To File" }) - diff --git a/lua/config/options.lua b/lua/config/options.lua index 9ab0d2d3..7a60ed46 100755 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -54,6 +54,15 @@ local opts = { termguicolors = true, scrolloff = 10, pyxversion = 3, + + -- Sets how neovim will display certain whitespace characters in the editor. + -- See :help 'list' + -- and :help 'listchars' + list = true, + listchars = { tab = ' ', trail = '·', nbsp = '␣' }, + + -- Preview substitutions live, as you type! + inccommand = 'split', } for k, v in pairs(opts) do @@ -116,12 +125,11 @@ end opt.formatoptions = 'l' opt.formatoptions = opt.formatoptions - - 'a' -- Auto formatting is BAD. - - 't' -- Don't auto format my code. I got linters for that. - + 'c' -- In general, I like it when comments respect textwidth - - 'o' -- O and o, don't continue comments - + 'r' -- But do continue when pressing enter. - + 'n' -- Indent past the formatlistpat, not underneath it. - + 'j' -- Auto-remove comments if possible. - - '2' -- I'm not in gradeschool anymore - + - 'a' -- Auto formatting is BAD. + - 't' -- Don't auto format my code. I got linters for that. + + 'c' -- In general, I like it when comments respect textwidth + - 'o' -- O and o, don't continue comments + + 'r' -- But do continue when pressing enter. + + 'n' -- Indent past the formatlistpat, not underneath it. + + 'j' -- Auto-remove comments if possible. + - '2' -- I'm not in gradeschool anymore diff --git a/lua/custom/plugins/auto-dark-mode.lua b/lua/custom/plugins/auto-dark-mode.lua index 8a0d2c18..6a5786e7 100755 --- a/lua/custom/plugins/auto-dark-mode.lua +++ b/lua/custom/plugins/auto-dark-mode.lua @@ -1,19 +1,14 @@ return { 'f-person/auto-dark-mode.nvim', - event = 'VimEnter', -- Lazy load on VimEnter event opts = { - update_interval = 1000, -- Check for mode change every second + update_interval = 2000, set_dark_mode = function() + vim.api.nvim_set_option_value('background', 'dark', {}) vim.cmd('colorscheme monokai') - vim.cmd('set background=dark') -- Ensure the background is set correctly end, set_light_mode = function() + vim.api.nvim_set_option_value('background', 'light', {}) vim.cmd('colorscheme solarized') - vim.cmd('set background=light') end, }, - config = function(_, opts) - require('auto-dark-mode').setup(opts) - end } - diff --git a/lua/custom/plugins/autopairs.lua b/lua/custom/plugins/autopairs.lua index 93085d0b..997e5345 100755 --- a/lua/custom/plugins/autopairs.lua +++ b/lua/custom/plugins/autopairs.lua @@ -10,4 +10,3 @@ return { cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) end, } - diff --git a/lua/custom/plugins/cmp.lua b/lua/custom/plugins/cmp.lua index 9244fe9c..0708a76e 100755 --- a/lua/custom/plugins/cmp.lua +++ b/lua/custom/plugins/cmp.lua @@ -3,29 +3,64 @@ return { 'hrsh7th/nvim-cmp', dependencies = { -- Snippet Engine & its associated nvim-cmp source - 'L3MON4D3/LuaSnip', - 'saadparwaiz1/cmp_luasnip', + { 'L3MON4D3/LuaSnip', lazy = true }, + { 'saadparwaiz1/cmp_luasnip', lazy = true }, -- Adds LSP completion capabilities - 'hrsh7th/cmp-nvim-lsp', + { 'hrsh7th/cmp-nvim-lsp' }, -- Adds a number of user-friendly snippets - 'rafamadriz/friendly-snippets', + { 'rafamadriz/friendly-snippets', lazy = true }, - -- Optional sources - 'hrsh7th/cmp-path', - 'hrsh7th/cmp-buffer', + -- Optional sources for path and buffer completion + { 'hrsh7th/cmp-path', lazy = true }, + { 'hrsh7th/cmp-buffer', lazy = true }, + + -- Optional: additional completions for cmdline and git + { 'hrsh7th/cmp-cmdline', lazy = true }, + { 'petertriho/cmp-git', lazy = true }, -- Git completions for commit messages + + -- Optional: icons for completion menu + { 'onsails/lspkind-nvim', lazy = true }, -- Adds nice icons to completion }, event = { 'InsertEnter', 'CmdlineEnter' }, config = function() + local cmp = require('cmp') + local luasnip = require('luasnip') + local lspkind = require('lspkind') + -- Set completion options vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } - -- Import required modules - local cmp = require('cmp') - local luasnip = require('luasnip') + local cmp_mappings = { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), -- Trigger completion + [''] = cmp.mapping.confirm({ select = true }), -- Confirm selection + [''] = 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' }), + [''] = 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' }), + [''] = cmp.mapping.abort(), -- Abort completion + } - -- Setup luasnip + -- Setup LuaSnip configuration luasnip.config.setup({ history = true, updateevents = 'TextChanged,TextChangedI', @@ -39,59 +74,34 @@ return { cmp.setup({ snippet = { expand = function(args) - luasnip.lsp_expand(args.body) + luasnip.lsp_expand(args.body) -- Expand snippets end, }, sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'buffer' }, - { name = 'path' }, + { name = 'nvim_lsp' }, -- LSP completions + { name = 'luasnip' }, -- Snippet completions + { name = 'path' }, -- Path completions + { name = 'buffer' }, -- Buffer completions }), window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), + completion = cmp.config.window.bordered(), -- Border for completion window + documentation = cmp.config.window.bordered(), -- Border for documentation window }, formatting = { fields = { 'abbr', 'kind', 'menu' }, - format = function(entry, item) - local menu_icon = { - nvim_lsp = 'λ', - luasnip = '⋗', - buffer = 'Ω', - path = '🖫', - } - item.menu = menu_icon[entry.source.name] or entry.source.name - return item - end, + format = lspkind.cmp_format({ -- Use lspkind for icons + with_text = true, + menu = { + nvim_lsp = '[LSP]', + luasnip = '[Snip]', + buffer = '[Buffer]', + path = '[Path]', + cmdline = '[Cmd]', + git = '[Git]', + }, + }), }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.confirm({ select = true }), - [''] = 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' }), - [''] = 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' }), - [''] = cmp.mapping.abort(), - }), + mapping = cmp.mapping.preset.insert(cmp_mappings), }) -- Setup for SQL filetype with vim-dadbod-completion @@ -101,6 +111,36 @@ return { { name = 'buffer' }, }), }) + + -- Setup for markdown with buffer-only completions + cmp.setup.filetype('markdown', { + sources = cmp.config.sources({ + { name = 'buffer' }, + }), + }) + + -- Setup for cmdline '/' (search) and ':' (command) mode + cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(cmp_mappings), + sources = { + { name = 'buffer' }, + }, + }) + + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(cmp_mappings), + sources = cmp.config.sources({ + { name = 'path' }, + { name = 'cmdline' }, + }), + }) + + -- Setup git commit message completion + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, + { name = 'buffer' }, + }), + }) end, } - diff --git a/lua/custom/plugins/comments.lua b/lua/custom/plugins/comments.lua index 4db08198..c0865530 100755 --- a/lua/custom/plugins/comments.lua +++ b/lua/custom/plugins/comments.lua @@ -2,4 +2,3 @@ return { 'numToStr/Comment.nvim', opts = {}, } - diff --git a/lua/custom/plugins/copilot.lua b/lua/custom/plugins/copilot.lua index 8631b195..9766fb0e 100755 --- a/lua/custom/plugins/copilot.lua +++ b/lua/custom/plugins/copilot.lua @@ -17,4 +17,3 @@ return { }, }, } - diff --git a/lua/custom/plugins/dadbod.lua b/lua/custom/plugins/dadbod.lua index 688a9134..f897f9e8 100755 --- a/lua/custom/plugins/dadbod.lua +++ b/lua/custom/plugins/dadbod.lua @@ -1,14 +1,17 @@ return { - 'tpope/vim-dadbod', + 'kristijanhusak/vim-dadbod-ui', dependencies = { - 'kristijanhusak/vim-dadbod-ui', - 'kristijanhusak/vim-dadbod-completion', + { 'tpope/vim-dadbod', lazy = true }, + { 'kristijanhusak/vim-dadbod-completion', ft = { 'sql', 'mysql', 'plsql' }, lazy = true }, -- Optional }, - keys = { - { 'du', 'DBUIToggle', { desc = 'Toggle dadbod', noremap = true } }, + cmd = { + 'DBUI', + 'DBUIToggle', + 'DBUIAddConnection', + 'DBUIFindBuffer', }, init = function() + -- Your DBUI configuration vim.g.db_ui_use_nerd_fonts = 1 end, } - diff --git a/lua/custom/plugins/dap.lua b/lua/custom/plugins/dap.lua index 797e65e2..4c27ca10 100755 --- a/lua/custom/plugins/dap.lua +++ b/lua/custom/plugins/dap.lua @@ -1,16 +1,16 @@ return { - -- Add the nvim-dap related plugins + -- add the nvim-dap related plugins { 'mfussenegger/nvim-dap', dependencies = { - { 'rcarriga/nvim-dap-ui', opt = true, cmd = 'DapUI' }, + { 'rcarriga/nvim-dap-ui', opt = true, cmd = 'Dapui' }, { 'nvim-neotest/nvim-nio', opt = true, cmd = 'Neotest' }, - { 'theHamsta/nvim-dap-virtual-text', opt = true, ft = { 'python', 'go', 'rust' } }, + { 'thehamsta/nvim-dap-virtual-text', opt = true, ft = { 'python', 'go', 'rust' } }, { 'mfussenegger/nvim-dap-python', opt = true, ft = 'python' }, { 'leoluz/nvim-dap-go', opt = true, ft = 'go' }, { 'simrat39/rust-tools.nvim', opt = true, ft = 'rust' }, - 'williamboman/mason.nvim', -- Mason for managing external tools - 'williamboman/mason-lspconfig.nvim' + 'williamboman/mason.nvim', -- mason for managing external tools + 'williamboman/mason-lspconfig.nvim', }, config = function() local dap = require('dap') @@ -18,26 +18,16 @@ return { local dap_virtual_text = require('nvim-dap-virtual-text') local mason_registry = require('mason-registry') - -- Initialize dap-ui + -- initialize dap-ui dapui.setup() - -- Initialize dap-virtual-text + -- initialize dap-virtual-text dap_virtual_text.setup() - -- Keybindings - vim.api.nvim_set_keymap('n', 'dc', ':lua require"dap".continue()', { noremap = true, silent = true }) - vim.api.nvim_set_keymap('n', 'ds', ':lua require"dap".step_over()', { noremap = true, silent = true }) - vim.api.nvim_set_keymap('n', 'di', ':lua require"dap".step_into()', { noremap = true, silent = true }) - vim.api.nvim_set_keymap('n', 'do', ':lua require"dap".step_out()', { noremap = true, silent = true }) - vim.api.nvim_set_keymap('n', 'db', ':lua require"dap".toggle_breakpoint()', { noremap = true, silent = true }) - vim.api.nvim_set_keymap('n', 'dB', ':lua require"dap".set_breakpoint(vim.fn.input("Breakpoint condition: "))', { noremap = true, silent = true }) - vim.api.nvim_set_keymap('n', 'dr', ':lua require"dap".repl.open()', { noremap = true, silent = true }) - vim.api.nvim_set_keymap('n', 'du', ':lua require"dapui".toggle()', { noremap = true, silent = true }) - - -- DAP Python + -- dap python local function get_python_path() local cwd = vim.fn.getcwd() - if vim.env.VIRTUAL_ENV then - return vim.env.VIRTUAL_ENV .. '/bin/python' + if vim.env.virtual_env then + return vim.env.virtual_env .. '/bin/python' elseif vim.fn.executable(cwd .. '/venv/bin/python') == 1 then return cwd .. '/venv/bin/python' elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then @@ -49,13 +39,13 @@ return { require('dap-python').setup(get_python_path()) - -- DAP Go + -- dap go require('dap-go').setup() - -- DAP Rust + -- dap rust local rust_tools = require('rust-tools') - -- Ensure codelldb is installed via Mason + -- ensure codelldb is installed via mason local codelldb_package = mason_registry.get_package('codelldb') local codelldb_path = codelldb_package:get_install_path() local codelldb_adapter = codelldb_path .. '/extension/adapter/codelldb' @@ -63,55 +53,121 @@ return { rust_tools.setup({ tools = { - autoSetHints = true, + autosethints = true, inlay_hints = { show_parameter_hints = true, - parameter_hints_prefix = "<- ", - other_hints_prefix = "=> ", + parameter_hints_prefix = '<- ', + other_hints_prefix = '=> ', }, }, server = { on_attach = function(_, bufnr) - -- DAP Rust keymaps - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'dr', ':RustDebuggables', { noremap = true, silent = true }) - -- Keybind for RustHoverActions - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', ':RustHoverActions', { noremap = true, silent = true }) + -- dap rust keymaps + vim.api.nvim_buf_set_keymap( + bufnr, + 'n', + 'dr', + ':rustdebuggables', + { noremap = true, silent = true } + ) + -- keybind for rusthoveractions + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'k', ':rusthoveractions', { noremap = true, silent = true }) end, }, dap = { - adapter = require('rust-tools.dap').get_codelldb_adapter( - codelldb_adapter, - codelldb_lib - ), + adapter = require('rust-tools.dap').get_codelldb_adapter(codelldb_adapter, codelldb_lib), }, }) - -- DAP UI integration - dap.listeners.after.event_initialized["dapui_config"] = function() + -- dap ui integration + dap.listeners.after.event_initialized['dapui_config'] = function() dapui.open() end - dap.listeners.before.event_terminated["dapui_config"] = function() + dap.listeners.before.event_terminated['dapui_config'] = function() dapui.close() end - dap.listeners.before.event_exited["dapui_config"] = function() + dap.listeners.before.event_exited['dapui_config'] = function() dapui.close() end - -- Define signs for breakpoints - vim.fn.sign_define('DapBreakpoint', { text = '🔴', texthl = '', linehl = '', numhl = '' }) - vim.fn.sign_define('DapStopped', { text = '🟢', texthl = '', linehl = '', numhl = '' }) + -- define signs for breakpoints + vim.fn.sign_define('dapbreakpoint', { text = '🔴', texthl = '', linehl = '', numhl = '' }) + vim.fn.sign_define('dapstopped', { text = '🟢', texthl = '', linehl = '', numhl = '' }) end, keys = { - { 'n', 'dc', ':lua require"dap".continue()' }, - { 'n', 'ds', ':lua require"dap".step_over()' }, - { 'n', 'di', ':lua require"dap".step_into()' }, - { 'n', 'do', ':lua require"dap".step_out()' }, - { 'n', 'db', ':lua require"dap".toggle_breakpoint()' }, - { 'n', 'dB', ':lua require"dap".set_breakpoint(vim.fn.input("Breakpoint condition: "))' }, - { 'n', 'dr', ':lua require"dap".repl.open()' }, - { 'n', 'du', ':lua require"dapui".toggle()' } + { + 'dc', + function() + require('dap').continue() + end, + mode = 'n', + noremap = true, + silent = true, + }, + { + 'ds', + function() + require('dap').step_over() + end, + mode = 'n', + noremap = true, + silent = true, + }, + { + 'di', + function() + require('dap').step_into() + end, + mode = 'n', + noremap = true, + silent = true, + }, + { + 'do', + function() + require('dap').step_out() + end, + mode = 'n', + noremap = true, + silent = true, + }, + { + 'db', + function() + require('dap').toggle_breakpoint() + end, + mode = 'n', + noremap = true, + silent = true, + }, + { + 'dsb', + function() + require('dap').set_breakpoint(vim.fn.input('Breakpoint condition: ')) + end, + mode = 'n', + noremap = true, + silent = true, + }, + { + 'dr', + function() + require('dap').repl.open() + end, + mode = 'n', + noremap = true, + silent = true, + }, + { + 'du', + function() + require('dapui').toggle() + end, + mode = 'n', + noremap = true, + silent = true, + }, }, - ft = { 'python', 'go', 'rust' } - } + ft = { 'python', 'go', 'rust' }, + }, } - diff --git a/lua/custom/plugins/formatting.lua b/lua/custom/plugins/formatting.lua index 987e1fb3..5bb59741 100755 --- a/lua/custom/plugins/formatting.lua +++ b/lua/custom/plugins/formatting.lua @@ -5,6 +5,17 @@ return { 'WhoIsSethDaniel/mason-tool-installer.nvim', }, event = { 'BufReadPre', 'BufNewFile' }, + cmd = { 'ConformInfo' }, + keys = { + { + 'f', + function() + require('conform').format({ async = true, lsp_fallback = true }) + end, + mode = '', + desc = '[F]ormat buffer', + }, + }, opts = function() local formatters_by_ft = { lua = { 'stylua' }, @@ -16,33 +27,38 @@ return { end end, go = { 'gofumpt', 'goimports' }, - yaml = { 'prettier' }, -- Added YAML formatter - bash = { 'shfmt' }, -- Added Bash formatter - rust = { 'rustfmt' }, -- Added Rust formatter - dockerfile = { 'hadolint' }, -- Added Dockerfile formatter + yaml = { 'prettier' }, + bash = { 'shfmt' }, + rust = { 'rustfmt' }, + dockerfile = { 'hadolint' }, } - require('conform').setup({ + return { + notify_on_error = false, + format_on_save = function(bufnr) + local disable_filetypes = { c = true, cpp = true } + return { + timeout_ms = 500, + lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], + } + end, formatters_by_ft = formatters_by_ft, - format_on_save = { - lsp_fallback = true, - timeout_ms = 500, - }, - }) + } + end, + config = function(_, opts) + require('conform').setup(opts) require('mason-tool-installer').setup({ ensure_installed = { - 'stylua', -- Lua - 'ruff', -- Python - 'isort', -- Python - 'black', -- Python - 'gofumpt', -- Go - 'goimports', -- Go - 'prettier', -- YAML, JSON, etc. - 'shfmt', -- Bash - 'hadolint', -- Dockerfile + 'stylua', + 'ruff', + 'isort', + 'black', + 'gofumpt', + 'goimports', + 'shfmt', + 'hadolint', }, }) end, } - diff --git a/lua/custom/plugins/gitsigns.lua b/lua/custom/plugins/gitsigns.lua index cb877b33..b9133925 100755 --- a/lua/custom/plugins/gitsigns.lua +++ b/lua/custom/plugins/gitsigns.lua @@ -14,7 +14,8 @@ return { -- on_attach function executed when the plugin is attached to a buffer on_attach = function(bufnr) vim.keymap.set('n', 'hp', require('gitsigns').preview_hunk, { - buffer = bufnr, desc = 'Preview git hunk' + buffer = bufnr, + desc = 'Preview git hunk', }) -- Don't override built-in and fugitive keymaps @@ -42,4 +43,3 @@ return { }, }, } - diff --git a/lua/custom/plugins/linting.lua b/lua/custom/plugins/linting.lua index c1283506..382bab89 100755 --- a/lua/custom/plugins/linting.lua +++ b/lua/custom/plugins/linting.lua @@ -12,9 +12,10 @@ return { go = { 'golangcilint' }, yaml = { 'yamllint' }, bash = { 'shellcheck' }, - lua = { 'luacheck' }, -- Added Lua linter - rust = { 'clippy' }, -- Use `clippy` for Rust linting + lua = { 'luacheck' }, -- Added Lua linter + rust = { 'clippy' }, -- Use `clippy` for Rust linting dockerfile = { 'hadolint' }, -- Added Dockerfile linter + -- rust = { 'clippy' }, -- Use `clippy` for Rust linting } -- Autocommand group for triggering linting @@ -36,15 +37,15 @@ return { -- Mason tool installer setup require('mason-tool-installer').setup({ ensure_installed = { - 'ruff', -- Python + -- 'clippy', -- Rust + 'ruff', -- Python -- 'mypy', -- Uncomment if needed for additional Python linting 'golangci-lint', -- Go - 'yamllint', -- YAML - 'shellcheck', -- Bash - 'luacheck', -- Lua - 'hadolint', -- Dockerfile + 'yamllint', -- YAML + 'shellcheck', -- Bash + 'luacheck', -- Lua + 'hadolint', -- Dockerfile }, }) end, } - diff --git a/lua/custom/plugins/lsp-config.lua b/lua/custom/plugins/lsp-config.lua index 9aac69bf..db452ae1 100755 --- a/lua/custom/plugins/lsp-config.lua +++ b/lua/custom/plugins/lsp-config.lua @@ -10,6 +10,7 @@ return { 'j-hui/fidget.nvim', tag = 'legacy', opts = {}, + event = 'LspAttach', -- Lazy load on LSP attachment }, -- Additional Lua configuration @@ -54,7 +55,9 @@ return { }, }, }, - rust_analyzer = { cmd = { 'rustup', 'run', 'stable', 'rust-analyzer' } }, + rust_analyzer = { + cmd = { 'rustup', 'run', 'stable', 'rust-analyzer' }, + }, texlab = { flags = { debounce_text_changes = 150, @@ -62,13 +65,13 @@ return { settings = { texlab = { build = { - executable = "latexmk", - args = { "-pdf", "-xelatex", "-output-directory=output", "-interaction=nonstopmode", "-synctex=1", "%f" }, + executable = 'latexmk', + args = { '-pdf', '-xelatex', '-output-directory=output', '-interaction=nonstopmode', '-synctex=1', '%f' }, onSave = true, }, forwardSearch = { - executable = "zathura", - args = { "--synctex-forward", "%l:1:%f", "%p" }, + executable = 'zathura', + args = { '--synctex-forward', '%l:1:%f', '%p' }, }, }, }, @@ -87,6 +90,13 @@ return { }, }, }, + marksman = { + filetypes = { 'markdown' }, + root_dir = function(fname) + return require('lspconfig.util').root_pattern('.marksman.toml', '.git')(fname) or vim.loop.cwd() + end, + settings = {}, + }, yamlls = { filetypes = { 'yaml' }, settings = { @@ -156,11 +166,12 @@ return { spacing = 2, }, float = { - Source = 'if_many', + source = 'if_many', border = 'rounded', }, }) + -- Define diagnostic signs local sign = function(opts) vim.fn.sign_define(opts.name, { texthl = opts.name, @@ -174,10 +185,8 @@ return { sign({ name = 'DiagnosticSignHint', text = '⚑' }) sign({ name = 'DiagnosticSignInfo', text = '»' }) - -- Fidget configuration (LSP progress) - require('fidget').setup({}) - -- Neodev setup for improved Lua development + require('fidget').setup({}) require('neodev').setup({ library = { plugins = { 'nvim-dap-ui' }, @@ -186,4 +195,3 @@ return { }) end, } - diff --git a/lua/custom/plugins/markdown-preview.lua b/lua/custom/plugins/markdown-preview.lua deleted file mode 100644 index ab48dc3a..00000000 --- a/lua/custom/plugins/markdown-preview.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - 'iamcco/markdown-preview.nvim', -} - diff --git a/lua/custom/plugins/neogen.lua b/lua/custom/plugins/neogen.lua index cc75cfa0..abd6aea0 100755 --- a/lua/custom/plugins/neogen.lua +++ b/lua/custom/plugins/neogen.lua @@ -5,8 +5,20 @@ return { 'L3MON4D3/LuaSnip', }, keys = { - { 'nf', function() require('neogen').generate({ type = 'func' }) end, desc = 'Generate function doc' }, - { 'nt', function() require('neogen').generate({ type = 'type' }) end, desc = 'Generate type doc' }, + { + 'nf', + function() + require('neogen').generate({ type = 'func' }) + end, + desc = 'Generate function doc', + }, + { + 'nt', + function() + require('neogen').generate({ type = 'type' }) + end, + desc = 'Generate type doc', + }, }, config = function() require('neogen').setup({ @@ -16,4 +28,3 @@ return { -- Uncomment next line if you want to follow only stable versions -- version = "*" } - diff --git a/lua/custom/plugins/solarized.lua b/lua/custom/plugins/solarized.lua index 04eb8a60..b24e5660 100755 --- a/lua/custom/plugins/solarized.lua +++ b/lua/custom/plugins/solarized.lua @@ -1,8 +1,7 @@ return { 'shaunsingh/solarized.nvim', - event = "VeryLazy", + event = 'VeryLazy', config = function() vim.g.solarized_variant = 'light' end, } - diff --git a/lua/custom/plugins/todo-notes.lua b/lua/custom/plugins/todo-notes.lua new file mode 100644 index 00000000..7c1a967d --- /dev/null +++ b/lua/custom/plugins/todo-notes.lua @@ -0,0 +1,7 @@ +-- Highlight todo, notes, etc in comments +return { + 'folke/todo-comments.nvim', + event = 'VimEnter', + dependencies = { 'nvim-nua/plenary.nvim' }, + opts = { signs = false }, +} diff --git a/lua/custom/plugins/which-key.lua b/lua/custom/plugins/which-key.lua index 5b7258bb..6874358f 100755 --- a/lua/custom/plugins/which-key.lua +++ b/lua/custom/plugins/which-key.lua @@ -1,18 +1,73 @@ -return { - 'folke/which-key.nvim', - event = 'VimEnter', - opts = { - plugins = { - marks = true, - registers = true, - spelling = { - enabled = true, - suggestions = 20, - }, - }, - windows = { - border = 'single', - }, - }, -} +-- return { +-- 'folke/which-key.nvim', +-- event = 'VimEnter', +-- opts = { +-- plugins = { +-- marks = true, +-- registers = true, +-- spelling = { +-- enabled = true, +-- suggestions = 20, +-- }, +-- }, +-- windows = { +-- border = 'single', +-- }, +-- }, +-- } +return { -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VimEnter', -- Sets the loading event to 'VimEnter' + config = function() -- This is the function that runs, AFTER loading + require('which-key').setup({ + icons = { + -- set icon mappings to true if you have a Nerd Font + mappings = vim.g.have_nerd_font, + -- If you are using a Nerd Font: set icons.keys to an empty table which will use the + -- default whick-key.nvim defined Nerd Font icons, otherwise define a string table + keys = vim.g.have_nerd_font and {} or { + Up = ' ', + Down = ' ', + Left = ' ', + Right = ' ', + C = ' ', + M = ' ', + D = ' ', + S = ' ', + CR = ' ', + Esc = ' ', + ScrollWheelDown = ' ', + ScrollWheelUp = ' ', + NL = ' ', + BS = ' ', + Space = ' ', + Tab = ' ', + F1 = '', + F2 = '', + F3 = '', + F4 = '', + F5 = '', + F6 = '', + F7 = '', + F8 = '', + F9 = '', + F10 = '', + F11 = '', + F12 = '', + }, + }, + }) + + -- Document existing key chains + require('which-key').add({ + { 'c', group = '[C]ode', mode = { 'n', 'x' } }, + { 'd', group = '[D]ocument' }, + { 'r', group = '[R]ename' }, + { 's', group = '[S]earch' }, + { 'w', group = '[W]orkspace' }, + { 't', group = '[T]oggle' }, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + }) + end, +}