chore(nvim): cleanup and keybindings

This commit is contained in:
2024-09-23 16:25:54 +03:00
parent 0908a23231
commit fd8d72ab38
12 changed files with 188 additions and 261 deletions

View File

@@ -28,45 +28,6 @@ require('lazy').setup {
nofity = false, nofity = false,
}, },
spec = { 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 {
{ '<leader>b', group = '[b] Buffer' },
{ '<leader>c', group = '[c] Code' },
{ '<leader>d', group = '[d] Document' },
{ '<leader>g', group = '[g] Git' },
{ '<leader>l', group = '[l] LSP' },
{ '<leader>p', group = '[p] Project' },
{ '<leader>q', group = '[q] Quit' },
{ '<leader>s', group = '[s] Search' },
{ '<leader>t', group = '[t] Toggle' },
{ '<leader>w', group = '[w] Workspace' },
{ '<leader>x', group = '[z] Trouble' },
{ '<leader>z', group = '[x] FZF' },
{ '<leader>?', group = '[?] Help' },
{
'<leader>?w',
function()
wk.show { global = false }
end,
desc = 'Buffer Local Keymaps (which-key)',
},
}
end,
},
-- Import plugins from `lua/plugins` directory -- Import plugins from `lua/plugins` directory
{ import = 'plugins' }, { import = 'plugins' },
}, },

View File

@@ -6,7 +6,7 @@ return {
cmd = { 'ConformInfo' }, cmd = { 'ConformInfo' },
keys = { keys = {
{ {
'<leader>f', '<leader>cf',
function() function()
require('conform').format { async = true, lsp_fallback = true } require('conform').format { async = true, lsp_fallback = true }
end, end,

View File

@@ -17,7 +17,21 @@ return {
{ {
'zbirenbaum/copilot-cmp', 'zbirenbaum/copilot-cmp',
dependencies = { 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() config = function()
require('copilot_cmp').setup() require('copilot_cmp').setup()
@@ -25,7 +39,6 @@ return {
}, },
}, },
config = function() config = function()
-- nvim-cmp setup
local cmp = require 'cmp' local cmp = require 'cmp'
local luasnip = require 'luasnip' local luasnip = require 'luasnip'
local lspkind = require 'lspkind' local lspkind = require 'lspkind'
@@ -35,8 +48,11 @@ return {
formatting = { formatting = {
format = lspkind.cmp_format { format = lspkind.cmp_format {
mode = 'symbol', mode = 'symbol',
max_width = 50, min_width = 40,
symbol_map = { Copilot = '' }, max_width = 100,
symbol_map = {
Copilot = ''
},
}, },
}, },
view = { view = {

View File

@@ -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,
},
},
}

View File

@@ -1,29 +1,30 @@
return { return {
'ray-x/go.nvim',
'ray-x/guihua.lua',
{ {
'rcarriga/nvim-dap-ui', 'rcarriga/nvim-dap-ui',
dependencies = { dependencies = {
'mfussenegger/nvim-dap', 'mfussenegger/nvim-dap',
'nvim-neotest/nvim-nio', 'nvim-neotest/nvim-nio',
'theHamsta/nvim-dap-virtual-text', 'theHamsta/nvim-dap-virtual-text',
'ray-x/go.nvim',
'ray-x/guihua.lua',
'leoluz/nvim-dap-go', 'leoluz/nvim-dap-go',
}, },
keys = {
{ '<leader>dt', '<cmd>DapUiToggle', desc = 'DAP: Toggle UI' },
{ '<leader>db', '<cmd>DapToggleBreakpoint', desc = 'DAP: Toggle Breakpoint' },
{ '<leader>dc', '<cmd>DapContinue', desc = 'DAP: Continue' },
{ '<leader>dr', ":lua require('dapui').open({reset = true})<CR>", desc = 'DAP: Reset' },
{ '<leader>ht', ":lua require('harpoon.ui').toggle_quick_menu()<CR>", desc = 'DAP: Harpoon UI' },
},
setup = function() setup = function()
require('dapui').setup() require('dapui').setup()
require('dap-go').setup() require('dap-go').setup()
require('nvim-dap-virtual-text').setup() require('nvim-dap-virtual-text').setup()
vim.fn.sign_define('DapBreakpoint', { text = '🔴', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' }) vim.fn.sign_define(
'DapBreakpoint',
-- Debugger { text = '🔴', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' }
vim.api.nvim_set_keymap('n', '<leader>dt', ':DapUiToggle<CR>', { noremap = true }) )
vim.api.nvim_set_keymap('n', '<leader>db', ':DapToggleBreakpoint<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>dc', ':DapContinue<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>dr', ":lua require('dapui').open({reset = true})<CR>", { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>ht', ":lua require('harpoon.ui').toggle_quick_menu()<CR>", { noremap = true })
end, end,
}, },
} }

View File

@@ -5,22 +5,22 @@ return {
dependencies = { dependencies = {
{ 'junegunn/fzf', run = ':call fzf#install()' }, { 'junegunn/fzf', run = ':call fzf#install()' },
}, },
config = function() keys = {
-- Stolen from https://github.com/erikw/dotfiles/blob/d68d6274d67ac47afa20b9a0b9f3b0fa54bcdaf3/.config/nvim/lua/plugins.lua -- 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. -- Search for files in given path.
vim.keymap.set('n', '<Leader>zf', ':FZF<space>', { silent = true, desc = 'FZF: search for files in given path.' }) { '<Leader><space>', ':FZF<space>', desc = 'FZF: search for files in given path.' },
-- Sublime-like shortcut 'go to file' ctrl+p. -- Sublime-like shortcut 'go to file' ctrl+p.
vim.keymap.set('n', '<C-p>', ':Files<CR>', { silent = true, desc = 'FZF: search for files starting at current directory.' }) { '<C-p>', ':Files<CR>', desc = 'FZF: search for files starting at current directory.' },
vim.keymap.set('n', '<Leader>zc', ':Commands<CR>', { silent = true, desc = 'FZF: search commands.' }) { '<Leader>zc', ':Commands<CR>', desc = 'FZF: search commands.' },
vim.keymap.set('n', '<Leader>zt', ':Tags<CR>', { silent = true, desc = 'FZF: search in tags file' }) { '<Leader>zt', ':Tags<CR>', desc = 'FZF: search in tags file' },
vim.keymap.set('n', '<Leader>zb', ':Buffers<CR>', { silent = true, desc = 'FZF: search open buffers.' }) { '<Leader>zb', ':Buffers<CR>', desc = 'FZF: search open buffers.' },
-- Ref: https://medium.com/@paulodiovani/vim-buffers-windows-and-tabs-an-overview-8e2a57c57afa). -- Ref: https://medium.com/@paulodiovani/vim-buffers-windows-and-tabs-an-overview-8e2a57c57afa
vim.keymap.set('n', '<Leader>zt', ':Windows<CR>', { silent = true, desc = 'FZF: search open tabs.' }) { '<Leader>zt', ':Windows<CR>', desc = 'FZF: search open tabs.' },
vim.keymap.set('n', '<Leader>zh', ':History<CR>', { silent = true, desc = 'FZF: search history of opened files' }) { '<Leader>zh', ':History<CR>', desc = 'FZF: search history of opened files' },
vim.keymap.set('n', '<Leader>zm', ':Maps<CR>', { silent = true, desc = 'FZF: search mappings.' }) { '<Leader>zm', ':Maps<CR>', desc = 'FZF: search mappings.' },
vim.keymap.set('n', '<Leader>zg', ':Rg<CR>', { silent = true, desc = 'FZF: search with rg (aka live grep).' }) { '<Leader>zg', ':Rg<CR>', 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, -- 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. -- the eaiest way is to create ignore files and exclude the in local git clone.
-- Ref: https://stackoverflow.com/a/1753078/265508 -- Ref: https://stackoverflow.com/a/1753078/265508

View File

@@ -1,5 +1,4 @@
return { return {
-- Git integration for buffers -- Git integration for buffers
-- https://github.com/lewis6991/gitsigns.nvim -- https://github.com/lewis6991/gitsigns.nvim
{ {
@@ -24,7 +23,7 @@ return {
end end
-- Navigation -- Navigation
map('n', ']c', function() map('n', 'gn', function()
if vim.wo.diff then if vim.wo.diff then
return ']c' return ']c'
end end
@@ -34,7 +33,7 @@ return {
return '<Ignore>' return '<Ignore>'
end, { expr = true }) end, { expr = true })
map('n', '[c', function() map('n', 'gp', function()
if vim.wo.diff then if vim.wo.diff then
return '[c' return '[c'
end end
@@ -43,70 +42,8 @@ return {
end) end)
return '<Ignore>' return '<Ignore>'
end, { expr = true }) end, { expr = true })
-- Actions
map({ 'n', 'v' }, '<leader>hs', ':Gitsigns stage_hunk<CR>')
map({ 'n', 'v' }, '<leader>hr', ':Gitsigns reset_hunk<CR>')
map('n', '<leader>hS', gs.stage_buffer)
map('n', '<leader>ha', gs.stage_hunk)
map('n', '<leader>hu', gs.undo_stage_hunk)
map('n', '<leader>hR', gs.reset_buffer)
map('n', '<leader>hp', gs.preview_hunk)
map('n', '<leader>hb', function()
gs.blame_line { full = true }
end)
map('n', '<leader>tB', gs.toggle_current_line_blame)
map('n', '<leader>hd', gs.diffthis)
map('n', '<leader>hD', function()
gs.diffthis '~'
end)
-- Text object
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end, end,
} }
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', '<leader>gs', neogit.open, { silent = true, noremap = true })
vim.keymap.set('n', '<leader>gc', ':Neogit commit<CR>', { silent = true, noremap = true })
vim.keymap.set('n', '<leader>gp', ':Neogit pull<CR>', { silent = true, noremap = true })
vim.keymap.set('n', '<leader>gP', ':Neogit push<CR>', { silent = true, noremap = true })
vim.keymap.set('n', '<leader>gb', ':Telescope git_branches<CR>', { silent = true, noremap = true })
vim.keymap.set('n', '<leader>gB', ':G blame<CR>', { 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,
},
} }

View File

@@ -5,6 +5,11 @@ return {
dependencies = { dependencies = {
{ 'nvim-telescope/telescope.nvim' }, { 'nvim-telescope/telescope.nvim' },
}, },
keys = {
{ 'n', 'gpd', '<cmd>lua require("goto-preview").goto_preview_definition()<CR>' },
{ 'n', 'gpi', '<cmd>lua require("goto-preview").goto_preview_implementation()<CR>' },
{ 'n', 'gP', '<cmd>lua require("goto-preview").close_all_windows()<CR>' },
},
config = function() config = function()
require('goto-preview').setup { require('goto-preview').setup {
width = 120, -- Width of the floating window width = 120, -- Width of the floating window

View File

@@ -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,
}

View File

@@ -1,7 +1,6 @@
return { return {
-- Fuzzy Finder (files, lsp, etc) -- Fuzzy Finder (files, lsp, etc)
-- https://github.com/nvim-telescope/telescope.nvim -- https://github.com/nvim-telescope/telescope.nvim
{
'nvim-telescope/telescope.nvim', 'nvim-telescope/telescope.nvim',
version = '*', version = '*',
lazy = false, lazy = false,
@@ -90,5 +89,4 @@ return {
}) })
end, { desc = '[/] Fuzzily search in current buffer]' }) end, { desc = '[/] Fuzzily search in current buffer]' })
end, end,
},
} }

View File

@@ -2,23 +2,20 @@ return {
'folke/trouble.nvim', 'folke/trouble.nvim',
lazy = false, lazy = false,
dependencies = 'nvim-tree/nvim-web-devicons', dependencies = 'nvim-tree/nvim-web-devicons',
config = function() keys = {
require('trouble').setup {
auto_preview = false,
auto_fold = true,
auto_close = true,
use_lsp_diagnostic_signs = true,
}
-- Keybindings
local wk = require 'which-key'
wk.add {
{ '<leader>xx', '<cmd>TroubleToggle<cr>', desc = 'Toggle Trouble' }, { '<leader>xx', '<cmd>TroubleToggle<cr>', desc = 'Toggle Trouble' },
{ '<leader>xw', '<cmd>TroubleToggle workspace_diagnostics<cr>', desc = 'Toggle Workspace Diagnostics' }, { '<leader>xw', '<cmd>TroubleToggle workspace_diagnostics<cr>', desc = 'Toggle Workspace Diagnostics' },
{ '<leader>xd', '<cmd>TroubleToggle document_diagnostics<cr>', desc = 'Toggle Document Diagnostics' }, { '<leader>xd', '<cmd>TroubleToggle document_diagnostics<cr>', desc = 'Toggle Document Diagnostics' },
{ '<leader>xl', '<cmd>TroubleToggle loclist<cr>', desc = 'Toggle Loclist' }, { '<leader>xl', '<cmd>TroubleToggle loclist<cr>', desc = 'Toggle Loclist' },
{ '<leader>xq', '<cmd>TroubleToggle quickfix<cr>', desc = 'Toggle Quickfix' }, { '<leader>xq', '<cmd>TroubleToggle quickfix<cr>', desc = 'Toggle Quickfix' },
{ 'gR', '<cmd>TroubleToggle lsp_references<cr>', desc = 'Toggle LSP References' }, { 'gR', '<cmd>TroubleToggle lsp_references<cr>', desc = 'Toggle LSP References' },
},
config = function()
require('trouble').setup {
auto_preview = false,
auto_fold = true,
auto_close = true,
use_lsp_diagnostic_signs = true,
} }
-- Diagnostic signs -- Diagnostic signs

View File

@@ -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
{
'<leader>b',
group = '[b] Buffer',
expand = function()
return require('which-key.extras').expand.buf()
end,
},
{ '<leader>c', group = '[c] Code' },
{ '<leader>d', group = '[d] Document' },
{ '<leader>g', group = '[g] Git' },
{ '<leader>l', group = '[l] LSP' },
{ '<leader>p', group = '[p] Project' },
{ '<leader>q', group = '[q] Quit' },
{ '<leader>s', group = '[s] Search' },
{ '<leader>t', group = '[t] Toggle' },
{ '<leader>w', group = '[w] Workspace' },
{ '<leader>x', group = '[z] Trouble' },
{ '<leader>z', group = '[x] FZF & Harpoon' },
{ '<leader>?', group = '[?] Help' },
{
'<leader>?w',
function()
wk.show { global = false }
end,
desc = 'Buffer Local Keymaps (which-key)',
},
-- Misc keybinds
{ 'QQ', ':q!<CR>', desc = 'Quit without saving' },
}
end,
}