local vim = require("vim") -- Make these function definitions global as they could be reused -- in plugin specific scripts or in other places. function keymap(mode, shortcut, command, options) -- Assume silent, noremap unless specified otherwise local opts = {noremap=true, silent=true} if options then opts = vim.tbl_extend("force", opts, options) end -- Perform the actual remap vim.api.nvim_set_keymap(mode, shortcut, command, opts) end -- This is a bit silly, but I don't like passing the mode argument -- to every keymap definition and this makes things a lot easier -- and a bit more vimscript-like function nmap(shortcut, command, options) keymap("n", shortcut, command, options) end function imap(shortcut, command, options) keymap("i", shortcut, command, options) end function vmap(shortcut, command, options) keymap("v", shortcut, command, options) end function tmap(shortcut, command, options) keymap("t", shortcut, command, options) end -- Unmap arrow keys in normal mode to remove bad habits nmap("", "") nmap("", "") nmap("", "") nmap("", "") -- Tab navigation nmap("", "gt") nmap("", "gT") nmap("", ":tabnew") nmap("", ":tabmove +") nmap("", ":tabmove -") nmap("", ":tabp") nmap("", ":tabn") -- Set splits navigation to just ALT + hjkl nmap("", "h") nmap("", "j") nmap("", "k") nmap("", "l") -- Split size adjusting nmap("", ":verical resize +3") nmap("", ":vertical resize -3") nmap("", ":resize +3") nmap("", ":resize -3") -- Define some common shortcuts nmap("", ":w") nmap("", ":undo") nmap("", ":redo") -- Terminal nmap("", ":split term://zsh:resize -7i") nmap("", ":vnew term://zshi") nmap("", ":tabnew term://zshi") tmap("", "") -- Use space for folding/unfolding sections nmap("", "za") vmap("", "zf") -- Use shift to quickly move 10 lines up/down nmap("K", "10k") nmap("J", "10j") -- Enable/Disable auto commenting nmap("c", ":setlocal formatoptions-=cro") nmap("C", ":setlocal formatoptions+=cro") -- Don't leave visual mode after indenting vmap("<", "", ">gv") -- System clipboard copying vmap("", '"+y') -- Alias replace all nmap("", ":%s//gI", {silent=false}) -- Stop search highlight with Esc nmap("", ":noh") -- Start spell-check nmap("s", ":setlocal spell! spelllang=en_us") -- Run shell check nmap("p", ":!shellckeck %") -- Compile opened file (using custom script) nmap("", ":w | !comp %") -- Close all opened buffers nmap("Q", ":bufdo bdelete") -- Don't set the incredibely annoying mappings that trigger dynamic SQL -- completion with dbext and keeps on freezing vim whenever pressed with -- a message saying that dbext plugin isn't installed -- See :h ft-sql.txt vim.g.omni_sql_no_default_maps = 1