local set = vim.keymap.set local silent = { silent = true } ---@param mode string|table ---@param keymap string local function unbind(mode, keymap) set(mode, keymap, function() end) end local function toggle_zen() vim.cmd('Neotree close') vim.cmd('Trouble todo close') vim.cmd('UndotreeHide') end local function paste() local value = vim.fn.getreg('+') if vim.fn.mode() == 'c' then -- value = vim.split(value, '\n')[1] -- only use first line (default with normal pasting) value = value:gsub('\n', ' ') -- replace newlines with spaces vim.api.nvim_feedkeys(value, 'c', false) else vim.api.nvim_put({ value }, 'c', true, true) end end -- "Greatest Keymap ever" - ThePrimeagen -- https://www.youtube.com/watch?v=qZO9A5F6BZs&list=PLm323Lc7iSW_wuxqmKx_xxNtJC_hJbQ7R&index=4 set('x', 'p', '"_dP') -- Misc set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) set('i', '', '', { desc = 'Ctrl + Backspace to delete word' }) set('n', '', 'nohlsearch', silent) set({ 'i', 'c' }, '', paste) set('n', 'z', toggle_zen, { desc = '[Z]en Mode', silent = true }) unbind({ 'i', 'n', 'v' }, '') set('n', 'U', 'redo') set('i', '', 'undo') set('i', '', 'undo') set({ 'i', 'n', 'v' }, '', 'wqa') -- Window Navigation - NO NEED BECAUSE IT CONFLICTS WITH TMUX -- set('n', '', '', { desc = 'Move focus to the left window' }) -- set('n', '', '', { desc = 'Move focus to the down window' }) -- set('n', '', '', { desc = 'Move focus to the up window' }) -- set('n', '', '', { desc = 'Move focus to the right window' }) -- Window resizing local resize = 2 set({ 'n', 't' }, '', string.format('vertical resize -%d', resize), { desc = 'Resize Left' }) set({ 'n', 't' }, '', string.format('resize -%d', resize), { desc = 'Resize Up' }) set({ 'n', 't' }, '', string.format('resize +%d', resize), { desc = 'Resize Down' }) set({ 'n', 't' }, '', string.format('vertical resize +%d', resize), { desc = 'Resize Right' }) -- Keep selection after < and > in visual mode set('v', '<', '', '>gv') -- Execute lua file or line set('n', 'x', '.lua', { desc = 'Execute the current line' }) set('n', 'x', 'source %', { desc = 'Execute the current file' }) -- Reformats file using lsp set('n', '=', vim.lsp.buf.format, { desc = 'Format File' })