.config/nvim/lua/config/commands.lua

Tue, 30 Apr 2024 21:53:24 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Tue, 30 Apr 2024 21:53:24 -0500
changeset 1152
59d9ca2ec2fd
parent 1095
226221dc1d6b
child 1155
fcec334dfe7a
permissions
-rw-r--r--

Match LSP maps to neovim 0.10 defs

1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 local command = vim.api.nvim_create_user_command
1095
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
2 local cmd, fn = vim.cmd, vim.fn
1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 command("Hgcd", function()
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 local root = fn.systemlist("hg root 2>/dev/null")[1]
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 if vim.v.shell_error == 0 then
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7 cmd.cd(root)
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 end
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 end, {})
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 command("Gcd", function()
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 local root = fn.systemlist("git rev-parse --show-toplevel 2>/dev/null")[1]
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 if vim.v.shell_error == 0 then
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 cmd.cd(root)
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 end
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 end, {})
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17
1079
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
18 command("Grep", function(ctx)
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
19 local pattern = ctx.fargs[1] or fn.expand("<cword>")
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
20 local grepcmd = table.concat({
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
21 vim.o.grepprg,
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
22 fn.shellescape(pattern),
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
23 table.concat(vim.list_slice(ctx.fargs, 2, #ctx.fargs), " "),
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
24 }, " ")
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
25
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
26 fn.setqflist({}, " ", { title = grepcmd, lines = fn.systemlist(grepcmd) })
1080
83c9f8460bde continue to confuse the verymagic options
Meredith Howard <mhoward@roomag.org>
parents: 1079
diff changeset
27 fn.setreg("/", [[\v]] .. pattern)
1079
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
28 cmd.copen()
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
29 cmd.cfirst()
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
30 end, { nargs = "*", complete = "file" })
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
31
1095
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
32 require("config.util").calias({
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
33 -- replace default:
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
34 grep = "Grep",
1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35
1095
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
36 -- typos:
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
37 Q = "q",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
38 Qa = "qa",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
39 W = "w",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
40 gcd = "Gcd",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
41 hgcd = "Hgcd",
1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42
1095
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
43 -- Make the ! versions default to stay in one window + buffer:
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
44 doc = "ViewDoc!",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
45 help = "ViewDocHelp!",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
46 man = "ViewDocMan!",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
47 perldoc = "ViewDocPerl!",
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
48 })

mercurial