dotfiles/.config/nvim/lua/keybindings.lua

58 lines
1.5 KiB
Lua

local function map(mode, combo, mapping, opts)
local options = {noremap = true}
if opts then
options = vim.tbl_extend('force', options, opts)
end
vim.api.nvim_set_keymap(mode, combo, mapping, options)
end
vim.g.mapleader = ' '
-- Navigate through panes using lead key and vim direction
map('', '<leader>h', ':wincmd h<CR>')
map('', '<leader>j', ':wincmd j<CR>')
map('', '<leader>k', ':wincmd k<CR>')
map('', '<leader>l', ':wincmd l<CR>')
-- Create splits and tabs
map('', '<leader>v', ':vsp<CR>')
map('', '<leader>b', ':sp<CR>')
map('', '<leader>W', ':tabnew<CR>')
-- Move to tab using lead key plus number
map('', '<leader>1', '1gt')
map('', '<leader>2', '2gt')
map('', '<leader>3', '3gt')
map('', '<leader>4', '4gt')
map('', '<leader>5', '5gt')
map('', '<leader>6', '6gt')
map('', '<leader>7', '7gt')
map('', '<leader>8', '8gt')
map('', '<leader>9', '9gt')
map('', '<leader>0', '10gt')
-- Open undotree panel
map('', '<leader>u', ':UndotreeToggle<CR>')
-- Open lazy.nvim
map('', '<leader>p', ':Lazy home<CR>')
--- Telescope ---
-- List project files
vim.keymap.set('', '<C-p>', function() require("telescope-config").project_files() end)
-- Grep through files in project
vim.keymap.set('', '<C-f>', ":Telescope live_grep<CR>")
--- Miscellaneous
-- Toggle line wrap
vim.keymap.set('', '<leader>w', function()
vim.cmd("set wrap! linebreak! nolist!")
end)
-- Format markdown tables
map('', '<leader>t', ":TableFormat<CR>")
-- Open lazy.nvim menu
map('', '<leader>lh', ":Lazy home<CR>")