138 lines
4.4 KiB
Lua
138 lines
4.4 KiB
Lua
-----------------------------------------------------------
|
|
-- 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', '<leader>/', ':nohlsearch<CR>')
|
|
|
|
-- Save current buffer
|
|
map('n', '<leader>s', ':up<CR>')
|
|
|
|
-- Move to previous buffer
|
|
map('n', '<leader>bp', ':bp<CR>')
|
|
|
|
-- Move to next buffer
|
|
map('n', '<leader>bn', ':bn<CR>')
|
|
|
|
-- Delete current buffer
|
|
map('n', '<leader>bd', ':bd<CR>')
|
|
|
|
-- Close the quickfix window
|
|
map('n', '<leader>cq', ':ccl<CR>')
|
|
|
|
-- 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', '<Tab>', function()
|
|
-- return vim.fn.pumvisible() == 1 and '<C-N>' or '<Tab>'
|
|
--end, {expr = true})
|
|
|
|
-- Use Shift+Tab to jump to the previous option in a popup menu
|
|
--vim.keymap.set('i', '<S-Tab>', function()
|
|
-- return vim.fn.pumvisible() == 1 and '<C-P>' or '<Tab>'
|
|
--end, {expr = true})
|
|
|
|
-----------------------------------------------------------
|
|
-- Telescope
|
|
-----------------------------------------------------------
|
|
|
|
-- Use ';' to search active buffers
|
|
map('n', ';', '<cmd>Telescope buffers<CR>')
|
|
|
|
-- Use Ctrl+P to show a list of files
|
|
map('n', '<C-P>', '<cmd>Telescope find_files<CR>')
|
|
|
|
-- Live Grep
|
|
map('n', '<leader>fg', '<cmd>Telescope live_grep<CR>')
|
|
|
|
-- Metals commands
|
|
map('n', '<leader>fm', '<cmd>Telescope metals commands<CR>')
|
|
|
|
-- Search project TODOs in Telescope
|
|
map('n', '<leader>ft', '<cmd>TodoTelescope<CR>')
|
|
|
|
-----------------------------------------------------------
|
|
-- Trouble
|
|
-----------------------------------------------------------
|
|
|
|
-- Show/hide Trouble
|
|
map('n', '<leader>xx', '<cmd>TroubleToggle<CR>')
|
|
|
|
-- Show workspace diagnostics
|
|
map('n', '<leader>xw', '<cmd>TroubleToggle workspace_diagnostics<CR>')
|
|
|
|
-- Show document diagnostics
|
|
map('n', '<leader>xd', '<cmd>TroubleToggle document_diagnostics<CR>')
|
|
|
|
-- Show quickfix
|
|
map('n', '<leader>xq', '<cmd>TroubleToggle quickfix<CR>')
|
|
|
|
-- Show local list
|
|
map('n', '<leader>xl', '<cmd>TroubleToggle loclist<CR>')
|
|
|
|
-- Show LSP references
|
|
map('n', '<leader>xr', '<cmd>TroubleToggle lsp_references<CR>')
|
|
|
|
-- Show project TODOs in Trouble
|
|
map('n', '<leader>xt', '<cmd>TodoTrouble<CR>')
|
|
|
|
-----------------------------------------------------------
|
|
-- Floaterm
|
|
-----------------------------------------------------------
|
|
|
|
-- Create a new floating terminal
|
|
vim.g.floaterm_keymap_new = '<leader>tc'
|
|
|
|
-- Move to the previous terminal
|
|
vim.g.floaterm_keymap_prev = '<leader>tp'
|
|
|
|
-- Move to the next terminal
|
|
vim.g.floaterm_keymap_next = '<leader>tn'
|
|
|
|
-- Toggle the visibility of the floating terminal
|
|
vim.g.floaterm_keymap_toggle = '<leader>tt'
|
|
|
|
-----------------------------------------------------------
|
|
-- nvim-tree
|
|
-----------------------------------------------------------
|
|
|
|
-- Toggle the file tree
|
|
map('n', '<C-A>tt', '<cmd>NvimTreeToggle<CR>')
|
|
|
|
-- Find the current buffer in the file tree
|
|
map('n', '<C-A>tf', '<cmd>NvimTreeFindFile<CR>')
|
|
|
|
-----------------------------------------------------------
|
|
-- LSP
|
|
-----------------------------------------------------------
|
|
|
|
map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>')
|
|
map('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
|
|
map('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>')
|
|
map('n', 'gds', '<cmd>lua vim.lsp.buf.document_symbol()<CR>')
|
|
map('n', 'gws', '<cmd>lua vim.lsp.buf.workspace_symbol()<CR>')
|
|
map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>')
|
|
map('n', '<leader>cl', '<cmd>lua vim.lsp.codelens.run()<CR>')
|
|
map('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>')
|
|
map('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>')
|
|
map('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>')
|
|
map('n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>')
|
|
map('n', '[c', '<cmd>lua vim.diagnostic.goto_prev { wrap = false }<CR>')
|
|
map('n', ']c', '<cmd>lua vim.diagnostic.goto_next { wrap = false }<CR>')
|