This commit is contained in:
Christoph J. Scherr 2024-07-04 16:20:45 +02:00
parent 4014b7dd9d
commit 4d741c98d6
4 changed files with 77 additions and 58 deletions

View File

@ -4,20 +4,33 @@
-- Clear highlighted searched on pressing <Esc> in normal mode -- Clear highlighted searched on pressing <Esc> in normal mode
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>', { desc = 'Hide search results' }) vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>', { desc = 'Hide search results' })
-- line numbers
vim.keymap.set('n', '<leader>tn', '<cmd> set nu! <cr>', { desc = '[T]oggle line [N]umbers' }) vim.keymap.set('n', '<leader>tn', '<cmd> set nu! <cr>', { desc = '[T]oggle line [N]umbers' })
vim.keymap.set('n', '<leader>trn', '<cmd> set rnu! <cr>', { desc = '[T]oggle [R]elative line [N]umbers' }) vim.keymap.set('n', '<leader>trn', '<cmd> set rnu! <cr>', { desc = '[T]oggle [R]elative line [N]umbers' })
vim.keymap.set('n', '<leader>tw', '<cmd> set wrap! <cr>', { desc = '[T]oggle [W]rap' })
vim.keymap.set('n', '<leader>ts', '<cmd> set spell! <cr>', { desc = '[T]oggle [S]pellcheck' })
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Insert movements -- Movements
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- go to beginning and end -- make big movements up and down
vim.keymap.set({ 't', 'i', 'v', 'n' }, '<A-j>', '<C-d>', { desc = 'move a many lines up' })
vim.keymap.set({ 't', 'i', 'v', 'n' }, '<A-k>', '<C-u>', { desc = 'move a many lines down' })
-- move to end and start of lines with H and L
vim.keymap.set({ 'v', 'n' }, 'H', '<Home>', { desc = 'move to start of line' })
vim.keymap.set({ 'v', 'n' }, 'L', '<End>', { desc = 'move to end of line' })
-- move+scroll
vim.keymap.set({ 'v', 'n' }, 'zk', '<C-e>', { desc = 'move and scroll up' })
vim.keymap.set({ 'v', 'n' }, 'zj', '<C-y>', { desc = 'move and scroll down' })
-- go to beginning and end in insert mode
vim.keymap.set('i', '<C-s>', '<esc>^i', { desc = 'Go to the start of the line' }) vim.keymap.set('i', '<C-s>', '<esc>^i', { desc = 'Go to the start of the line' })
vim.keymap.set('i', '<C-e>', '<End>', { desc = 'Go to the end of the line' }) vim.keymap.set('i', '<C-e>', '<End>', { desc = 'Go to the end of the line' })
vim.keymap.set('i', '<C-w>', '<esc>wa', { desc = 'Go a word further' }) vim.keymap.set('i', '<C-w>', '<esc>wa', { desc = 'Go a word further' })
vim.keymap.set('i', '<C-b>', '<esc>ba', { desc = 'Go a word backward' }) vim.keymap.set('i', '<C-b>', '<esc>ba', { desc = 'Go a word backward' })
-- navigate within insert mode -- navigate hjkl in insert mode
vim.keymap.set('i', '<C-h>', '<Left>', { desc = 'Move left' }) vim.keymap.set('i', '<C-h>', '<Left>', { desc = 'Move left' })
vim.keymap.set('i', '<C-j>', '<Right>', { desc = 'Move right' }) vim.keymap.set('i', '<C-j>', '<Right>', { desc = 'Move right' })
vim.keymap.set('i', '<C-k>', '<Down>', { desc = 'Move down' }) vim.keymap.set('i', '<C-k>', '<Down>', { desc = 'Move down' })
@ -38,13 +51,14 @@ vim.keymap.set('n', '<C-Down>', '<cmd>resize -1<cr>', { desc = 'Resize window' }
vim.keymap.set('n', '<C-Left>', '<cmd>vertical resize +1<cr>', { desc = 'Resize window vertically' }) vim.keymap.set('n', '<C-Left>', '<cmd>vertical resize +1<cr>', { desc = 'Resize window vertically' })
vim.keymap.set('n', '<C-Right>', '<cmd>vertical resize -1<cr>', { desc = 'Resize window vertically' }) vim.keymap.set('n', '<C-Right>', '<cmd>vertical resize -1<cr>', { desc = 'Resize window vertically' })
-- tabs/workspaces -- tabs/workspaces
vim.keymap.set('n', '<leader>wn', '<cmd>tabnew<cr>', { desc = 'Open a [N]ew [W]orkspace/Tab' }) vim.keymap.set('n', '<leader>wn', '<cmd>tabnew<cr>', { desc = 'Open a [N]ew [W]orkspace/Tab' })
vim.keymap.set('n', '<leader>wc', '<cmd>tabclose<cr>', { desc = '[C]lose a [W]orkspace/Tab' }) vim.keymap.set('n', '<leader>wc', '<cmd>tabclose<cr>', { desc = '[C]lose a [W]orkspace/Tab' })
vim.keymap.set('n', '<leader>wk', '<cmd>tabnext<cr>', { desc = 'Next [W]orkspace/Tab' }) vim.keymap.set('n', '<leader>wk', '<cmd>tabnext<cr>', { desc = 'Next [W]orkspace/Tab' })
vim.keymap.set('n', '<leader>wj', '<cmd>tabprevious<cr>', { desc = 'Last [W]orkspace/Tab' }) vim.keymap.set('n', '<leader>wj', '<cmd>tabprevious<cr>', { desc = 'Last [W]orkspace/Tab' })
vim.keymap.set('t', '<C-w>', vim.api.nvim_replace_termcodes('<C-\\><C-N>', true, true, true), { desc = 'Leave terminal mode' })
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Move to things -- Move to things
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -58,3 +72,40 @@ vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper win
-- diagnostics -- diagnostics
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
--------------------------------------------------------------------------------
-- Editing
--------------------------------------------------------------------------------
-- copy to system clipboard
vim.keymap.set({ 'n', 'v' }, '<leader>y', '"+y', { desc = '[Y]ank to system' })
vim.keymap.set({ 'n', 'v' }, '<leader>Y', '"+Y', { desc = '[Y]ank to system' })
vim.keymap.set({ 'n', 'v' }, '<leader>yy', '"+yy', { desc = '[Y]ank to system' })
vim.keymap.set({ 't', 'n', 'v' }, '<C-S-v>', '<C-w>"+pi', { desc = 'Paste the system clipboard' })
-- add lines from normal and visual, without insert mode
vim.keymap.set({ 'n', 'v' }, 'OO', 'O<Esc>', { desc = 'Insert a line above' })
vim.keymap.set({ 'n', 'v' }, 'oo', 'o<Esc>', { desc = 'Insert a line below' })
-- substitute, normally on 's', but the leap plugin is more useful on 's'
vim.keymap.set({ 'n' }, '<leader>s', 's', { desc = '[S]ubstitute hovered text' })
-- do something useful with the arrow keys:
-- move lines up/down and change indentation
vim.keymap.set({ 'n', 'v' }, '<Up>', '<cmd> move-2<cr>', { desc = 'Move line up' })
vim.keymap.set({ 'n', 'v' }, '<Down>', '<cmd> move+2<cr>', { desc = 'Move line down' })
vim.keymap.set({ 'n', 'v' }, '<Left>', '<<', { desc = 'Less indentation' })
vim.keymap.set({ 'n', 'v' }, '<Right>', '>>', { desc = 'More indentation' })
--------------------------------------------------------------------------------
-- Formating
--------------------------------------------------------------------------------
-- format the current buffer
vim.keymap.set('n', '<leader>ff', function()
require('conform').format()
end, { desc = '[F]ormat buffer' })
vim.keymap.set('n', '<leader>fF', function()
vim.lsp.buf.format()
end, { desc = '[F]ormat buffer (no plugin)' })
vim.keymap.set('n', '<leader>fw', function()
require('mini.trailspace').trim()
end, { desc = '[F]ormat remove [W]hitespace' })

View File

@ -17,49 +17,6 @@ return {
}, },
config = function() config = function()
require 'custom.plugins.configs.lsp' require 'custom.plugins.configs.lsp'
local cmp = require 'cmp' -- this is nvim-cmp
keys = {
{ '<C-k>', cmp.mapping.select_prev_item(), desc = 'Next completion' },
{ '<C-j>', cmp.mapping.select_next_item(), desc = 'Last completion' },
{ '<C-Space>', cmp.mapping.complete(), desc = 'Accept completion' },
{ '<C-e>', cmp.mapping.close(), desc = 'Hide completions' },
{ '<CR>', cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}, desc = 'Accept completion' },
{
'<Tab>',
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif require('luasnip').expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end, {
'i',
's',
}),
desc = 'Next completion',
},
{
'<S-Tab>',
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif require('luasnip').expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end, {
'i',
's',
}),
desc = 'Last completion',
},
},
end, end,
}, },
-- See `:help gitsigns` to understand what the configuration keys do -- See `:help gitsigns` to understand what the configuration keys do
@ -179,13 +136,13 @@ return {
-- Accept ([y]es) the completion. -- Accept ([y]es) the completion.
-- This will auto-import if your LSP supports it. -- This will auto-import if your LSP supports it.
-- This will expand snippets if the LSP sent a snippet. -- This will expand snippets if the LSP sent a snippet.
['<C-y>'] = cmp.mapping.confirm { select = true }, -- ['<C-y>'] = cmp.mapping.confirm { select = true },
-- If you prefer more traditional completion keymaps, -- If you prefer more traditional completion keymaps,
-- you can uncomment the following lines -- you can uncomment the following lines
--['<CR>'] = cmp.mapping.confirm { select = true }, ['<CR>'] = cmp.mapping.confirm { select = true },
--['<Tab>'] = cmp.mapping.select_next_item(), ['<Tab>'] = cmp.mapping.select_next_item(),
--['<S-Tab>'] = cmp.mapping.select_prev_item(), ['<S-Tab>'] = cmp.mapping.select_prev_item(),
-- Manually trigger a completion from nvim-cmp. -- Manually trigger a completion from nvim-cmp.
-- Generally you don't need this, because nvim-cmp will display -- Generally you don't need this, because nvim-cmp will display

View File

@ -96,6 +96,10 @@ return {
vim.keymap.set('n', '<localleader>fd', builtin.diagnostics, { desc = '[F]ind LSP [D]iagnostigs' }) vim.keymap.set('n', '<localleader>fd', builtin.diagnostics, { desc = '[F]ind LSP [D]iagnostigs' })
vim.keymap.set('n', '<localleader>fs', builtin.lsp_dynamic_workspace_symbols, { desc = '[F]ind LSP [S]ymbols' }) vim.keymap.set('n', '<localleader>fs', builtin.lsp_dynamic_workspace_symbols, { desc = '[F]ind LSP [S]ymbols' })
-- spelling
vim.keymap.set('n', 'z<space>', builtin.spell_suggest, { desc = '[F]ind spelling' })
vim.keymap.set('n', 'z=', builtin.spell_suggest, { desc = '[F]ind spelling' })
-- Slightly advanced example of overriding default behavior and theme -- Slightly advanced example of overriding default behavior and theme
vim.keymap.set('n', '<localleader>/', function() vim.keymap.set('n', '<localleader>/', function()
-- You can pass additional configuration to Telescope to change the theme, layout, etc. -- You can pass additional configuration to Telescope to change the theme, layout, etc.

View File

@ -13,6 +13,11 @@ return {
{ {
'ggandor/leap.nvim', 'ggandor/leap.nvim',
lazy = false, lazy = false,
keys = {
{ 's', '<plug>(leap-forward)', desc = 'leap forward' },
{ 'S', '<plug>(leap-backward)', desc = 'leap backward' },
{ 'gs', '<plug>(leap-from-window)', desc = 'leap from window' },
},
}, },
{ {
'ggandor/flit.nvim', 'ggandor/flit.nvim',
@ -31,7 +36,9 @@ return {
}, },
{ {
'kdheepak/lazygit.nvim', 'kdheepak/lazygit.nvim',
keys = { '<leader>gg', '<cmd> LazyGit <cr>', 'Open LazyGit' }, keys = {
{ '<leader>gg', '<cmd>LazyGit<cr>', desc = 'Open LazyGit' },
},
cmd = 'LazyGit', cmd = 'LazyGit',
-- optional for floating window border decoration -- optional for floating window border decoration
dependencies = { dependencies = {
@ -243,11 +250,11 @@ return {
{ {
'akinsho/toggleterm.nvim', 'akinsho/toggleterm.nvim',
keys = { keys = {
{ '<F12>', '<cmd>exe v:count1 "ToggleTerm direction=float"<cr>', desc = 'Toggle a big floating terminal' }, { '<F12>', mode = { 't', 'n', 'v' }, '<cmd>exe v:count1 "ToggleTerm direction=float"<cr>', desc = 'Toggle a big floating terminal' },
{ '<A-i>', '<cmd>exe v:count1 "ToggleTerm direction=float"<cr>', desc = 'Toggle a big floating terminal' }, { '<A-i>', mode = { 't', 'n', 'v' }, '<cmd>exe v:count1 "ToggleTerm direction=float"<cr>', desc = 'Toggle a big floating terminal' },
{ '<A-t>', '<cmd>exe v:count1 "ToggleTerm direction=tab"<cr>', desc = 'Toggle a terminal in a new tab' }, { '<A-t>', mode = { 't', 'n', 'v' }, '<cmd>exe v:count1 "ToggleTerm direction=tab"<cr>', desc = 'Toggle a terminal in a new tab' },
{ '<A-h>', '<cmd>exe v:count1 "ToggleTerm direction=horizontal"<cr>', desc = 'Toggle a horizontal terminal' }, { '<A-h>', mode = { 't', 'n', 'v' }, '<cmd>exe v:count1 "ToggleTerm direction=horizontal"<cr>', desc = 'Toggle a horizontal terminal' },
{ '<A-v>', '<cmd>exe v:count1 "ToggleTerm direction=vertical"<cr>', desc = 'Toggle a vertical terminal' }, { '<A-v>', mode = { 't', 'n', 'v' }, '<cmd>exe v:count1 "ToggleTerm direction=vertical"<cr>', desc = 'Toggle a vertical terminal' },
}, },
cmd = 'ToggleTerm', cmd = 'ToggleTerm',
opts = { opts = {