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', '', '', options) -- Exit Terminal mode enter Normal -- FILE NAVIGATION map('n', 'f', 'Telescope git_files', options) map('n', 'af', 'Telescope find_files', options) -- Grep project file contents with live results, respecting .gitignore map('n', 'g', "lua require('telescope.builtin').live_grep()", options) -- Telescope fuzzy search for buffers map('n', 'b', "lua require('telescope.builtin').buffers()", options) map('n', 'ga', '', options) -- ga to switch to last used buffer -- CODE NAVIGATOIN -- Quick Fix Lists -- global -- using control map('n', '', 'cnextzz', options) -- Go to next item in global qfixlist map('n', '', 'cprevzz', options) -- Go to previous item in global qfixlist -- Toggle the window if there are items in the qfixlist; allow recursive map('n', 'Q', 'call ToggleQFList(1)', {}) -- see plugin/navigation.vim for ToggleQFList definition -- local -- using leader map('n', 'j', 'lnextzz', options) -- Go to next item in local qfixlist map('n', 'k', 'lprevzz', options) -- Go to previous item in global qfixlist -- Toggle the window if there are items in the qfixlist; allow recursive map('n', 'q', 'call ToggleQFList(0)', {}) -- see plugin/navigation.vim for ToggleQFList definition -- GIT -- top level commands map('n', 'gs', 'G', options) -- Show git status map('n', 'gc', 'G commit', options) -- git commit map('n', 'gp', 'G push', {}) -- git push -- merge map('n', 'gh', 'diffget //2', options) -- merge from left pane map('n', 'gl', 'diffget //3', 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 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', 'k', function() vim.lsp.buf.hover() end, options) map('n', 's', function() vim.lsp.buf.signature_help() end, options) map('n', 'r', function() vim.lsp.buf.rename() end, options) map('n', 'a', function() vim.lsp.buf.code_action() end, options) map('n', 'gr', function() vim.lsp.buf.references() end, options) map('n', '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', 'Q', function() vim.diagnostic.set_qflist() end, options) map('n', 'F', function() vim.lsp.buf.formatting() end, options) end -- Code actions -- TODO: Generalize to LSP or only attach on Rust buffers map('n', 't', 'RustTest', options) -- Run test under cursor return { on_attach = on_attach }