local map = vim.api.nvim_set_keymap -- Avoid infinitely recursive definitions options = { noremap = true } -- 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', 'J', 'cnextzz', options) -- Go to next item in global qfixlist map('n', 'K', '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 } buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', options) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', options) buf_set_keymap('n', 'k', 'lua vim.lsp.buf.hover()', options) buf_set_keymap('n', 's', 'lua vim.lsp.buf.signature_help()', options) buf_set_keymap('n', 'r', 'lua vim.lsp.buf.rename()', options) buf_set_keymap('n', 'a', 'lua vim.lsp.buf.code_action()', { noremap = true }) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', options) buf_set_keymap('n', 'd', 'lua vim.lsp.diagnostic.show_line_diagnostics()', options) buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', options) buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', options) buf_set_keymap('n', 'Q', 'lua vim.diagnostic.set_qflist()', options) buf_set_keymap('n', 'F', 'lua vim.lsp.buf.formatting()', 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 }