mappings: Allow to remove plugin mappings in chadrc

This enables us to disable a plugin mappings individually

for eg:
  M.mappings.plugins = {
      telelscope = {
          find_hiddenfiles = false
      }
  }

  This will disable the telelscope find_hiddenfiles mapping.

It's also helpful when we want to use the mapping used by find_hiddenfiles for something else
This commit is contained in:
Akianonymus 2022-01-22 12:51:12 +05:30 committed by siduck
parent 4c85f25a09
commit bad06dc44f
2 changed files with 22 additions and 11 deletions

View File

@ -166,7 +166,7 @@ M.mappings = {
} }
-- plugins related mappings -- plugins related mappings
-- To disable a mapping, equate the variable to "" or false or nil in chadrc
M.mappings.plugins = { M.mappings.plugins = {
bufferline = { bufferline = {
next_buffer = "<TAB>", next_buffer = "<TAB>",

View File

@ -1,7 +1,7 @@
local utils = require "core.utils" local utils = require "core.utils"
local config = utils.load_config() local config = utils.load_config()
local map = utils.map local map_wrapper = utils.map
local maps = config.mappings local maps = config.mappings
local plugin_maps = maps.plugins local plugin_maps = maps.plugins
@ -9,41 +9,52 @@ local nvChad_options = config.options.nvChad
local cmd = vim.cmd local cmd = vim.cmd
-- This is a wrapper function made to disable a plugin mapping from chadrc
-- If keys are nil, false or empty string, then the mapping will be not applied
-- Useful when one wants to use that keymap for any other purpose
local map = function(...)
local keys = select(2, ...)
if not keys or keys == "" then
return
end
map_wrapper(...)
end
local M = {} local M = {}
-- these mappings will only be called during initialization -- these mappings will only be called during initialization
M.misc = function() M.misc = function()
local function non_config_mappings() local function non_config_mappings()
-- Don't copy the replaced text after pasting in visual mode -- Don't copy the replaced text after pasting in visual mode
map("v", "p", '"_dP') map_wrapper("v", "p", '"_dP')
-- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down> -- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using :map -- empty mode is same as using :map
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
map("", "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map_wrapper("", "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true })
map("", "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) map_wrapper("", "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true })
map("", "<Down>", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map_wrapper("", "<Down>", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true })
map("", "<Up>", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) map_wrapper("", "<Up>", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true })
-- use ESC to turn off search highlighting -- use ESC to turn off search highlighting
map("n", "<Esc>", ":noh <CR>") map_wrapper("n", "<Esc>", ":noh <CR>")
-- center cursor when moving (goto_definition) -- center cursor when moving (goto_definition)
-- yank from current cursor to end of line -- yank from current cursor to end of line
map("n", "Y", "yg$") map_wrapper("n", "Y", "yg$")
end end
local function optional_mappings() local function optional_mappings()
-- don't yank text on cut ( x ) -- don't yank text on cut ( x )
if not nvChad_options.copy_cut then if not nvChad_options.copy_cut then
map({ "n", "v" }, "x", '"_x') map_wrapper({ "n", "v" }, "x", '"_x')
end end
-- don't yank text on delete ( dd ) -- don't yank text on delete ( dd )
if not nvChad_options.copy_del then if not nvChad_options.copy_del then
map({ "n", "v" }, "d", '"_d') map_wrapper({ "n", "v" }, "d", '"_d')
end end
-- navigation within insert mode -- navigation within insert mode