local function map(mode, lhs, rhs, opts) local options = {noremap = false} if opts then options = vim.tbl_extend('force', options, opts) end vim.api.nvim_set_keymap(mode, lhs, rhs, options) end local function noremap(mode, lhs, rhs, opts) local options = {noremap = true} if opts then options = vim.tbl_extend('force', options, opts) end vim.api.nvim_set_keymap(mode, lhs, rhs, options) end -- leader vim.g.mapleader = ' ' -- visual block indenting noremap('v', '<', '', '>gv') -- centered cursor noremap('n', 'n', 'nzz') noremap('n', 'N', 'Nzz') noremap('n', 'J', 'mzJ`z') -- escape terminal mode noremap('t', '', '') -- newline without entering insert mode noremap('n', '', 'o') noremap('n', '', 'O') -- movement noremap('n', 'h', ':wincmd h') noremap('n', 'j', ':wincmd j') noremap('n', 'k', ':wincmd k') noremap('n', 'l', ':wincmd l') -- splits and buffers noremap('n', 'sv', ':vsplit') noremap('n', 'sz', ':split') noremap('n', 'st', ':tabnew') noremap('n', 'sb', ':Telescope buffers') noremap('n', 'sh', ':tabprevious') noremap('n', 'sl', ':tabnext') -- basics noremap('n', 'q', ':q') noremap('n', 'Q', ':qa') noremap('n', 'x', ':q!') noremap('n', 'X', ':qa!') noremap('n', 'w', ':w') noremap('n', 'W', ':wa') noremap('n', 'f', ':NvimTreeToggle') noremap('n', 'F', ':Telescope find_files') -- toggle term noremap('n', 'c', ':ToggleTermToggleAll') noremap('n', 'C', ':ToggleTerm') -- frequent actions noremap('n', 'ar', ':source ~/.config/nvim/init.lua') noremap('n', 'ac', ':cd ~/.config/nvim/') -- keymap switches noremap('n', 'me', ':set keymap=') noremap('n', 'mh', ':set keymap=hebrew') -- telescope noremap('n', 'tt', ':Telescope') noremap('n', 'tl', ':Telescope lsp_dynamic_workspace_symbols') noremap('n', 'to', ':Telescope oldfiles') noremap('n', 'tg', ':Telescope live_grep') noremap('n', 'ts', ':Telescope treesitter') noremap('n', 'tm', ':Telescope git_status') noremap('n', 'tb', ':Telescope git_branches') noremap('n', 'tc', ':Telescope git_commits') noremap('n', 'tf', ':Telescope git_files') -- code noremap('n', 'gf', ':Neoformat') noremap('n', 'gd', ':Telescope lsp_definitions') noremap('n', 'gi', ':Telescope lsp_implementations') noremap('n', 'gr', ':Telescope lsp_references') noremap('n', 'ga', ':Telescope lsp_code_actions') noremap('n', 'gq', ':Telescope lsp_workspace_diagnostics') noremap('n', 'gD', ':lua vim.lsp.buf.declaration()') noremap('n', 'gk', ':lua vim.lsp.buf.hover()') noremap('n', 'gt', ':lua vim.lsp.buf.type_definition()') noremap('n', 'gn', ':lua vim.lsp.buf.rename()') noremap('n', 'ge', ':lua vim.lsp.diagnostic.show_line_diagnostics()') noremap('n', '[d', ':lua vim.lsp.diagnostic.goto_prev()') noremap('n', ']d', ':lua vim.lsp.diagnostic.goto_next()') -- debug mappings noremap('n', 'dc', ":lua require'dap'.continue()") noremap('n', 'dn', ":lua require'dap'.step_over()") noremap('n', 'di', ":lua require'dap'.step_into()") noremap('n', 'do', ":lua require'dap'.step_out()") noremap('n', 'db', ":lua require'dap'.toggle_breakpoint()") noremap('n', 'dl', ":lua require'dap'.run_last()") noremap('n', 'dq', ":lua require'dap'.close()") noremap('n', 'dv', ':Telescope dap variables') noremap('n', 'dh', ':Telescope dap commands') noremap('n', 'dp', ':Telescope dap list_breakpoints') noremap('n', 'du', ":lua require'dapui'.toggle()") -- vsnip jumpable mappings map('i', '', "vsnip#jumpable(1) ? '(vsnip-jump-next)' : ''", {expr = true}) map('s', '', "vsnip#jumpable(1) ? '(vsnip-jump-next)' : ''", {expr = true}) map('i', '', "vsnip#jumpable(-1) ? '(vsnip-jump-next)' : ''", {expr = true}) map('s', '', "vsnip#jumpable(-1) ? '(vsnip-jump-next)' : ''", {expr = true})