From f162354317aa99473876305540cc2a8daa0af7bd Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Mon, 23 Mar 2026 20:34:20 -0400 Subject: [PATCH] refactor: cleanup UI and navigation plugins - Simplify telescope.lua configuration - Streamline trouble.lua diagnostics - Refactor oil.lua file manager - Update harpoon.lua quick file navigation - Clean up indent.lua, lualine.lua, which-key.lua --- lua/custom/plugins/harpoon.lua | 67 +++----------------------------- lua/custom/plugins/indent.lua | 17 ++------ lua/custom/plugins/lualine.lua | 26 +++++++++---- lua/custom/plugins/oil.lua | 31 +++++---------- lua/custom/plugins/telescope.lua | 52 +++++++------------------ lua/custom/plugins/trouble.lua | 33 +++------------- lua/custom/plugins/which-key.lua | 16 -------- 7 files changed, 59 insertions(+), 183 deletions(-) diff --git a/lua/custom/plugins/harpoon.lua b/lua/custom/plugins/harpoon.lua index 20206da..23b7ead 100755 --- a/lua/custom/plugins/harpoon.lua +++ b/lua/custom/plugins/harpoon.lua @@ -14,70 +14,18 @@ return { dependencies = { 'nvim-lua/plenary.nvim' }, config = function() local harpoon = require('harpoon') - -- local actions = require('telescope.actions') - -- local action_state = require('telescope.actions.state') - -- local conf = require('telescope.config').values harpoon:setup({ settings = { save_on_toggle = true, sync_on_ui_close = true, key = function() - return vim.loop.cwd() or 'global' + return vim.uv.cwd() or 'global' end, }, }) - -- Telescope integration - -- local function toggle_telescope() - -- local list = harpoon:list() - -- local file_paths = {} - -- - -- for _, item in ipairs(list.items) do - -- table.insert(file_paths, item.value) - -- end - -- - -- require('telescope.pickers') - -- .new({}, { - -- prompt_title = 'Harpoon', - -- finder = require('telescope.finders').new_table({ - -- results = file_paths, - -- }), - -- previewer = false, - -- sorter = conf.generic_sorter({}), - -- layout_config = { - -- width = 0.5, - -- height = 0.5, - -- prompt_position = 'top', - -- }, - -- layout_strategy = 'vertical', - -- attach_mappings = function(prompt_bufnr, map) - -- map('i', '', function() - -- local selection = action_state.get_selected_entry() - -- if not selection then - -- return - -- end - -- - -- local target = selection[1] - -- for _, item in ipairs(harpoon:list().items) do - -- if item.value == target then - -- harpoon:list():remove(item) - -- break - -- end - -- end - -- actions.close(prompt_bufnr) - -- toggle_telescope() - -- end) - -- return true - -- end, - -- }) - -- :find() - -- end - vim.keymap.set('n', 'a', function() - local harpoon = require('harpoon') - - -- Check if we're in an oil buffer if vim.fn.expand('%:p'):sub(1, 6) == 'oil://' then local ok_oil, oil = pcall(require, 'oil') if not ok_oil then @@ -92,9 +40,9 @@ return { end local full_path = oil.get_current_dir() .. entry.name - local stat = vim.loop.fs_stat(full_path) + local stat = vim.uv.fs_stat(full_path) if not stat or stat.type ~= 'file' then - vim.notify('Selected entry is not a file: ' .. full_path, vim.log.levels.INFO) + vim.notify('Not a file: ' .. full_path, vim.log.levels.INFO) return end @@ -102,18 +50,16 @@ return { value = entry.name, context = { filename = entry.name, cwd = oil.get_current_dir() or 'global' }, }) - vim.notify('Added ' .. entry.name .. ' to harpoon', vim.log.levels.INFO) + vim.notify('Added ' .. entry.name .. ' to harpoon') return end - -- Regular file buffer harpoon:list():add() - end, { desc = 'Harpoon: Add file to list (if not already present)' }) + end, { desc = 'Harpoon: Add file' }) vim.keymap.set('n', '', function() harpoon.ui:toggle_quick_menu(harpoon:list()) - end, { desc = 'Harpoon: Toggle quick menu' }) - + end) vim.keymap.set('n', '', function() harpoon:list():select(1) end) @@ -126,7 +72,6 @@ return { vim.keymap.set('n', '', function() harpoon:list():select(4) end) - vim.keymap.set('n', '', function() harpoon:list():prev() end) diff --git a/lua/custom/plugins/indent.lua b/lua/custom/plugins/indent.lua index 68149b9..2456c93 100755 --- a/lua/custom/plugins/indent.lua +++ b/lua/custom/plugins/indent.lua @@ -1,25 +1,16 @@ -local highlight = { - 'Whitespace', - 'Function', -} - return { - -- Add indentation guides even on blank lines 'lukas-reineke/indent-blankline.nvim', main = 'ibl', - event = 'VeryLazy', + event = 'BufReadPost', opts = { indent = { - highlight = highlight, + highlight = { 'Whitespace', 'Function' }, char = '┆', }, whitespace = { - highlight = highlight, + highlight = { 'Whitespace', 'Function' }, remove_blankline_trail = true, }, - scope = { - enabled = true, - exclude = { language = { 'vim', 'lua', 'go', 'python', 'rust', 'sh', 'json', 'yaml', 'toml', 'markdown' } }, - }, + scope = { enabled = false }, -- excluded for all your languages anyway }, } diff --git a/lua/custom/plugins/lualine.lua b/lua/custom/plugins/lualine.lua index cc82b62..d171cf1 100755 --- a/lua/custom/plugins/lualine.lua +++ b/lua/custom/plugins/lualine.lua @@ -1,6 +1,7 @@ return { 'nvim-lualine/lualine.nvim', - dependencies = { 'nvim-tree/nvim-web-devicons', 'tpope/vim-fugitive' }, + event = 'UIEnter', + dependencies = { 'nvim-tree/nvim-web-devicons', option = true }, config = function() require('lualine').setup({ options = { @@ -11,24 +12,35 @@ return { }, sections = { lualine_a = { + { 'mode', icons_enabled = true }, + }, + lualine_b = { { 'buffers', show_modified_status = true, - symbols = { modified = '●', alternate_file = '#', directory = '' }, + symbols = { modified = '●', alternate_file = '#', directory = '' }, }, }, - lualine_b = { - { 'mode', icons_enabled = true }, - }, lualine_c = { 'branch', { 'diff', colored = false, symbols = { added = ' ', modified = ' ', removed = ' ' } }, + { + 'diagnostics', + sources = { 'nvim_lsp' }, + symbols = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' }, + }, -- shows E/W/H counts }, lualine_x = { - 'encoding', - { 'fileformat', symbols = { unix = ' ', mac = ' ', dos = ' ' } }, + { + display_components = { 'lsp_client_name', 'spinner', { 'title', 'percentage', 'message' } }, + }, + }, + lualine_y = { + { 'encoding', show_bomb = true }, + { 'fileformat', symbols = { unix = '', mac = '', dos = '' } }, 'filetype', }, + lualine_z = { 'location' }, -- line:col }, extensions = { 'fugitive', 'nvim-tree', 'fzf' }, }) diff --git a/lua/custom/plugins/oil.lua b/lua/custom/plugins/oil.lua index cbcea85..3fae08b 100755 --- a/lua/custom/plugins/oil.lua +++ b/lua/custom/plugins/oil.lua @@ -1,5 +1,6 @@ return { 'stevearc/oil.nvim', + cmd = 'Oil', keys = { { 'e', 'Oil', desc = 'Open parent directory' }, { @@ -10,45 +11,33 @@ return { desc = 'Toggle oil floating window', }, }, - dependencies = { 'nvim-tree/nvim-web-devicons' }, + dependencies = { { 'nvim-tree/nvim-web-devicons', optional = true } }, config = function() - local oil = require('oil') - - oil.setup({ - columns = { - 'icon', - -- 'permissions', - }, + require('oil').setup({ + columns = { 'icon' }, keymaps = { - ['C-h'] = false, - ['M-h'] = 'actions.select_split', - }, - view_options = { - show_hidden = true, + [''] = false, + [''] = 'actions.select_split', }, + view_options = { show_hidden = true }, float = { padding = 2, max_width = 80, max_height = 30, border = 'rounded', - win_options = { - winblend = 0, - }, + win_options = { winblend = 0 }, relative = 'editor', }, }) - -- Theme-aware highlights for oil local function set_oil_highlights() if vim.o.background == 'dark' then - -- Monokai colors vim.api.nvim_set_hl(0, 'OilDir', { fg = '#A6E22E' }) vim.api.nvim_set_hl(0, 'OilFile', { fg = '#D3D0C8' }) vim.api.nvim_set_hl(0, 'OilHiddenFile', { fg = '#75715E' }) vim.api.nvim_set_hl(0, 'OilProgress', { fg = '#66D9EF' }) vim.api.nvim_set_hl(0, 'OilSymlink', { fg = '#F92672' }) else - -- Solarized light colors vim.api.nvim_set_hl(0, 'OilDir', { fg = '#859900' }) vim.api.nvim_set_hl(0, 'OilFile', { fg = '#657B83' }) vim.api.nvim_set_hl(0, 'OilHiddenFile', { fg = '#93A1A1' }) @@ -58,8 +47,8 @@ return { end set_oil_highlights() - vim.api.nvim_create_autocmd('OptionSet', { - pattern = 'background', + + vim.api.nvim_create_autocmd('ColorScheme', { callback = set_oil_highlights, }) end, diff --git a/lua/custom/plugins/telescope.lua b/lua/custom/plugins/telescope.lua index ede1521..4b3f2d3 100755 --- a/lua/custom/plugins/telescope.lua +++ b/lua/custom/plugins/telescope.lua @@ -1,11 +1,10 @@ return { - -- Fuzzy Finder (files, LSP, etc.) 'nvim-telescope/telescope.nvim', cmd = 'Telescope', - version = '*', keys = { { 'ff', 'Telescope find_files', desc = 'Find Files' }, { 'fg', 'Telescope live_grep', desc = 'Live Grep' }, + { 'fG', 'LiveGrepGitRoot', desc = 'Live Grep Git Root' }, { 'fb', 'Telescope buffers', desc = 'Buffers' }, { 'fh', 'Telescope help_tags', desc = 'Help Tags' }, { 'fr', 'Telescope oldfiles', desc = 'Recent Files' }, @@ -13,69 +12,46 @@ return { dependencies = { 'nvim-lua/plenary.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, - 'nvim-tree/nvim-web-devicons', + { 'nvim-tree/nvim-web-devicons', optional = true }, }, config = function() local telescope = require('telescope') + local actions = require('telescope.actions') - -- Configure Telescope telescope.setup({ defaults = { - -- prompt_prefix = '🔍 ', sorting_strategy = 'descending', layout_strategy = 'flex', mappings = { i = { - [''] = false, -- Disable Ctrl+u clearing input - [''] = false, -- Disable Ctrl+d clearing input + [''] = false, + [''] = false, + [''] = function(prompt_bufnr) + -- close first, then center -- this is the correct order + actions.select_default(prompt_bufnr) + vim.cmd('normal! zz') + end, }, }, - -- Attach the global mapping for centering the cursor on selection - attach_mappings = function(prompt_bufnr, _) - local actions = require('telescope.actions') - - -- When selecting a result, center it in the middle of the screen - actions.select_default:replace(function() - local line = actions.state.get_selected_entry().lnum - vim.api.nvim_win_set_cursor(0, { line, 0 }) - vim.cmd('normal! zz') -- This centers the line in the middle of the screen - actions.close(prompt_bufnr) -- Close the Telescope window - end) - - return true - end, - }, - extensions = { - fzf = {}, }, + extensions = { fzf = {} }, }) - -- Load the fzf extension for Telescope telescope.load_extension('fzf') - -- Function to find git root directory local function find_git_root() local current_file = vim.api.nvim_buf_get_name(0) local current_dir = current_file ~= '' and vim.fn.fnamemodify(current_file, ':h') or vim.fn.getcwd() local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] - if vim.v.shell_error ~= 0 then - print('Not a git repository, searching in current directory.') return vim.fn.getcwd() end return git_root end - -- Function for live_grep within the Git root - local function live_grep_git_root() - local git_root = find_git_root() - if git_root then - require('telescope.builtin').live_grep({ search_dirs = { git_root } }) - end - end - - -- Command to trigger live_grep_git_root - vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, { desc = 'Live grep in Git root' }) + vim.api.nvim_create_user_command('LiveGrepGitRoot', function() + require('telescope.builtin').live_grep({ search_dirs = { find_git_root() } }) + end, { desc = 'Live grep in Git root' }) end, } diff --git a/lua/custom/plugins/trouble.lua b/lua/custom/plugins/trouble.lua index 89a326a..8b99827 100755 --- a/lua/custom/plugins/trouble.lua +++ b/lua/custom/plugins/trouble.lua @@ -1,39 +1,18 @@ return { 'folke/trouble.nvim', version = '*', - opts = {}, -- for default options, refer to the configuration section for custom setup. cmd = 'Trouble', - event = 'LspAttach', keys = { - { - 'xx', - 'Trouble diagnostics toggle', - desc = 'Diagnostics (Trouble)', - }, + { 'xx', 'Trouble diagnostics toggle', desc = 'Diagnostics (Trouble)' }, { 'xX', 'Trouble diagnostics toggle filter.buf=0', desc = 'Buffer Diagnostics (Trouble)', }, - { - 'xs', - 'Trouble symbols toggle focus=false', - desc = 'Symbols (Trouble)', - }, - { - 'xl', - 'Trouble lsp toggle focus=false win.position=right', - desc = 'LSP Definitions / references / ... (Trouble)', - }, - { - 'xL', - 'Trouble loclist toggle', - desc = 'Location List (Trouble)', - }, - { - 'xQ', - 'Trouble qflist toggle', - desc = 'Quickfix List (Trouble)', - }, + { 'xs', 'Trouble symbols toggle focus=false', desc = 'Symbols (Trouble)' }, + { 'xl', 'Trouble lsp toggle focus=false win.position=right', desc = 'LSP Definitions (Trouble)' }, + { 'xL', 'Trouble loclist toggle', desc = 'Location List (Trouble)' }, + { 'xQ', 'Trouble qflist toggle', desc = 'Quickfix List (Trouble)' }, }, + opts = {}, } diff --git a/lua/custom/plugins/which-key.lua b/lua/custom/plugins/which-key.lua index 53ff70d..2090428 100755 --- a/lua/custom/plugins/which-key.lua +++ b/lua/custom/plugins/which-key.lua @@ -16,22 +16,6 @@ return { Esc = ' ', ScrollWheelDown = ' ', ScrollWheelUp = ' ', - NL = ' ', - BS = ' ', - Space = ' ', - Tab = ' ', - F1 = '', - F2 = '', - F3 = '', - F4 = '', - F5 = '', - F6 = '', - F7 = '', - F8 = '', - F9 = '', - F10 = '', - F11 = '', - F12 = '', }, }, opts = {