mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-06-30 12:30:43 +00:00
Use utility module for keymap/abbrev functions
This commit is contained in:
parent
950d19e1a0
commit
768764a899
8 changed files with 110 additions and 116 deletions
29
home/.config/nvim/lua/utility/mappings.lua
Normal file
29
home/.config/nvim/lua/utility/mappings.lua
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue