--- Personal lua config files for NeoVim. -- Last Changed: 2019-01-27 -- Author: Federico Igne -- License: This file is placed in the public domain. local api = vim.api --- A collection of helper functions to manipulate mappings local m = { nore = { }, b = { nore = { } }, un = { b = { } } } local function map(bufnr, mode, keys, repl, opts) local opts = opts or { } if bufnr then api.nvim_buf_set_keymap(bufnr, mode, keys, repl, opts) else api.nvim_set_keymap(mode, keys, repl, opts) end end local function unmap(bufnr, mode, keys) if bufnr then api.nvim_buf_del_keymap(bufnr, mode, keys) else api.nvim_del_keymap(mode, keys) end end local function noremap(bufnr, mode, keys, repl, opts) local opts = opts or { } opts.noremap = true map(bufnr, mode, keys, repl, opts) end for _, mode in pairs({'n', 'i', 'v', 'x', 't'}) do m[mode] = function(keys, repl, opts) map(nil, mode, keys, repl, opts) end m.nore[mode] = function(keys, repl, opts) noremap(nil, mode, keys, repl, opts) end m.b[mode] = function(bufnr, keys, repl, opts) map(bufnr, mode, keys, repl, opts) end m.b.nore[mode] = function(bufnr, keys, repl, opts) noremap(bufnr, mode, keys, repl, opts) end m.un[mode] = function(keys) unmap(nil, mode, keys) end m.un.b[mode] = function(bufnr, keys) unmap(bufnr, mode, keys) end end return m