----------------------------------------------------------- -- Define keymaps for Neovim and plugins. ----------------------------------------------------------- local function map(mode, lhs, rhs, opts) local options = { noremap = true, silent = true } if opts then options = vim.tbl_extend('force', options, opts) end vim.api.nvim_set_keymap(mode, lhs, rhs, options) end -- Change leader to a comma vim.g.mapleader = ',' vim.g.maplocalleader = ' ' ----------------------------------------------------------- -- General ----------------------------------------------------------- -- Clear search highlighting map('n', '/', ':nohlsearch') -- Save current buffer map('n', 's', ':up') -- Move to previous buffer map('n', 'bp', ':bp') -- Move to next buffer map('n', 'bn', ':bn') -- Delete current buffer map('n', 'bd', ':bd') -- Close the quickfix window map('n', 'cq', ':ccl') -- Create a vertical split map('n', 'v', ':vsplit') -- These appear broken with latest neovim, and nvim-cmp has -- settings that work in any case. Keep as a reminder for a -- few weeks just in case. -- Use Tab to jump to the next option in a popup menu --vim.keymap.set('i', '', function() -- return vim.fn.pumvisible() == 1 and '' or '' --end, {expr = true}) -- Use Shift+Tab to jump to the previous option in a popup menu --vim.keymap.set('i', '', function() -- return vim.fn.pumvisible() == 1 and '' or '' --end, {expr = true}) ----------------------------------------------------------- -- Telescope ----------------------------------------------------------- -- Use ';' to search active buffers map('n', ';', 'Telescope buffers') -- Use Ctrl+P to show a list of files map('n', '', 'Telescope find_files') -- Live Grep map('n', 'fg', 'Telescope live_grep') -- Metals commands map('n', 'fm', 'Telescope metals commands') -- Search project TODOs in Telescope map('n', 'ft', 'TodoTelescope') ----------------------------------------------------------- -- Trouble ----------------------------------------------------------- -- Show/hide Trouble map('n', 'xx', 'TroubleToggle') -- Show workspace diagnostics map('n', 'xw', 'TroubleToggle workspace_diagnostics') -- Show document diagnostics map('n', 'xd', 'TroubleToggle document_diagnostics') -- Show quickfix map('n', 'xq', 'TroubleToggle quickfix') -- Show local list map('n', 'xl', 'TroubleToggle loclist') -- Show LSP references map('n', 'xr', 'TroubleToggle lsp_references') -- Show project TODOs in Trouble map('n', 'xt', 'TodoTrouble') ----------------------------------------------------------- -- Floaterm ----------------------------------------------------------- -- Create a new floating terminal vim.g.floaterm_keymap_new = 'tc' -- Move to the previous terminal vim.g.floaterm_keymap_prev = 'tp' -- Move to the next terminal vim.g.floaterm_keymap_next = 'tn' -- Toggle the visibility of the floating terminal vim.g.floaterm_keymap_toggle = 'tt' ----------------------------------------------------------- -- nvim-tree ----------------------------------------------------------- -- Toggle the file tree map('n', 'tt', 'NvimTreeToggle') -- Find the current buffer in the file tree map('n', 'tf', 'NvimTreeFindFile') ----------------------------------------------------------- -- LSP ----------------------------------------------------------- map('n', 'K', 'lua vim.lsp.buf.hover()') map('n', 'gi', 'lua vim.lsp.buf.implementation()') map('n', 'gr', 'lua vim.lsp.buf.references()') map('n', 'gds', 'lua vim.lsp.buf.document_symbol()') map('n', 'gws', 'lua vim.lsp.buf.workspace_symbol()') map('n', 'gd', 'lua vim.lsp.buf.definition()') map('n', 'cl', 'lua vim.lsp.codelens.run()') map('n', 'D', 'lua vim.lsp.buf.type_definition()') map('n', 'rn', 'lua vim.lsp.buf.rename()') map('n', 'ca', 'lua vim.lsp.buf.code_action()') map('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()') map('n', '[c', 'lua vim.diagnostic.goto_prev { wrap = false }') map('n', ']c', 'lua vim.diagnostic.goto_next { wrap = false }')