-- Shorten function name local keymap = vim.keymap.set -- Silent keymap option local opts = { silent = true } --Remap space as leader key keymap("", "", "", opts) vim.g.mapleader = " " -- Modes -- normal_mode = "n", -- insert_mode = "i", -- visual_mode = "v", -- visual_block_mode = "x", -- term_mode = "t", -- command_mode = "c", -- Normal -- -- Better window navigation keymap("n", "", "h", opts) keymap("n", "", "j", opts) keymap("n", "", "k", opts) keymap("n", "", "l", opts) -- Resize with arrows keymap("n", "", ":resize -2", opts) keymap("n", "", ":resize +2", opts) keymap("n", "", ":vertical resize -2", opts) keymap("n", "", ":vertical resize +2", opts) -- Navigate buffers keymap("n", "", ":BufferLineCycleNext", opts) keymap("n", "", ":BufferLineCyclePrev", opts) keymap("n", "H", "", opts) keymap("n", "L", "", opts) keymap("n", "", ":BufferLineMoveNext", opts) keymap("n", "", ":BufferLineMovePrev", opts) for _, mode in ipairs({"n", "i", "v"}) do vim.keymap.set(mode, '', "BufferLineGoToBuffer 1", { noremap = true, silent = true }) vim.keymap.set(mode, '', "BufferLineGoToBuffer 2", { noremap = true, silent = true }) vim.keymap.set(mode, '', "BufferLineGoToBuffer 3", { noremap = true, silent = true }) vim.keymap.set(mode, '', "BufferLineGoToBuffer 4", { noremap = true, silent = true }) vim.keymap.set(mode, '', "BufferLineGoToBuffer 5", { noremap = true, silent = true }) end -- Clear highlights keymap("n", "h", "nohlsearch", opts) -- Close buffers keymap("n", "", "Bdelete", opts) keymap("n", "", "Bdelete!", opts) -- Better paste keymap("x", "p", '"_dP', opts) -- Insert -- -- Press jk fast to enter --keymap("i", "jk", "", opts) -- Visual -- -- Stay in indent mode keymap("v", "<", "", ">gv", opts) -- search with '-', for my LatinAmerican layour keymap("n", "-", "/", opts) keymap("x", "-", "/", opts) -- Plugins -- -- NvimTree keymap("n", "e", ":NvimTreeToggle", opts) -- Telescope keymap("n", "fa", ":Telescope find_files", opts) keymap("n", "ff", ":Telescope git_files", opts) keymap("n", "ft", ":Telescope live_grep", opts) keymap("n", "fp", ":Telescope projects", opts) keymap("n", "fb", ":Telescope buffers", opts) -- keymap("n", "fs", ":Telescope grep_string", opts) keymap("n", "fr", ":Telescope oldfiles", opts) function vim.getVisualSelection() vim.cmd('noau normal! "vy"') local text = vim.fn.getreg('v') vim.fn.setreg('v', {}) text = string.gsub(text, "\n", "") if #text > 0 then return text else return '' end end -- keymap('n', 'fs', ':Telescope current_buffer_fuzzy_find', opts) -- keymap('v', 'fs', function() -- local tb = require('telescope.builtin') -- local text = vim.getVisualSelection() -- tb.current_buffer_fuzzy_find({ default_text = text }) -- end, opts) keymap('n', 'fs', ':Telescope grep_string', opts) keymap('v', 'fs', function() local tb = require('telescope.builtin') local text = vim.getVisualSelection() tb.live_grep({ default_text = text }) end, opts) -- Git --keymap("n", "gg", "lua _LAZYGIT_TOGGLE()", opts) -- Comment keymap("n", "/", "lua require('Comment.api').toggle_current_linewise()", opts) keymap("x", "/", 'lua require("Comment.api").toggle_linewise_op(vim.fn.visualmode())') -- DAP keymap("n", "", "lua require'dap'.toggle_breakpoint()", opts) keymap("n", "", "lua require'dap'.continue()", opts) keymap("n", "", "lua require'dap'.step_over()", opts) keymap("n", "", "lua require'dap'.step_into()", opts) keymap("n", "", "lua require'dap'.step_out()", opts) keymap("n", "dr", "lua require'dap'.repl.toggle()", opts) keymap("n", "dl", "lua require'dap'.run_last()", opts) keymap("n", "du", "lua require'dapui'.toggle()", opts) keymap("n", "", "lua require'dap'.terminate()", opts) -- Shift+F5 ---- Vimspector --keymap("n", "", "VimspectorToggleBreakpoint", opts) --keymap("n", "", "VimspectorContinue", opts) --keymap("n", "", "VimspectorStepOver", opts) --keymap("n", "", "VimspectorStepInto", opts) --keymap("n", "", "VimspectorStepOut", opts) --keymap("n", "", "VimspectorReset", opts) -- Shift+F5 --keymap("n", "", "VimspectorRestart", opts) -- Ctrl+Shift+F5 --keymap("n", "di", "VimspectorBalloonEval", opts) -- move.nvim keymap('n', '', ':MoveLine(1)', opts) keymap('n', '', ':MoveLine(-1)', opts) keymap('x', '', ':MoveBlock(1)', opts) keymap('x', '', ':MoveBlock(-1)', opts) -- disable arrow keys keymap("n", "", "", opts) keymap("n", "", "", opts) keymap("n", "", "", opts) keymap("n", "", "", opts) keymap("i", "", "", opts) keymap("i", "", "", opts) keymap("i", "", "", opts) keymap("i", "", "", opts) -- move through wrapped lines keymap("n", "j", "gj") keymap("n", "k", "gk") local function clean_screen() vim.o.number = not vim.o.number; --if not vim.diagnostic.get_next() then return end if vim.o.number then vim.diagnostic.show() vim.opt.signcolumn = "yes" vim.cmd("syntax on") else vim.diagnostic.hide() vim.opt.signcolumn = "no" vim.cmd("syntax off") end end keymap("n", "n", clean_screen, opts) local function otherkeymaps() local ok local wk local gs ok, wk = pcall(require, "which-key") if not ok then return end ok, gs = pcall(require, "gitsigns") if not ok then return end wk.register({ g = { name = "gitsigns", p = { "Gitsigns preview_hunk", "Preview hunk" }, b = { function() gs.blame_line{full=false} end, "Blame line (short)" }, B = { function() gs.blame_line{full=true} end, "Blame line (full)" } }, prefix = "" }) end otherkeymaps()