diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 56f448c..3030caf 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -28,45 +28,6 @@ require('lazy').setup { nofity = false, }, spec = { - -- Useful plugin to show you pending keybinds. - -- https://github.com/folke/which-key.nvim - { - 'folke/which-key.nvim', - lazy = false, -- Load this plugin lazily - version = '*', - priority = 1001, -- Make sure to load this as soon as possible - dependencies = { - 'nvim-lua/plenary.nvim', - 'echasnovski/mini.icons', - }, - config = function() -- This is the function that runs, AFTER loading - local wk = require 'which-key' - wk.setup() - - wk.add { - { 'b', group = '[b] Buffer' }, - { 'c', group = '[c] Code' }, - { 'd', group = '[d] Document' }, - { 'g', group = '[g] Git' }, - { 'l', group = '[l] LSP' }, - { 'p', group = '[p] Project' }, - { 'q', group = '[q] Quit' }, - { 's', group = '[s] Search' }, - { 't', group = '[t] Toggle' }, - { 'w', group = '[w] Workspace' }, - { 'x', group = '[z] Trouble' }, - { 'z', group = '[x] FZF' }, - { '?', group = '[?] Help' }, - { - '?w', - function() - wk.show { global = false } - end, - desc = 'Buffer Local Keymaps (which-key)', - }, - } - end, - }, -- Import plugins from `lua/plugins` directory { import = 'plugins' }, }, diff --git a/config/nvim/lua/plugins/autoformat.lua b/config/nvim/lua/plugins/autoformat.lua index 3db7a5e..d8ca19f 100644 --- a/config/nvim/lua/plugins/autoformat.lua +++ b/config/nvim/lua/plugins/autoformat.lua @@ -6,7 +6,7 @@ return { cmd = { 'ConformInfo' }, keys = { { - 'f', + 'cf', function() require('conform').format { async = true, lsp_fallback = true } end, diff --git a/config/nvim/lua/plugins/cmp.lua b/config/nvim/lua/plugins/cmp.lua index 2d18a28..86feff1 100644 --- a/config/nvim/lua/plugins/cmp.lua +++ b/config/nvim/lua/plugins/cmp.lua @@ -17,7 +17,21 @@ return { { 'zbirenbaum/copilot-cmp', dependencies = { - 'zbirenbaum/copilot.lua', + { + 'zbirenbaum/copilot.lua', + cmd = 'Copilot', + build = ':Copilot setup', + event = { 'InsertEnter', 'LspAttach' }, + fix_pairs = true, + opts = { + suggestion = { enabled = false }, + panel = { enabled = false }, + filetypes = { + markdown = true, + help = true, + }, + }, + } }, config = function() require('copilot_cmp').setup() @@ -25,7 +39,6 @@ return { }, }, config = function() - -- nvim-cmp setup local cmp = require 'cmp' local luasnip = require 'luasnip' local lspkind = require 'lspkind' @@ -35,8 +48,11 @@ return { formatting = { format = lspkind.cmp_format { mode = 'symbol', - max_width = 50, - symbol_map = { Copilot = '' }, + min_width = 40, + max_width = 100, + symbol_map = { + Copilot = '' + }, }, }, view = { diff --git a/config/nvim/lua/plugins/copilot.lua b/config/nvim/lua/plugins/copilot.lua deleted file mode 100644 index 65d3b4f..0000000 --- a/config/nvim/lua/plugins/copilot.lua +++ /dev/null @@ -1,17 +0,0 @@ --- CoPilot --- https://github.com/zbirenbaum/copilot.lua -return { - 'zbirenbaum/copilot.lua', - cmd = 'Copilot', - build = ':Copilot setup', - event = { 'InsertEnter', 'LspAttach' }, - fix_pairs = true, - opts = { - suggestion = { enabled = false }, - panel = { enabled = false }, - filetypes = { - markdown = true, - help = true, - }, - }, -} diff --git a/config/nvim/lua/plugins/dap.lua b/config/nvim/lua/plugins/dap.lua index fd4474e..e44652e 100644 --- a/config/nvim/lua/plugins/dap.lua +++ b/config/nvim/lua/plugins/dap.lua @@ -1,29 +1,30 @@ return { - - 'ray-x/go.nvim', - 'ray-x/guihua.lua', - { 'rcarriga/nvim-dap-ui', dependencies = { 'mfussenegger/nvim-dap', 'nvim-neotest/nvim-nio', 'theHamsta/nvim-dap-virtual-text', + 'ray-x/go.nvim', + 'ray-x/guihua.lua', 'leoluz/nvim-dap-go', }, + keys = { + { 'dt', 'DapUiToggle', desc = 'DAP: Toggle UI' }, + { 'db', 'DapToggleBreakpoint', desc = 'DAP: Toggle Breakpoint' }, + { 'dc', 'DapContinue', desc = 'DAP: Continue' }, + { 'dr', ":lua require('dapui').open({reset = true})", desc = 'DAP: Reset' }, + { 'ht', ":lua require('harpoon.ui').toggle_quick_menu()", desc = 'DAP: Harpoon UI' }, + }, setup = function() require('dapui').setup() require('dap-go').setup() require('nvim-dap-virtual-text').setup() - vim.fn.sign_define('DapBreakpoint', { text = '🔴', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' }) - - -- Debugger - vim.api.nvim_set_keymap('n', 'dt', ':DapUiToggle', { noremap = true }) - vim.api.nvim_set_keymap('n', 'db', ':DapToggleBreakpoint', { noremap = true }) - vim.api.nvim_set_keymap('n', 'dc', ':DapContinue', { noremap = true }) - vim.api.nvim_set_keymap('n', 'dr', ":lua require('dapui').open({reset = true})", { noremap = true }) - vim.api.nvim_set_keymap('n', 'ht', ":lua require('harpoon.ui').toggle_quick_menu()", { noremap = true }) + vim.fn.sign_define( + 'DapBreakpoint', + { text = '🔴', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' } + ) end, }, } diff --git a/config/nvim/lua/plugins/fzf.lua b/config/nvim/lua/plugins/fzf.lua index 6d643a4..8e56e87 100644 --- a/config/nvim/lua/plugins/fzf.lua +++ b/config/nvim/lua/plugins/fzf.lua @@ -5,22 +5,22 @@ return { dependencies = { { 'junegunn/fzf', run = ':call fzf#install()' }, }, - config = function() + keys = { -- Stolen from https://github.com/erikw/dotfiles/blob/d68d6274d67ac47afa20b9a0b9f3b0fa54bcdaf3/.config/nvim/lua/plugins.lua - -- Comment must be on line of its own... -- Search for files in given path. - vim.keymap.set('n', 'zf', ':FZF', { silent = true, desc = 'FZF: search for files in given path.' }) + { '', ':FZF', desc = 'FZF: search for files in given path.' }, -- Sublime-like shortcut 'go to file' ctrl+p. - vim.keymap.set('n', '', ':Files', { silent = true, desc = 'FZF: search for files starting at current directory.' }) - vim.keymap.set('n', 'zc', ':Commands', { silent = true, desc = 'FZF: search commands.' }) - vim.keymap.set('n', 'zt', ':Tags', { silent = true, desc = 'FZF: search in tags file' }) - vim.keymap.set('n', 'zb', ':Buffers', { silent = true, desc = 'FZF: search open buffers.' }) - -- Ref: https://medium.com/@paulodiovani/vim-buffers-windows-and-tabs-an-overview-8e2a57c57afa). - vim.keymap.set('n', 'zt', ':Windows', { silent = true, desc = 'FZF: search open tabs.' }) - vim.keymap.set('n', 'zh', ':History', { silent = true, desc = 'FZF: search history of opened files' }) - vim.keymap.set('n', 'zm', ':Maps', { silent = true, desc = 'FZF: search mappings.' }) - vim.keymap.set('n', 'zg', ':Rg', { silent = true, desc = 'FZF: search with rg (aka live grep).' }) - + { '', ':Files', desc = 'FZF: search for files starting at current directory.' }, + { 'zc', ':Commands', desc = 'FZF: search commands.' }, + { 'zt', ':Tags', desc = 'FZF: search in tags file' }, + { 'zb', ':Buffers', desc = 'FZF: search open buffers.' }, + -- Ref: https://medium.com/@paulodiovani/vim-buffers-windows-and-tabs-an-overview-8e2a57c57afa + { 'zt', ':Windows', desc = 'FZF: search open tabs.' }, + { 'zh', ':History', desc = 'FZF: search history of opened files' }, + { 'zm', ':Maps', desc = 'FZF: search mappings.' }, + { 'zg', ':Rg', desc = 'FZF: search with rg (aka live grep).' }, + }, + config = function() -- To ignore a certain path in a git project from both RG and FD used by FZF, -- the eaiest way is to create ignore files and exclude the in local git clone. -- Ref: https://stackoverflow.com/a/1753078/265508 diff --git a/config/nvim/lua/plugins/git.lua b/config/nvim/lua/plugins/git.lua index 6634beb..90f30e7 100644 --- a/config/nvim/lua/plugins/git.lua +++ b/config/nvim/lua/plugins/git.lua @@ -1,5 +1,4 @@ return { - -- Git integration for buffers -- https://github.com/lewis6991/gitsigns.nvim { @@ -24,7 +23,7 @@ return { end -- Navigation - map('n', ']c', function() + map('n', 'gn', function() if vim.wo.diff then return ']c' end @@ -34,7 +33,7 @@ return { return '' end, { expr = true }) - map('n', '[c', function() + map('n', 'gp', function() if vim.wo.diff then return '[c' end @@ -43,70 +42,8 @@ return { end) return '' end, { expr = true }) - - -- Actions - map({ 'n', 'v' }, 'hs', ':Gitsigns stage_hunk') - map({ 'n', 'v' }, 'hr', ':Gitsigns reset_hunk') - map('n', 'hS', gs.stage_buffer) - map('n', 'ha', gs.stage_hunk) - map('n', 'hu', gs.undo_stage_hunk) - map('n', 'hR', gs.reset_buffer) - map('n', 'hp', gs.preview_hunk) - map('n', 'hb', function() - gs.blame_line { full = true } - end) - map('n', 'tB', gs.toggle_current_line_blame) - map('n', 'hd', gs.diffthis) - map('n', 'hD', function() - gs.diffthis '~' - end) - - -- Text object - map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk') end, } end, }, - - -- git-worktree.nvim: Manage git worktrees - -- https://github.com/ThePrimeagen/git-worktree.nvim - { - 'ThePrimeagen/git-worktree.nvim', - config = function() - require('git-worktree').setup() - end, - }, - - -- An interactive and powerful Git interface for Neovim, inspired by Magit - -- https://github.com/NeogitOrg/neogit - { - 'NeogitOrg/neogit', - config = function() - -- This contains mainly Neogit but also a bunch of Git settings - -- like fetching branches with telescope or blaming with fugitive - local neogit = require 'neogit' - - vim.keymap.set('n', 'gs', neogit.open, { silent = true, noremap = true }) - vim.keymap.set('n', 'gc', ':Neogit commit', { silent = true, noremap = true }) - vim.keymap.set('n', 'gp', ':Neogit pull', { silent = true, noremap = true }) - vim.keymap.set('n', 'gP', ':Neogit push', { silent = true, noremap = true }) - vim.keymap.set('n', 'gb', ':Telescope git_branches', { silent = true, noremap = true }) - vim.keymap.set('n', 'gB', ':G blame', { silent = true, noremap = true }) - - neogit.setup { - disable_commit_confirmation = true, - disable_signs = false, - disable_context_highlighting = false, - disable_builtin_notifications = false, - signs = { - section = { '', '' }, - item = { '', '' }, - hunk = { '', '' }, - }, - integrations = { - diffview = true, - }, - } - end, - }, } diff --git a/config/nvim/lua/plugins/goto-preview.lua b/config/nvim/lua/plugins/goto-preview.lua index a016151..c7f9fd9 100644 --- a/config/nvim/lua/plugins/goto-preview.lua +++ b/config/nvim/lua/plugins/goto-preview.lua @@ -5,6 +5,11 @@ return { dependencies = { { 'nvim-telescope/telescope.nvim' }, }, + keys = { + { 'n', 'gpd', 'lua require("goto-preview").goto_preview_definition()' }, + { 'n', 'gpi', 'lua require("goto-preview").goto_preview_implementation()' }, + { 'n', 'gP', 'lua require("goto-preview").close_all_windows()' }, + }, config = function() require('goto-preview').setup { width = 120, -- Width of the floating window diff --git a/config/nvim/lua/plugins/obsidian.lua b/config/nvim/lua/plugins/obsidian.lua deleted file mode 100644 index c991e20..0000000 --- a/config/nvim/lua/plugins/obsidian.lua +++ /dev/null @@ -1,19 +0,0 @@ -return { - 'epwalsh/obsidian.nvim', - version = '*', -- recommended, use latest release instead of latest commit - lazy = true, - ft = 'markdown', - dependencies = { - 'nvim-lua/plenary.nvim', - }, - config = function() - require('obsidian').setup { - workspaces = { - { - name = 'Notes', - path = vim.fn.expand '$HOME/Code/ivuorinen/obsidian', - }, - }, - } - end, -} diff --git a/config/nvim/lua/plugins/telescope.lua b/config/nvim/lua/plugins/telescope.lua index 12f6f6e..0504f21 100644 --- a/config/nvim/lua/plugins/telescope.lua +++ b/config/nvim/lua/plugins/telescope.lua @@ -1,94 +1,92 @@ return { -- Fuzzy Finder (files, lsp, etc) -- https://github.com/nvim-telescope/telescope.nvim - { - 'nvim-telescope/telescope.nvim', - version = '*', - lazy = false, - dependencies = { - { 'nvim-lua/plenary.nvim' }, - { 'nvim-telescope/telescope-symbols.nvim' }, - { 'folke/which-key.nvim' }, - { 'ThePrimeagen/harpoon' }, + 'nvim-telescope/telescope.nvim', + version = '*', + lazy = false, + dependencies = { + { 'nvim-lua/plenary.nvim' }, + { 'nvim-telescope/telescope-symbols.nvim' }, + { 'folke/which-key.nvim' }, + { 'ThePrimeagen/harpoon' }, - -- 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, - }, + -- 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, }, - config = function() - local t = require 'telescope' - local a = require 'telescope.actions' - local themes = require 'telescope.themes' + }, + config = function() + local t = require 'telescope' + local a = require 'telescope.actions' + local themes = require 'telescope.themes' - -- [[ Configure Telescope ]] - -- See `:help telescope` and `:help telescope.setup()` - t.setup { - defaults = { - layout_strategy = 'horizontal', - layout_config = { - preview_width = 0.65, - horizontal = { - size = { - width = '95%', - height = '95%', - }, - }, - }, - pickers = { - find_files = { - theme = 'dropdown', - }, - }, - mappings = { - i = { - [''] = false, - [''] = a.move_selection_next, - [''] = a.move_selection_previous, - [''] = a.move_selection_previous, + -- [[ Configure Telescope ]] + -- See `:help telescope` and `:help telescope.setup()` + t.setup { + defaults = { + layout_strategy = 'horizontal', + layout_config = { + preview_width = 0.65, + horizontal = { + size = { + width = '95%', + height = '95%', }, }, }, - } + pickers = { + find_files = { + theme = 'dropdown', + }, + }, + mappings = { + i = { + [''] = false, + [''] = a.move_selection_next, + [''] = a.move_selection_previous, + [''] = a.move_selection_previous, + }, + }, + }, + } - -- Load extensions - pcall(t.load_extension, 'harpoon') - pcall(t.load_extension, 'git_worktree') - -- Enable telescope fzf native, if installed - pcall(t.load_extension, 'fzf') + -- Load extensions + pcall(t.load_extension, 'harpoon') + pcall(t.load_extension, 'git_worktree') + -- Enable telescope fzf native, if installed + pcall(t.load_extension, 'fzf') - -- [[ Telescope Keymaps ]] - -- See `:help telescope.builtin` - -- See `:help telescope.keymap` - local b = require 'telescope.builtin' + -- [[ Telescope Keymaps ]] + -- See `:help telescope.builtin` + -- See `:help telescope.keymap` + local b = require 'telescope.builtin' - local wk = require 'which-key' - wk.add { - -- { '', b.buffers, desc = '[ ] Find existing buffers' }, - { 'gR', "lua require('telescope').extensions.git_worktree.create_git_worktree()", desc = 'Create Git worktree' }, - { 'gr', "lua require('telescope').extensions.git_worktree.git_worktrees()", desc = 'Git worktrees' }, - { 'sS', b.git_status, desc = '' }, - { 'sd', b.diagnostics, desc = '[S]earch [D]iagnostics' }, - { 'sf', b.find_files, desc = '[S]earch [F]iles' }, - { 'sg', b.live_grep, desc = '[S]earch by [G]rep' }, - { 'sm', ':Telescope harpoon marks', desc = 'Harpoon Marks' }, - { 'sn', "lua require('telescope').extensions.notify.notify()", desc = 'Notify' }, - { 'so', b.oldfiles, desc = '[?] Find recently opened files' }, - { 'sw', b.grep_string, desc = '[S]earch current [W]ord' }, - { 'st', ':TodoTelescope', desc = 'Telescope: Todo' }, - { '', "lua require('telescope.builtin').commands()", desc = 'Telescope: Commands' }, - } + local wk = require 'which-key' + wk.add { + -- { '', b.buffers, desc = '[ ] Find existing buffers' }, + { 'gR', "lua require('telescope').extensions.git_worktree.create_git_worktree()", desc = 'Create Git worktree' }, + { 'gr', "lua require('telescope').extensions.git_worktree.git_worktrees()", desc = 'Git worktrees' }, + { 'sS', b.git_status, desc = '' }, + { 'sd', b.diagnostics, desc = '[S]earch [D]iagnostics' }, + { 'sf', b.find_files, desc = '[S]earch [F]iles' }, + { 'sg', b.live_grep, desc = '[S]earch by [G]rep' }, + { 'sm', ':Telescope harpoon marks', desc = 'Harpoon Marks' }, + { 'sn', "lua require('telescope').extensions.notify.notify()", desc = 'Notify' }, + { 'so', b.oldfiles, desc = '[?] Find recently opened files' }, + { 'sw', b.grep_string, desc = '[S]earch current [W]ord' }, + { 'st', ':TodoTelescope', desc = 'Telescope: Todo' }, + { '', "lua require('telescope.builtin').commands()", desc = 'Telescope: Commands' }, + } - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to telescope to change theme, layout, etc. - b.current_buffer_fuzzy_find(themes.get_dropdown { - winblend = 10, - previewer = true, - }) - end, { desc = '[/] Fuzzily search in current buffer]' }) - end, - }, + vim.keymap.set('n', '/', function() + -- You can pass additional configuration to telescope to change theme, layout, etc. + b.current_buffer_fuzzy_find(themes.get_dropdown { + winblend = 10, + previewer = true, + }) + end, { desc = '[/] Fuzzily search in current buffer]' }) + end, } diff --git a/config/nvim/lua/plugins/trouble.lua b/config/nvim/lua/plugins/trouble.lua index 9e9fa67..07bdf92 100644 --- a/config/nvim/lua/plugins/trouble.lua +++ b/config/nvim/lua/plugins/trouble.lua @@ -2,6 +2,14 @@ return { 'folke/trouble.nvim', lazy = false, dependencies = 'nvim-tree/nvim-web-devicons', + keys = { + { 'xx', 'TroubleToggle', desc = 'Toggle Trouble' }, + { 'xw', 'TroubleToggle workspace_diagnostics', desc = 'Toggle Workspace Diagnostics' }, + { 'xd', 'TroubleToggle document_diagnostics', desc = 'Toggle Document Diagnostics' }, + { 'xl', 'TroubleToggle loclist', desc = 'Toggle Loclist' }, + { 'xq', 'TroubleToggle quickfix', desc = 'Toggle Quickfix' }, + { 'gR', 'TroubleToggle lsp_references', desc = 'Toggle LSP References' }, + }, config = function() require('trouble').setup { auto_preview = false, @@ -10,17 +18,6 @@ return { use_lsp_diagnostic_signs = true, } - -- Keybindings - local wk = require 'which-key' - wk.add { - { 'xx', 'TroubleToggle', desc = 'Toggle Trouble' }, - { 'xw', 'TroubleToggle workspace_diagnostics', desc = 'Toggle Workspace Diagnostics' }, - { 'xd', 'TroubleToggle document_diagnostics', desc = 'Toggle Document Diagnostics' }, - { 'xl', 'TroubleToggle loclist', desc = 'Toggle Loclist' }, - { 'xq', 'TroubleToggle quickfix', desc = 'Toggle Quickfix' }, - { 'gR', 'TroubleToggle lsp_references', desc = 'Toggle LSP References' }, - } - -- Diagnostic signs -- https://github.com/folke/trouble.nvim/issues/52 local signs = { diff --git a/config/nvim/lua/plugins/which-key.lua b/config/nvim/lua/plugins/which-key.lua new file mode 100644 index 0000000..11f0ad8 --- /dev/null +++ b/config/nvim/lua/plugins/which-key.lua @@ -0,0 +1,48 @@ +-- Useful plugin to show you pending keybinds. +-- https://github.com/folke/which-key.nvim +return { + 'folke/which-key.nvim', + lazy = false, + version = '*', + priority = 1001, -- Make sure to load this as soon as possible + dependencies = { + 'nvim-lua/plenary.nvim', + 'echasnovski/mini.icons', + }, + config = function() + local wk = require 'which-key' + wk.setup() + + wk.add { + -- Groups + { + 'b', + group = '[b] Buffer', + expand = function() + return require('which-key.extras').expand.buf() + end, + }, + { 'c', group = '[c] Code' }, + { 'd', group = '[d] Document' }, + { 'g', group = '[g] Git' }, + { 'l', group = '[l] LSP' }, + { 'p', group = '[p] Project' }, + { 'q', group = '[q] Quit' }, + { 's', group = '[s] Search' }, + { 't', group = '[t] Toggle' }, + { 'w', group = '[w] Workspace' }, + { 'x', group = '[z] Trouble' }, + { 'z', group = '[x] FZF & Harpoon' }, + { '?', group = '[?] Help' }, + { + '?w', + function() + wk.show { global = false } + end, + desc = 'Buffer Local Keymaps (which-key)', + }, + -- Misc keybinds + { 'QQ', ':q!', desc = 'Quit without saving' }, + } + end, +}