vim: use vim.keymap instead of custom functions

`vim.keymap` was introduced in nvim 0.7, so this is the minimum  version
required for this to work.
This commit is contained in:
Fernando Schauenburg 2022-07-01 21:09:27 +02:00
parent 0be2a1b45e
commit 97839fa58b
4 changed files with 13 additions and 24 deletions

View file

@ -1,3 +1,3 @@
local nmap = require 'fs.util'.buf_nmap
nmap { 'q', '<cmd>q<cr>' }
local nmap = require 'fs.util'.nmap
nmap { 'q', '<cmd>q<cr>', { buffer = true } }

View file

@ -1,10 +1,11 @@
vim.bo.tabstop = 2
local nmap = require 'fs.util'.buf_nmap
local nmap = require 'fs.util'.nmap
local buffer = { buffer = true }
-- execute the current line
nmap { '<leader>x', [[<cmd>call luaeval(getline("."))<cr>]] }
nmap { '<leader>x', [[<cmd>call luaeval(getline("."))<cr>]], buffer }
-- save and execute the current file
nmap { '<leader><leader>x', '<cmd>silent write | luafile %<cr>' }
nmap { '<leader><leader>x', '<cmd>silent write | luafile %<cr>', buffer }

View file

@ -1,4 +1,4 @@
local nmap = require'fs.util'.buf_nmap
local nmap = require'fs.util'.nmap
local setup = function()
-- Disable concealling on italic, bold, etc.
@ -13,9 +13,9 @@ local setup = function()
end
local config = function()
nmap { '<leader>+', '<cmd>.,.HeaderIncrease<cr>' }
nmap { '<leader>=', '<cmd>.,.HeaderIncrease<cr>' }
nmap { '<leader>-', '<cmd>.,.HeaderDecrease<cr>' }
nmap { '<leader>+', '<cmd>.,.HeaderIncrease<cr>', { buffer = true } }
nmap { '<leader>=', '<cmd>.,.HeaderIncrease<cr>', { buffer = true } }
nmap { '<leader>-', '<cmd>.,.HeaderDecrease<cr>', { buffer = true } }
end
return { setup = setup, config = config }

View file

@ -1,20 +1,8 @@
local M = {}
local map = function(mode, lhs, rhs, opts)
local opts = vim.tbl_extend('keep', opts or {}, { noremap = true })
vim.api.nvim_set_keymap(mode, lhs, rhs, opts)
end
local buf_map = function(mode, lhs, rhs, opts)
local opts = vim.tbl_extend('keep', opts or {}, { noremap = true })
vim.api.nvim_buf_set_keymap(0, mode, lhs, rhs, opts)
end
M.nmap = function(tbl) map('n', tbl[1], tbl[2], tbl[3]) end
M.imap = function(tbl) map('i', tbl[1], tbl[2], tbl[3]) end
M.vmap = function(tbl) map('v', tbl[1], tbl[2], tbl[3]) end
M.buf_nmap = function(tbl) buf_map('n', tbl[1], tbl[2], tbl[3]) end
M.buf_imap = function(tbl) buf_map('i', tbl[1], tbl[2], tbl[3]) end
M.nmap = function(tbl) vim.keymap.set('n', tbl[1], tbl[2], tbl[3]) end
M.imap = function(tbl) vim.keymap.set('i', tbl[1], tbl[2], tbl[3]) end
M.vmap = function(tbl) vim.keymap.set('v', tbl[1], tbl[2], tbl[3]) end
M.colors = function(gui)
if gui or vim.opt.termguicolors:get() then