2024-03-11 13:46:43 +00:00
function map ( mode , lhs , rhs , opts )
2024-03-15 11:40:59 +00:00
local options = { noremap = true , silent = true }
if opts then
options = vim.tbl_extend ( " force " , options , opts )
end
vim.keymap . set ( mode , lhs , rhs , options )
2024-03-11 13:46:43 +00:00
end
--This code just maps vim.keymap.set() to something easier to type. Also, typing { noremap = true, silent = true } won’ t be needed, because that is also implemented in the function.
vim.g . mapleader = " "
2024-03-15 11:40:59 +00:00
map ( " i " , " jk " , " <esc> " ) -- remap escape
2024-03-11 13:46:43 +00:00
map ( " n " , " <leader>+ " , " :bNext<cr> " ) --switch tabs
map ( " n " , " <leader>n " , " :Neotree toggle<cr> " ) --open Nerdtree
map ( " n " , " <leader>z " , " :ZenMode<cr> " ) --open ZenMode (distraction-free)
2024-03-11 22:29:52 +00:00
map ( " n " , " <leader>d " , " :ToggleDiag<cr> " ) -- toggle all diagnostics
2024-03-11 13:46:43 +00:00
2024-03-17 16:25:46 +00:00
vim.api . nvim_create_autocmd ( " LspAttach " , {
desc = " LSP actions " ,
callback = function ( )
local bufmap = function ( mode , lhs , rhs )
local opts = { buffer = true }
vim.keymap . set ( mode , lhs , rhs , opts )
end
-- Displays hover information about the symbol under the cursor
bufmap ( " n " , " K " , " <cmd>lua vim.lsp.buf.hover()<cr> " )
-- Jump to the definition
bufmap ( " n " , " gd " , " <cmd>lua vim.lsp.buf.definition()<cr> " )
-- Jump to declaration
bufmap ( " n " , " gD " , " <cmd>lua vim.lsp.buf.declaration()<cr> " )
-- Lists all the implementations for the symbol under the cursor
bufmap ( " n " , " gi " , " <cmd>lua vim.lsp.buf.implementation()<cr> " )
-- Jumps to the definition of the type symbol
bufmap ( " n " , " go " , " <cmd>lua vim.lsp.buf.type_definition()<cr> " )
-- Lists all the references
bufmap ( " n " , " gr " , " <cmd>lua vim.lsp.buf.references()<cr> " )
-- Displays a function's signature information
bufmap ( " n " , " gs " , " <cmd>lua vim.lsp.buf.signature_help()<cr> " )
-- Renames all references to the symbol under the cursor
bufmap ( " n " , " <F2> " , " <cmd>lua vim.lsp.buf.rename()<cr> " )
-- Selects a code action available at the current cursor position
bufmap ( " n " , " <F4> " , " <cmd>lua vim.lsp.buf.code_action()<cr> " )
-- Show diagnostics in a floating window
bufmap ( " n " , " gl " , " <cmd>lua vim.diagnostic.open_float()<cr> " )
-- Move to the previous diagnostic
bufmap ( " n " , " [d " , " <cmd>lua vim.diagnostic.goto_prev()<cr> " )
-- Move to the next diagnostic
bufmap ( " n " , " ]d " , " <cmd>lua vim.diagnostic.goto_next()<cr> " )
end ,
} )