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

Tue, 14 Mar 2023 22:56:37 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Tue, 14 Mar 2023 22:56:37 -0500
changeset 1087
bfcf9813c223
parent 1080
83c9f8460bde
child 1095
226221dc1d6b
permissions
-rw-r--r--

try to fix stopinsert/autowrite again

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
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 local calias = require("config.util").calias
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 local cmd = vim.cmd
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 local fn = vim.fn
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 command("Hgcd", function()
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7 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
8 if vim.v.shell_error == 0 then
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 cmd.cd(root)
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 end
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 end, {})
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 command("Gcd", function()
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 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
15 if vim.v.shell_error == 0 then
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 cmd.cd(root)
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 end
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 end, {})
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19
1079
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
20 command("Grep", function(ctx)
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
21 local pattern = ctx.fargs[1] or fn.expand("<cword>")
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
22 local grepcmd = table.concat({
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
23 vim.o.grepprg,
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
24 fn.shellescape(pattern),
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
25 table.concat(vim.list_slice(ctx.fargs, 2, #ctx.fargs), " "),
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
26 }, " ")
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
27
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
28 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
29 fn.setreg("/", [[\v]] .. pattern)
1079
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
30 cmd.copen()
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
31 cmd.cfirst()
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
32 end, { nargs = "*", complete = "file" })
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
33
1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
34 calias("Q", "q")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35 calias("Qa", "qa")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36 calias("W", "w")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 calias("grep", "Grep")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
38
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
39 calias("gcd", "Gcd")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
40 calias("hgcd", "Hgcd")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 -- Switch these to default to stay in one window + buffer
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 calias("doc", "ViewDoc!")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 calias("help", "ViewDocHelp!")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
45 calias("man", "ViewDocMan!")
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
46 calias("perldoc", "ViewDocPerl!")

mercurial