From: Samir Benmendil Date: Tue, 11 Apr 2023 14:50:05 +0000 (+0100) Subject: nvim: disable LazyVim's keymaps and import some of them X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/8e3c8f1a0a5ba3e52bb62bd8c4820e9ae28b35e7?ds=sidebyside nvim: disable LazyVim's keymaps and import some of them --- diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua index 2c134f7..11d6c1f 100644 --- a/nvim/lua/config/keymaps.lua +++ b/nvim/lua/config/keymaps.lua @@ -1,3 +1,97 @@ -- Keymaps are automatically loaded on the VeryLazy event --- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua --- Add any additional keymaps here + +local Util = require("lazyvim.util") + +local function map(mode, lhs, rhs, opts) + local keys = require("lazy.core.handler").handlers.keys + ---@cast keys LazyKeysHandler + -- do not create the keymap if a lazy keys handler exists + if not keys.active[keys.parse({ lhs, mode = mode }).id] then + opts = opts or {} + opts.silent = opts.silent ~= false + vim.keymap.set(mode, lhs, rhs, opts) + end +end + +-- Resize window using arrow keys +-- TODO: this is cool, but should also support a number +map("n", "", "resize +2", { desc = "Increase window height" }) +map("n", "", "resize -2", { desc = "Decrease window height" }) +map("n", "", "vertical resize -2", { desc = "Decrease window width" }) +map("n", "", "vertical resize +2", { desc = "Increase window width" }) + +-- Move Lines +map("n", "", "m .+1==", { desc = "Move down" }) +map("n", "", "m .-2==", { desc = "Move up" }) +map("i", "", "m .+1==gi", { desc = "Move down" }) +map("i", "", "m .-2==gi", { desc = "Move up" }) +map("v", "", ":m '>+1gv=gv", { desc = "Move down" }) +map("v", "", ":m '<-2gv=gv", { desc = "Move up" }) + +-- buffers +if Util.has("bufferline.nvim") then + map("n", "", "BufferLineCyclePrev", { desc = "Prev buffer" }) + map("n", "", "BufferLineCycleNext", { desc = "Next buffer" }) + map("n", "[b", "BufferLineCyclePrev", { desc = "Prev buffer" }) + map("n", "]b", "BufferLineCycleNext", { desc = "Next buffer" }) +else + map("n", "", "bprevious", { desc = "Prev buffer" }) + map("n", "", "bnext", { desc = "Next buffer" }) + map("n", "[b", "bprevious", { desc = "Prev buffer" }) + map("n", "]b", "bnext", { desc = "Next buffer" }) +end +map("n", "bb", "e #", { desc = "Switch to Other Buffer" }) +map("n", "`", "e #", { desc = "Switch to Other Buffer" }) + +-- Clear search with +map({ "i", "n" }, "", "noh", { desc = "Escape and clear hlsearch" }) + +-- Clear search, diff update and redraw +-- taken from runtime/lua/_editor.lua +map( + "n", + "ur", + "nohlsearchdiffupdatenormal! ", + { desc = "Redraw / clear hlsearch / diff update" } +) + +map({ "n", "x" }, "gw", "*N", { desc = "Search word under cursor" }) + +-- Add undo break-points +map("i", ",", ",u") +map("i", ".", ".u") +map("i", ";", ";u") + +-- better indenting +map("v", "<", "", ">gv") + +-- lazy +map("n", "l", ":Lazy", { desc = "Lazy" }) + +-- new file +map("n", "fn", "enew", { desc = "New File" }) + +if not Util.has("trouble.nvim") then + map("n", "[q", vim.cmd.cprev, { desc = "Previous quickfix" }) + map("n", "]q", vim.cmd.cnext, { desc = "Next quickfix" }) +end + +-- stylua: ignore start + +-- toggle options +map("n", "uf", require("lazyvim.plugins.lsp.format").toggle, { desc = "Toggle format on Save" }) +map("n", "ud", Util.toggle_diagnostics, { desc = "Toggle Diagnostics" }) +local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 +map("n", "uc", function() Util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" }) + +-- highlights under cursor +if vim.fn.has("nvim-0.9.0") == 1 then + map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) +end + +-- floating terminal +-- TODO: I prefer a split buffer for terminal, need to review how to make this more vim-like +map("n", "ft", function() Util.float_term(nil, { cwd = Util.get_root() }) end, { desc = "Terminal (root dir)" }) +map("n", "fT", function() Util.float_term() end, { desc = "Terminal (cwd)" }) +map("t", "", "", {desc = "Enter Normal Mode"}) diff --git a/nvim/lua/plugins/core.lua b/nvim/lua/plugins/core.lua index 5b83b88..d782f4c 100644 --- a/nvim/lua/plugins/core.lua +++ b/nvim/lua/plugins/core.lua @@ -5,6 +5,7 @@ return { defaults = { autocmds = false, options = false, + keymaps = false, }, }, },