You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.6 KiB
Lua

local map = vim.keymap.set
-- Avoid infinitely recursive definitions
options = { noremap = true }
-- Navigation
map('n', 'gh', '0', options) -- make gh go to beginning of line
map('n', 'gl', '$', options) -- make gl go to end of line
map('n', 'gk', 'gg', options) -- make gk go to top of document
map('n', 'gj', 'G', options) -- make gj go to bottom of document
-- WINDOW MANAGEMENT
-- Terminal
map('t', '<C-e>', '<C-\\><C-n>', options) -- Exit Terminal mode enter Normal
-- FILE NAVIGATION
map('n', '<leader>f', '<cmd>Telescope git_files<CR>', options)
map('n', '<leader>af', '<cmd>Telescope find_files<CR>', options)
-- Grep project file contents with live results, respecting .gitignore
map('n', '<leader>g', "<cmd>lua require('telescope.builtin').live_grep()<CR>", options)
-- Telescope fuzzy search for buffers
map('n', '<leader>b', "<cmd>lua require('telescope.builtin').buffers()<CR>", options)
map('n', 'ga', '<C-^><CR>', options) -- ga to switch to last used buffer
-- CODE NAVIGATOIN
-- Quick Fix Lists
-- global -- using control
map('n', '<C-n>', '<cmd>cnext<CR>zz', options) -- Go to next item in global qfixlist
map('n', '<C-p>', '<cmd>cprev<CR>zz', options) -- Go to previous item in global qfixlist
-- Toggle the window if there are items in the qfixlist; allow recursive
map('n', 'Q', '<cmd>call ToggleQFList(1)<CR>', {}) -- see plugin/navigation.vim for ToggleQFList definition
-- local -- using leader
map('n', '<leader>j', '<cmd>lnext<CR>zz', options) -- Go to next item in local qfixlist
map('n', '<leader>k', '<cmd>lprev<CR>zz', options) -- Go to previous item in global qfixlist
-- Toggle the window if there are items in the qfixlist; allow recursive
map('n', '<leader>q', '<cmd>call ToggleQFList(0)<CR>', {}) -- see plugin/navigation.vim for ToggleQFList definition
-- GIT
-- top level commands
map('n', '<leader>gs', '<cmd>G<CR>', options) -- Show git status
map('n', '<leader>gc', '<cmd>G commit<CR>', options) -- git commit
map('n', '<leader>gp', '<cmd>G push<CR>', {}) -- git push
-- merge
map('n', '<leader>gh', '<cmd>diffget //2<CR>', options) -- merge from left pane
map('n', '<leader>gl', '<cmd>diffget //3<CR>', options) -- merge from right pane
-- LSP
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
map('n', 'gD', function() vim.lsp.buf.declaration() end, options)
map('n', 'gd', function() vim.lsp.buf.definition() end, options)
map('n', '<leader>k', function() vim.lsp.buf.hover() end, options)
map('n', '<leader>s', function() vim.lsp.buf.signature_help() end, options)
map('n', '<leader>r', function() vim.lsp.buf.rename() end, options)
map('n', '<leader>a', function() vim.lsp.buf.code_action() end, options)
map('n', 'gr', function() vim.lsp.buf.references() end, options)
map('n', '<leader>d', function() vim.diagnostic.open_float() end, options)
map('n', '[d', function() vim.diagnostic.goto_prev() end, options)
map('n', ']d', function() vim.diagnostic.goto_next() end, options)
map('n', '<leader>Q', function() vim.diagnostic.set_qflist() end, options)
map('n', '<leader>F', function() vim.lsp.buf.format() end, options)
end
-- Code actions
-- TODO: Generalize to LSP or only attach on Rust buffers
map('n', '<leader>t', '<cmd>RustTest<CR>', options) -- Run test under cursor
return { on_attach = on_attach }