neovim-confs/lua/custom/maps/init.lua

115 lines
6.4 KiB
Lua
Raw Normal View History

2024-07-04 11:26:39 +02:00
--------------------------------------------------------------------------------
-- Toggles
--------------------------------------------------------------------------------
-- 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', '<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' })
2024-07-04 16:20:45 +02:00
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' })
2024-07-04 11:26:39 +02:00
--------------------------------------------------------------------------------
2024-07-04 16:20:45 +02:00
-- Movements
2024-07-04 11:26:39 +02:00
--------------------------------------------------------------------------------
2024-07-04 16:20:45 +02:00
-- 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
2024-07-04 11:26:39 +02:00
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' })
2024-07-04 17:53:31 +02:00
vim.keymap.set('i', '<C-w>', '<esc>lwi', { desc = 'Go a word further' })
vim.keymap.set('i', '<C-b>', '<esc>lbi', { desc = 'Go a word backward' })
2024-07-04 11:26:39 +02:00
2024-07-04 16:20:45 +02:00
-- navigate hjkl in insert mode
2024-07-04 11:26:39 +02:00
vim.keymap.set('i', '<C-h>', '<Left>', { desc = 'Move left' })
2024-07-04 17:53:31 +02:00
vim.keymap.set('i', '<C-j>', '<Down>', { desc = 'Move down' })
vim.keymap.set('i', '<C-k>', '<Up>', { desc = 'Move up' })
vim.keymap.set('i', '<C-l>', '<Right>', { desc = 'Move right' })
2024-07-04 11:26:39 +02:00
2024-07-04 17:35:15 +02:00
-- move to window
-- See `:help wincmd` for a list of all window commands
vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
-- 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_next, { desc = 'Go to next [D]iagnostic message' })
-- let me out!!!
2024-07-04 19:03:42 +02:00
vim.keymap.set({ 'n', 'v' }, 'qqq', '<cmd>bd!<cr>', { desc = '[Q]uit the current window' })
vim.keymap.set({ 'n', 'v' }, '<A-c>', '<cmd>bw!<cr>', { desc = '[Q]uit the current window' })
2024-07-04 17:35:15 +02:00
2024-07-04 11:26:39 +02:00
--------------------------------------------------------------------------------
-- Workspace, buffer and window manipulation
--------------------------------------------------------------------------------
-- split windows
vim.keymap.set('n', '<leader>"', '<cmd>vsplit<cr>', { desc = 'Split the window vertically' })
vim.keymap.set('n', '<leader>%', '<cmd>split<cr>', { desc = 'Split the window horizontally' })
-- window actions
vim.keymap.set('n', '<leader>wbn', '<cmd>enew<cr>', { desc = 'Open a [N]ew [B]uffer' })
vim.keymap.set('n', '<leader>wbc', '<cmd>bw<cr>', { desc = '[C]lose current [B]uffer' }) -- :bd would keep in background
vim.keymap.set('n', '<C-Up>', '<cmd>resize +1<cr>', { desc = 'Resize window' })
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-Right>', '<cmd>vertical resize -1<cr>', { desc = 'Resize window vertically' })
-- tabs/workspaces
2024-07-04 19:03:42 +02:00
vim.keymap.set('n', '<Tab>', '<cmd>bnext<cr>', { desc = 'Next Buffer' })
vim.keymap.set('n', '<S-Tab>', '<cmd>bprev<cr>', { desc = 'Last Buffer' })
2024-07-04 11:26:39 +02:00
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>wk', '<cmd>tabnext<cr>', { desc = 'Next [W]orkspace/Tab' })
vim.keymap.set('n', '<leader>wj', '<cmd>tabprevious<cr>', { desc = 'Last [W]orkspace/Tab' })
2024-07-04 16:20:45 +02:00
vim.keymap.set('t', '<C-w>', vim.api.nvim_replace_termcodes('<C-\\><C-N>', true, true, true), { desc = 'Leave terminal mode' })
--------------------------------------------------------------------------------
-- 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' })