2024-07-21 22:02:50 +02:00
|
|
|
-- [[ Basic Keymaps ]]
|
|
|
|
-- See `:help vim.keymap.set()`
|
|
|
|
|
|
|
|
-- Set highlight on search, but clear on pressing <Esc> in normal mode
|
|
|
|
vim.opt.hlsearch = true
|
|
|
|
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
|
|
|
|
|
|
|
|
-- Diagnostic keymaps
|
2024-08-06 12:14:44 +02:00
|
|
|
---@diagnostic disable-next-line: deprecated
|
2024-07-21 22:02:50 +02:00
|
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
|
2024-08-06 12:14:44 +02:00
|
|
|
---@diagnostic disable-next-line: deprecated
|
2024-07-21 22:02:50 +02:00
|
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
|
2024-08-06 12:14:44 +02:00
|
|
|
|
2024-07-21 22:02:50 +02:00
|
|
|
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
|
|
|
|
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
|
|
|
|
|
2024-08-03 21:56:21 +02:00
|
|
|
vim.keymap.set('n', '<leader>l', '<cmd>Lazy<CR>', { desc = 'Lazy plugin manager' })
|
2024-08-25 01:40:24 +02:00
|
|
|
vim.keymap.set('n', '<leader>1', '<cmd>!!<CR>', { desc = 'Run last command' })
|
2024-08-03 21:56:21 +02:00
|
|
|
|
2024-07-21 22:02:50 +02:00
|
|
|
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
|
|
|
|
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
|
|
|
|
-- is not what someone will guess without a bit more experience.
|
|
|
|
--
|
|
|
|
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
|
|
|
|
-- or just use <C-\><C-n> to exit terminal mode
|
|
|
|
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
|
|
|
|
|
|
|
|
-- TIP: Disable arrow keys in normal mode
|
|
|
|
vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
|
|
|
|
vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
|
|
|
|
vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
|
|
|
|
vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
|
|
|
|
|
2024-08-01 00:39:27 +02:00
|
|
|
-- Resize windows
|
2024-08-07 18:03:09 +02:00
|
|
|
vim.keymap.set('n', '<C-Up>', '<cmd>resize +2<cr>', { desc = 'Increase Window Height' })
|
|
|
|
vim.keymap.set('n', '<C-Down>', '<cmd>resize -2<cr>', { desc = 'Decrease Window Height' })
|
|
|
|
vim.keymap.set('n', '<C-Left>', '<cmd>vertical resize -2<cr>', { desc = 'Decrease Window Width' })
|
|
|
|
vim.keymap.set('n', '<C-Right>', '<cmd>vertical resize +2<cr>', { desc = 'Increase Window Width' })
|
2024-08-01 00:39:27 +02:00
|
|
|
vim.keymap.set('n', '<C-S-0>', '<cmd>wincmd =<CR>', { desc = 'Set height/width equal' })
|
|
|
|
|
2024-07-21 22:02:50 +02:00
|
|
|
-- Keybinds to make split navigation easier.
|
|
|
|
-- Use CTRL+<hjkl> to switch between windows
|
|
|
|
--
|
|
|
|
-- 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' })
|
|
|
|
|
2024-08-07 18:16:14 +02:00
|
|
|
-- Move Lines
|
|
|
|
vim.keymap.set('n', '<A-j>', '<cmd>m .+1<cr>==', { desc = 'Move Down' })
|
|
|
|
vim.keymap.set('n', '<A-k>', '<cmd>m .-2<cr>==', { desc = 'Move Up' })
|
|
|
|
vim.keymap.set('i', '<A-j>', '<esc><cmd>m .+1<cr>==gi', { desc = 'Move Down' })
|
|
|
|
vim.keymap.set('i', '<A-k>', '<esc><cmd>m .-2<cr>==gi', { desc = 'Move Up' })
|
|
|
|
vim.keymap.set('v', '<A-j>', ":m '>+1<cr>gv=gv", { desc = 'Move Down' })
|
|
|
|
vim.keymap.set('v', '<A-k>', ":m '<-2<cr>gv=gv", { desc = 'Move Up' })
|
2024-07-21 22:02:50 +02:00
|
|
|
|
2024-08-07 18:02:47 +02:00
|
|
|
-- https://github.com/mhinz/vim-galore#saner-behavior-of-n-and-n
|
|
|
|
vim.keymap.set('n', 'n', "'Nn'[v:searchforward].'zv'", { expr = true, desc = 'Next Search Result' })
|
|
|
|
vim.keymap.set('x', 'n', "'Nn'[v:searchforward]", { expr = true, desc = 'Next Search Result' })
|
|
|
|
vim.keymap.set('o', 'n', "'Nn'[v:searchforward]", { expr = true, desc = 'Next Search Result' })
|
|
|
|
vim.keymap.set('n', 'N', "'nN'[v:searchforward].'zv'", { expr = true, desc = 'Prev Search Result' })
|
|
|
|
vim.keymap.set('x', 'N', "'nN'[v:searchforward]", { expr = true, desc = 'Prev Search Result' })
|
|
|
|
vim.keymap.set('o', 'N', "'nN'[v:searchforward]", { expr = true, desc = 'Prev Search Result' })
|
|
|
|
|
|
|
|
-- Buffers
|
|
|
|
vim.keymap.set('n', '<S-h>', '<cmd>bprevious<cr>', { desc = 'Prev Buffer' })
|
|
|
|
vim.keymap.set('n', '<S-l>', '<cmd>bnext<cr>', { desc = 'Next Buffer' })
|
|
|
|
vim.keymap.set('n', '<leader>bb', '<cmd>e #<cr>', { desc = 'Switch to Other Buffer' })
|
2024-10-24 11:22:31 +02:00
|
|
|
vim.keymap.set('n', '<leader>bd', '<cmd>:bd<cr>', { desc = 'Delete Buffer and Window' })
|
2024-10-24 12:30:48 +02:00
|
|
|
vim.keymap.set('n', '<leader>bD', '<cmd>:bd!<cr>', { desc = 'Force Delete Buffer and Window (discard changes)' })
|
2024-10-24 11:22:31 +02:00
|
|
|
vim.keymap.set('n', '<leader>bo', '<cmd>%bd|e#|bd#<cr>', { desc = 'Delete Other Buffers' })
|
2024-10-24 12:30:48 +02:00
|
|
|
vim.keymap.set('n', '<leader>br', '<cmd>:e! %<cr>', { desc = '[B]uffer [R]eload (discard changes)' })
|
2024-08-07 18:02:47 +02:00
|
|
|
|
|
|
|
-- Tabs
|
|
|
|
vim.keymap.set('n', '<leader><tab>l', '<cmd>tablast<cr>', { desc = 'Last Tab' })
|
|
|
|
vim.keymap.set('n', '<leader><tab>o', '<cmd>tabonly<cr>', { desc = 'Close Other Tabs' })
|
|
|
|
vim.keymap.set('n', '<leader><tab>f', '<cmd>tabfirst<cr>', { desc = 'First Tab' })
|
|
|
|
vim.keymap.set('n', '<leader><tab><tab>', '<cmd>tabnew<cr>', { desc = 'New Tab' })
|
|
|
|
vim.keymap.set('n', '<leader><tab>d', '<cmd>tabclose<cr>', { desc = 'Close Tab' })
|
|
|
|
vim.keymap.set('n', '<leader><tab>]', '<cmd>tabnext<cr>', { desc = 'Next Tab' })
|
|
|
|
vim.keymap.set('n', '<leader><tab>[', '<cmd>tabprevious<cr>', { desc = 'Previous Tab' })
|
|
|
|
|
2024-12-14 18:17:19 +01:00
|
|
|
vim.keymap.set('n', '\\', '<cmd>Neotree toggle<cr>', { desc = 'Toggle Neotree' })
|
2024-12-14 20:59:27 +01:00
|
|
|
vim.keymap.set('n', '0', '<cmd>ToggleTerm<cr>', { desc = 'Toggle Terminal' })
|
2024-12-14 18:17:19 +01:00
|
|
|
|
2024-11-12 16:31:04 +01:00
|
|
|
-- Define a function to wrap lines to 80 columns
|
|
|
|
vim.keymap.set('n', '<leader>dw', function()
|
|
|
|
-- Save the current 'textwidth' setting
|
|
|
|
local current_tw = vim.o.textwidth
|
|
|
|
|
|
|
|
-- Set 'textwidth' to 80 temporarily
|
|
|
|
vim.o.textwidth = 80
|
|
|
|
|
|
|
|
-- Reformat all lines in the buffer
|
|
|
|
vim.api.nvim_command 'normal! ggVGgq'
|
|
|
|
|
|
|
|
-- Restore the original 'textwidth'
|
|
|
|
vim.o.textwidth = current_tw
|
|
|
|
end, { desc = '[D]ocument [W]rap to 80 column width' })
|
|
|
|
|
2024-07-21 22:14:58 +02:00
|
|
|
-- vim: ts=2 sts=2 sw=2 et
|