Use utility module for keymap/abbrev functions

This commit is contained in:
ItsDrike 2021-12-06 22:49:03 +01:00
parent 950d19e1a0
commit 768764a899
No known key found for this signature in database
GPG key ID: FB8CA11A2CF3A843
8 changed files with 110 additions and 116 deletions

View file

@ -0,0 +1,29 @@
local vim = require("vim")
local api = vim.api
local cmd = vim.cmd
local M = {}
-- Define a keymap
function M.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
api.nvim_set_keymap(mode, shortcut, command, opts)
end
-- Define an abbreviation
function M.abbrev(mode, input, result, reabbrev)
-- Assume noreabbrev unless specified otherwise
reabbrev = reabbrev or false
local command
if reabbrev then
command = mode .. "abbrev"
else
command = mode .. "noreabbrev"
end
cmd(command .. " " .. input .. " " .. result)
end
return M