local map = vim.keymap.set local opts = { noremap = true, silent = true } vim.g.mapleader = ',' local function create_function_tabdo(command) return function() local curr_tab = vim.fn.tabpagenr() vim.cmd.tabdo(command) vim.cmd.tabn(curr_tab) end end -- Toggle line highlighting map('n', 'c', create_function_tabdo('set cursorline!'), opts) map('n', '/', function() vim.opt.hlsearch = not vim.opt.hlsearch["_value"] end, opts) map('i', 'jk', '', opts) map('i', 'ол', '', opts) -- x to blackhole map('n', 'x', '"_x', opts) -- Increment/decrement map('n', '+', '', opts) map('n', '-', '', opts) -- map \ to prev finding map({"n", "v"}, [[\]], ',', opts) -- Select all map('n', '', 'ggG', opts) -- Scroll tabs map("n", '', vim.cmd.tabnext, opts) map("n", '', vim.cmd.tabprev, opts) -- Kill current buffer map("n", 'qq', 'bd!', opts) -- Quick exit without saving map("n", 'qa', 'qa!', opts) map("n", 'eh', 'set list!', opts) vim.opt.listchars=[[tab:→\ ,eol:↵,trail:·,extends:↷,precedes:↶]] -- Tags panel (ctags required) map("n", 't', 'TagbarToggle', opts) -- Telescope map("n", 'ff', 'Telescope find_files', opts) map("n", 'fg', 'Telescope live_grep', opts) -- Expand %% to dirname of current file in command line map("c", '%%', [[getcmdtype() == ':' ? expand('%:h').'/' : '%%']], {expr = true}) -- Save from root vim.api.nvim_create_user_command('Sw', [[execute 'silent! write !SUDO_ASKPASS=$(command -v vim_askpass_helper) sudo -A tee % >/dev/null']], {}) -- Toggle line number style function toggle_number_style() local opt = vim.opt local number = opt.number["_value"] local relativenumber = opt.relativenumber["_value"] if (not number) and (not relativenumber) then opt.number = true opt.relativenumber = false elseif (number) and (not relativenumber) then opt.number = false opt.relativenumber = true elseif (not number) and (relativenumber) then opt.number = true opt.relativenumber = true elseif (number) and (relativenumber) then opt.number = false opt.relativenumber = false end end -- Toggle line number style map('n', 'l', create_function_tabdo('lua toggle_number_style()'), opts) local function set_trouble_keymap(key, cmd) map("n", string.format("x%s", key), string.format("TroubleToggle %s", cmd), opts) end set_trouble_keymap("x", "") set_trouble_keymap("w", "workspace_diagnostics") set_trouble_keymap("d", "document_diagnostics") set_trouble_keymap("l", "loclist") set_trouble_keymap("q", "quickfix") local function set_gitsigns_keymap(key, cmd) map("n", string.format("g%s", key), string.format("Gitsigns %s", cmd), opts) end set_gitsigns_keymap('p', 'preview_hunk') set_gitsigns_keymap('b', 'blame_line') set_gitsigns_keymap('n', 'next_hunk')