.config/nvim/lua/config/autocmds.lua

changeset 1166
34bf03fa07e4
parent 1165
840f0fde07e2
equal deleted inserted replaced
1165:840f0fde07e2 1166:34bf03fa07e4
4 4
5 local g = vim.api.nvim_create_augroup("vimrc", { clear = true }) 5 local g = vim.api.nvim_create_augroup("vimrc", { clear = true })
6 6
7 -- >> neovim specific 7 -- >> neovim specific
8 -- Always start terminals in insert/terminal mode 8 -- Always start terminals in insert/terminal mode
9 autocmd(g, "TermOpen", "*", cmd.startinsert) 9 autocmd(g, "TermOpen", "*", function(_) cmd.startinsert() end)
10 10
11 -- neovim's autoread doesn't do this by default. 11 -- neovim's autoread doesn't do this by default.
12 autocmd(g, "FocusGained", "*", cmd.checktime) 12 autocmd(g, "FocusGained", "*", function(_) cmd.checktime() end)
13 13
14 -- >> autowriteall improvment 14 -- >> autowriteall improvment
15 -- Stopinsert on leave, or autowriteall doesn't work. 15 -- Stopinsert on leave, or autowriteall doesn't work.
16 autocmd(g, { "WinLeave", "FocusLost" }, "*", function() 16 autocmd(g, { "WinLeave", "FocusLost" }, "*", function(_)
17 if fn.pumvisible() == 0 then 17 if fn.pumvisible() == 0 then
18 cmd.stopinsert() 18 cmd.stopinsert()
19 end 19 end
20 pcall(cmd.wa) 20 pcall(cmd.wa)
21 end) 21 end)
31 31
32 -- >> jump to last position on open 32 -- >> jump to last position on open
33 local nojump = vim.regex([[mail\|commit\|rebase]]) 33 local nojump = vim.regex([[mail\|commit\|rebase]])
34 assert(nojump, "Couldn't compile nojump regexp?") 34 assert(nojump, "Couldn't compile nojump regexp?")
35 35
36 autocmd(g, "BufReadPost", "*", function() 36 autocmd(g, "BufReadPost", "*", function(_)
37 if nojump:match_str(vim.bo.filetype or "") then 37 if nojump:match_str(vim.bo.filetype or "") then
38 return 38 return
39 end 39 end
40 40
41 local lastpos = fn.line([['"]]) 41 local lastpos = fn.line([['"]])
43 vim.cmd([[normal! g`"]]) 43 vim.cmd([[normal! g`"]])
44 end 44 end
45 end) 45 end)
46 46
47 -- >> simple highlight conflict markers 47 -- >> simple highlight conflict markers
48 autocmd(g, "BufReadPost", "*", function() 48 autocmd(g, "BufReadPost", "*", function(_)
49 fn.matchadd("Error", [[\m^\([<>|]\)\{7} \@=\|^=\{7}$]]) 49 fn.matchadd("Error", [[\m^\([<>|]\)\{7} \@=\|^=\{7}$]])
50 end) 50 end)

mercurial