# HG changeset patch # User Meredith Howard # Date 1680065869 18000 # Node ID 226221dc1d6b6dc05cc44cfa174a546951ed9f6a # Parent 694fb6cd9cc2c43404b2572386413adb85f399e6 Simplify command aliases diff --git a/.config/nvim/lua/config/commands.lua b/.config/nvim/lua/config/commands.lua --- a/.config/nvim/lua/config/commands.lua +++ b/.config/nvim/lua/config/commands.lua @@ -1,7 +1,5 @@ local command = vim.api.nvim_create_user_command -local calias = require("config.util").calias -local cmd = vim.cmd -local fn = vim.fn +local cmd, fn = vim.cmd, vim.fn command("Hgcd", function() local root = fn.systemlist("hg root 2>/dev/null")[1] @@ -31,16 +29,20 @@ command("Grep", function(ctx) cmd.cfirst() end, { nargs = "*", complete = "file" }) -calias("Q", "q") -calias("Qa", "qa") -calias("W", "w") -calias("grep", "Grep") +require("config.util").calias({ + -- replace default: + grep = "Grep", -calias("gcd", "Gcd") -calias("hgcd", "Hgcd") + -- typos: + Q = "q", + Qa = "qa", + W = "w", + gcd = "Gcd", + hgcd = "Hgcd", --- Switch these to default to stay in one window + buffer -calias("doc", "ViewDoc!") -calias("help", "ViewDocHelp!") -calias("man", "ViewDocMan!") -calias("perldoc", "ViewDocPerl!") + -- Make the ! versions default to stay in one window + buffer: + doc = "ViewDoc!", + help = "ViewDocHelp!", + man = "ViewDocMan!", + perldoc = "ViewDocPerl!", +}) diff --git a/.config/nvim/lua/config/util.lua b/.config/nvim/lua/config/util.lua --- a/.config/nvim/lua/config/util.lua +++ b/.config/nvim/lua/config/util.lua @@ -1,18 +1,19 @@ local M = {} -local api = vim.api -local fn = vim.fn +local api, fn = vim.api, vim.fn -function M.calias(abbrev, expand) - vim.cmd.cnoreabbrev( - string.format( - [[ %s (getcmdtype() == ":" && getcmdline() == "%s") ? "%s" : "%s"]], - abbrev, - abbrev, - expand, - abbrev +function M.calias(aliases) + for abbrev, expand in pairs(aliases) do + vim.cmd.cnoreabbrev( + string.format( + [[ %s (getcmdtype() == ":" && getcmdline() == "%s") ? "%s" : "%s"]], + abbrev, + abbrev, + expand, + abbrev + ) ) - ) + end end function M.autocmd(group, event, pattern, opts)