Tue, 14 Mar 2023 22:56:37 -0500
try to fix stopinsert/autowrite again
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
1 | local autocmd = require("config.util").autocmd |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
2 | local cmd = vim.cmd |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
3 | local fn = vim.fn |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
4 | |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
5 | local g = vim.api.nvim_create_augroup("vimrc", { clear = true }) |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
6 | |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
7 | -- >> neovim specific |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
8 | -- Always start terminals in insert/terminal mode |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
9 | autocmd(g, "TermOpen", "*", cmd.startinsert) |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
10 | |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
11 | -- neovim's autoread doesn't do this by default. |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
12 | autocmd(g, "FocusGained", "*", cmd.checktime) |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
13 | |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
14 | -- >> autowriteall improvment |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
15 | -- Stopinsert on leave, or autowriteall doesn't work. |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
16 | autocmd(g, { "WinLeave", "FocusLost" }, "*", function() |
1087
bfcf9813c223
try to fix stopinsert/autowrite again
Meredith Howard <mhoward@roomag.org>
parents:
1086
diff
changeset
|
17 | if fn.pumvisible() == 0 then |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
18 | fn.stopinsert() |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
19 | end |
1087
bfcf9813c223
try to fix stopinsert/autowrite again
Meredith Howard <mhoward@roomag.org>
parents:
1086
diff
changeset
|
20 | cmd.wa() |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
21 | end) |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
22 | |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
23 | -- >> auto mkpath on write |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
24 | autocmd(g, "BufWritePre", "*", { |
1076
15007f695dfb
clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents:
1075
diff
changeset
|
25 | callback = function(ctx) |
15007f695dfb
clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents:
1075
diff
changeset
|
26 | if vim.bo[ctx.buf].buftype == "" and not string.match(ctx.file, "^[%w]+:") then |
15007f695dfb
clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents:
1075
diff
changeset
|
27 | fn.mkdir(fn.fnamemodify(ctx.file, ":p:h"), "p") |
15007f695dfb
clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents:
1075
diff
changeset
|
28 | end |
15007f695dfb
clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents:
1075
diff
changeset
|
29 | end, |
15007f695dfb
clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents:
1075
diff
changeset
|
30 | }) |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
31 | |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
32 | -- >> auto session ? |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
33 | |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
34 | -- >> jump to last position on open |
1086
82f517e1ae76
regexp match "no jump on load" filetypes
Meredith Howard <mhoward@roomag.org>
parents:
1082
diff
changeset
|
35 | local nojump = vim.regex([[mail\|commit\|rebase]]) |
82f517e1ae76
regexp match "no jump on load" filetypes
Meredith Howard <mhoward@roomag.org>
parents:
1082
diff
changeset
|
36 | assert(nojump, "Couldn't compile nojump regexp?") |
82f517e1ae76
regexp match "no jump on load" filetypes
Meredith Howard <mhoward@roomag.org>
parents:
1082
diff
changeset
|
37 | |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
38 | autocmd(g, "BufReadPost", "*", function() |
1086
82f517e1ae76
regexp match "no jump on load" filetypes
Meredith Howard <mhoward@roomag.org>
parents:
1082
diff
changeset
|
39 | if nojump:match_str(vim.bo.filetype or "") then |
82f517e1ae76
regexp match "no jump on load" filetypes
Meredith Howard <mhoward@roomag.org>
parents:
1082
diff
changeset
|
40 | return |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
41 | end |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
42 | |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
43 | local lastpos = fn.line([['"]]) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
44 | if lastpos >= 1 and lastpos <= fn.line("$") then |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
45 | vim.cmd([[normal! g`"]]) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
46 | end |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
47 | end) |
1075
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
48 | |
3b88450bda15
port custom autocmds to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
49 | -- >> simple highlight conflict markers |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
50 | autocmd(g, "BufReadPost", "*", function() |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
51 | fn.matchadd("Error", [[\m^\([<>|]\)\{7} \@=\|^=\{7}$]]) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
1077
diff
changeset
|
52 | end) |