nvim-config/lua/keybinds.lua
2023-03-27 16:07:20 -07:00

89 lines
3.5 KiB
Lua

local opts = { noremap = true, silent = true }
local map = vim.api.nvim_set_keymap
map('', '<Space>', '<Nop>', opts)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Window Navigation without needing <C-w> first
map('n', '<C-h>', '<C-w>h', opts)
map('n', '<C-j>', '<C-w>j', opts)
map('n', '<C-k>', '<C-w>k', opts)
map('n', '<C-l>', '<C-w>l', opts)
-- Stay in visual mode when indenting
map('v', '<', '<gv', opts)
map('v', '>', '>gv', opts)
-- Resize with C-arrow
map('n', '<C-Up>', '<cmd>resize -2<CR>', opts)
map('n', '<C-Down>', '<cmd>resize +2<CR>', opts)
map('n', '<C-Left>', '<cmd>vertical resize -2<CR>', opts)
map('n', '<C-Right>', '<cmd>vertical resize +2<CR>', opts)
-- Jump to column and row rather than first column in row
map('n', "'", '`', opts)
map('n', '`', "'", opts)
-- Close context menus
map('n', '<leader>q', '<cmd>cclose<CR>', opts)
-- Navigate buffers
map('n', '<S-l>', '<cmd>BufferLineCycleNext<CR>', opts) -- :bnext
map('n', '<S-h>', '<cmd>BufferLineCyclePrev<CR>', opts) -- :bprevious
map('n', ']b', '<cmd>BufferLineMoveNext<CR>', opts)
map('n', '[b', '<cmd>BufferLineMovePrev<CR>', opts)
map('n', '<leader>w', '<cmd>Bdelete<CR>', opts) -- don't close if unsaved
map('n', '<leader>c', '<cmd>Bdelete!<CR>', opts) -- close it no matter what B)
-- Navigate Git Signs
map('n', ']g', '<cmd>Gitsigns next_hunk<CR>', opts)
map('n', '[g', '<cmd>Gitsigns prev_hunk<CR>', opts)
-- Toggle Diagnostics
map('n', '<leader>de', '<cmd>lua vim.diagnostic.enable()<cr>', opts)
map('n', '<leader>dd', '<cmd>lua vim.diagnostic.disable()<cr>', opts)
-- NvimTree
map('n', '<leader>e', '<cmd>NvimTreeToggle<CR>', opts)
map('n', '<leader>o', '<cmd>NvimTreeFocus<CR>', opts)
-- Telescope (See also configs/telescope.lua)
map('n', '<leader>ff', '<cmd>Telescope find_files<CR>', opts)
map('n', '<leader>fw', '<cmd>Telescope live_grep<CR>', opts)
map('n', '<leader>fp', '<cmd>lua require("telescope.builtin").live_grep({ type_filter = "py" })<CR>', opts)
map('n', '<leader>fo', '<cmd>Telescope oldfiles<CR>', opts)
map('n', '<leader>fr', '<cmd>Telescope projects<CR>', opts) -- ahmedkhalf/project.nvim
map('n', '<leader>fb', '<cmd>Telescope buffers<CR>', opts)
map('n', '<leader>fh', '<cmd>Telescope help_tags<CR>', opts)
map('n', '<leader>fs', '<cmd>Telescope git_status<CR>', opts)
map('n', '<leader>fc', '<cmd>Telescope git_commits<CR>', opts)
map('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
-- Lspsaga (See also configs/lspsaga.lua)
--map("n", "gl", "<cmd>Lspsaga show_line_diagnostics<CR>", opts)
map('n', 'gpd', '<cmd>Lspsaga preview_definition<CR>', opts)
map('n', 'gs', '<cmd>Lspsaga signature_help<CR>', opts)
map('i', '<C-s>', '<cmd>Lspsaga signature_help<CR>', opts)
map('n', '<leader>lr', '<cmd>Lspsaga rename<CR>', opts)
map('n', '<leader>la', '<cmd>Lspsaga code_action<CR>', opts)
map('n', '<C-u>', "<cmd>lua require('lspsaga.action').smart_scroll_with_saga(-1)<CR>", opts)
map('n', '<C-d>', "<cmd>lua require('lspsaga.action').smart_scroll_with_saga(1)<CR>", opts)
-- Custom "toggle summary" function for blame
-- jkkj is a hack to refresh the git blame message since it doesn't update till the line changes
map('n', '<leader>s', '<cmd>GitBlameToggleSummary<CR>jkkj', opts)
-- LSP (see configs/lsp-installer.lua)
-- disable K in visual mode
map('v', 'K', '<Nop>', { noremap = false, silent = true })
-- Illuminate
map('n', '<C-n>', "<cmd>lua require('illuminate').goto_next_reference()<CR>", opts)
map('n', 'g<C-n>', "<cmd>lua require('illuminate').goto_prev_reference()<CR>", opts)
-- Ctrl+A to yank entire current buffer
map('n', '<C-a>', '<cmd>%y<CR>', opts)