dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

remaps.lua (1662B)


      1 local keymap = vim.keymap
      2 local check_duplicates = require("utils.duplicates").check_duplicates
      3 
      4 local X = {}
      5 
      6 local which_key_lazy_registers = nil
      7 local function lazy_register_which_key(input, description)
      8 	if which_key_lazy_registers == nil then
      9 		which_key_lazy_registers = {}
     10 	end
     11 
     12 	which_key_lazy_registers[input] = description
     13 end
     14 
     15 local function try_add_to_which_key_by_input(input, description)
     16 	local present_which_key, which_key = pcall(require, "which-key")
     17 
     18 	local has_leader = string.find(input, "<leader>")
     19 	if has_leader then
     20 		if present_which_key then
     21 			if which_key_lazy_registers ~= nil then
     22 				which_key.register(which_key_lazy_registers)
     23 				which_key_lazy_registers = nil
     24 			end
     25 			which_key.register({
     26 				[input] = description,
     27 			})
     28 		else
     29 			lazy_register_which_key(input, description)
     30 		end
     31 	end
     32 end
     33 
     34 function X.map(type, input, output, description, additional_options)
     35 	local options = { remap = true, desc = description }
     36 	if additional_options then
     37 		options = vim.tbl_deep_extend("force", options, additional_options)
     38 	end
     39 	keymap.set(type, input, output, options)
     40 	check_duplicates(type, input, description)
     41 end
     42 
     43 function X.noremap(type, input, output, description, additional_options)
     44 	local options = { remap = false }
     45 	if additional_options then
     46 		options = vim.tbl_deep_extend("force", options, additional_options)
     47 	end
     48 	X.map(type, input, output, description, options)
     49 end
     50 
     51 function X.map_virtual(input, description)
     52 	check_duplicates(type, input, description)
     53 	try_add_to_which_key_by_input(input, description)
     54 end
     55 
     56 function X.which_key(input, description)
     57 	try_add_to_which_key_by_input(input, description)
     58 end
     59 
     60 return X