Add a bunch of bindings to interact with the vim argument list

This commit is contained in:
Sheldon Lee 2023-04-06 02:22:57 +01:00
parent 4cc7fbe714
commit 864d76ed7d

View File

@ -1,5 +1,48 @@
vim.g.mapleader = " " vim.g.mapleader = " "
-- fzf intergration
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex) vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
vim.keymap.set("n", "<leader>f", vim.cmd.Files) vim.keymap.set("n", "<leader>ff", vim.cmd.Files)
vim.keymap.set("n", "<leader>t", vim.cmd.Tags) vim.keymap.set("n", "<leader>ft", vim.cmd.Tags)
vim.keymap.set("n", "<leader>rg", vim.cmd.Rg) vim.keymap.set("n", "<leader>fr", vim.cmd.Rg)
--
-- Vim argument list bindings
--
-- Generate list of arg action callbacks, which then executes vim.cmd.args()
-- to show argument list aftter performing normal argument action
--
-- pcall() is used to catch errors, but not do anything with them
local arg_actions = {
"argu",
"next",
"prev",
"first",
"last",
}
local arg_action = {}
for _, action in ipairs(arg_actions) do
arg_action[action] = function()
pcall(vim.cmd, action)
vim.cmd.args()
end
end
-- Generate list of callbacks that execute argu n from n = 1 to 4
-- argu_n[n] is a function that executes vim.cmd.argu(n)
local argu_n = {}
for n = 1, 4 do
argu_n[n] = function()
pcall(vim.cmd.argu, {n, bang=true})
vim.cmd.args()
end
end
vim.keymap.set("n", "<leader>a", vim.cmd.args)
vim.keymap.set("n", "<leader>u", arg_action["argu"])
vim.keymap.set("n", "<leader>an", arg_action["next"])
vim.keymap.set("n", "<leader>ap", arg_action["prev"])
vim.keymap.set("n", "<leader>af", arg_action["first"])
vim.keymap.set("n", "<leader>al", arg_action["last"])
vim.keymap.set("n", "<leader>aa", argu_n[1])
vim.keymap.set("n", "<leader>ra", argu_n[1])
vim.keymap.set("n", "<leader>ar", argu_n[2])
vim.keymap.set("n", "<leader>as", argu_n[3])
vim.keymap.set("n", "<leader>at", argu_n[4])