From 864d76ed7df72cd47d6945f74186d16012bc6ad2 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Thu, 6 Apr 2023 02:22:57 +0100 Subject: [PATCH] Add a bunch of bindings to interact with the vim argument list --- .config/nvim/lua/sheldonmlee/remap.lua | 49 ++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/.config/nvim/lua/sheldonmlee/remap.lua b/.config/nvim/lua/sheldonmlee/remap.lua index 29a4d2d..65dde2b 100644 --- a/.config/nvim/lua/sheldonmlee/remap.lua +++ b/.config/nvim/lua/sheldonmlee/remap.lua @@ -1,5 +1,48 @@ vim.g.mapleader = " " +-- fzf intergration vim.keymap.set("n", "pv", vim.cmd.Ex) -vim.keymap.set("n", "f", vim.cmd.Files) -vim.keymap.set("n", "t", vim.cmd.Tags) -vim.keymap.set("n", "rg", vim.cmd.Rg) +vim.keymap.set("n", "ff", vim.cmd.Files) +vim.keymap.set("n", "ft", vim.cmd.Tags) +vim.keymap.set("n", "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", "a", vim.cmd.args) +vim.keymap.set("n", "u", arg_action["argu"]) +vim.keymap.set("n", "an", arg_action["next"]) +vim.keymap.set("n", "ap", arg_action["prev"]) +vim.keymap.set("n", "af", arg_action["first"]) +vim.keymap.set("n", "al", arg_action["last"]) +vim.keymap.set("n", "aa", argu_n[1]) +vim.keymap.set("n", "ra", argu_n[1]) +vim.keymap.set("n", "ar", argu_n[2]) +vim.keymap.set("n", "as", argu_n[3]) +vim.keymap.set("n", "at", argu_n[4])