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 -- 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 opts = { buffer = bufnr, remap = false } vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, opts) vim.keymap.set('n', 'k', function() vim.lsp.buf.hover() end, opts) vim.keymap.set('n', 'r', function() vim.lsp.buf.rename() end, opts) vim.keymap.set('n', 'a', function() vim.lsp.buf.code_action() end, opts) vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() end, opts) vim.keymap.set('n', 'd', function() vim.diagnostic.open_float() end, opts) vim.keymap.set('n', '[d', function() vim.diagnostic.goto_prev() end, opts) vim.keymap.set('n', ']d', function() vim.diagnostic.goto_next() end, opts) vim.keymap.set('n', 'Q', function() vim.diagnostic.set_qflist() end, opts) vim.keymap.set('n', 'F', function() vim.lsp.buf.format() end, opts) end local cmp = require('cmp') local cmp_select = {behavior = cmp.SelectBehavior.Select} local cmp_mappings = { [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), [''] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true, }), [''] = cmp.mapping.abort(), } return { on_attach = on_attach, cmp_mappings = cmp_mappings }