Files
.dotfiles/.config/nvim/lua/config/maps.lua

46 lines
2.1 KiB
Lua

-- unmap arrow keys in non-insert modes
Map({ 'n', 'v' }, '<up>', '<nop>')
Map({ 'n', 'v' }, '<down>', '<nop>')
Map({ 'n', 'v' }, '<left>', '<nop>')
Map({ 'n', 'v' }, '<right>', '<nop>')
-- tab management / navigation
Map('n', '<c-t>', '<cmd>enew<cr>', { desc = 'create a new tab' })
-- for help exiting certain modes
Map({ 'n', 'i' }, '<esc>', '<cmd>nohlsearch<cr><esc>', { desc = 'cancel search highlighting and escape' })
Map('t', '<c-esc>', '<c-\\><c-n>', { desc = 'exit terminal mode' })
-- window management
Map('n', '<m-s>', '<cmd>wincmd s<cr>', { desc = 'horizontal split' })
Map('n', '<m-v>', '<cmd>wincmd v<cr>', { desc = 'vertical split' })
Map('n', '<c-h>', '<cmd>wincmd h<cr>', { desc = 'move focus to the left window' })
Map('n', '<c-l>', '<cmd>wincmd l<cr>', { desc = 'move focus to the right window' })
Map('n', '<c-j>', '<cmd>wincmd j<cr>', { desc = 'move focus to the lower window' })
Map('n', '<c-k>', '<cmd>wincmd k<cr>', { desc = 'move focus to the upper window' })
Map('n', '<m-H>', '<cmd>wincmd H<cr>', { desc = 'move window to left' })
Map('n', '<m-L>', '<cmd>wincmd L<cr>', { desc = 'move window to right' })
Map('n', '<m-K>', '<cmd>wincmd K<cr>', { desc = 'move window to top' })
Map('n', '<m-J>', '<cmd>wincmd J<cr>', { desc = 'move window to bottom' })
-- diagnostic / lsp key bindings
Map('n', 'K', vim.lsp.buf.hover, { desc = 'symbol hover' })
Map('n', '<F2>', vim.lsp.buf.rename, { desc = 'rename symbol' })
Map('n', '<leader>lm', vim.diagnostic.open_float, { desc = 'view line\'s diagnostic messages' })
Map('n', '<leader>q', vim.lsp.buf.code_action, { desc = 'view quickfix list' })
-- smart tabulation
Map('i', '<tab>', function()
local _, col = unpack(vim.api.nvim_win_get_cursor(0)) -- get cursor position
local isindent = vim.api.nvim_get_current_line():sub(1, col):match('^%s*$')
local tabexpnd = vim.bo.expandtab
local tabwidth = vim.bo.shiftwidth > 0 and vim.bo.shiftwidth or vim.bo.tabstop
if not tabexpnd and isindent then
return '\t'
else
local spaces = tabwidth - col % tabwidth
return string.rep(' ', spaces == 0 and tabwidth or spaces)
end
end, { expr = true, desc = "smart tabulation" })