summaryrefslogtreecommitdiff
path: root/fnl/settings/autocmds.fnl
blob: a6461302353eb39393a6de935b8a2fe98cf2ba8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
;; Autocommands for nvim.

(local cursorline (require :util.cursorline))

(local autocmds
       [[:FileType
         {:pattern [:qf :help :man :lspinfo :spectre_panel]
          :command "nnoremap <silent> <buffer> q :close<CR>"}]
        [:TextYankPost
         {:callback (lambda []
                      (vim.highlight.on_yank {:higroup :Visual :timeout 200}))}]
        [:FileType
         {:pattern :lir
          :callback (fn []
                      (tset vim.opt_local :number false)
                      (tset vim.opt_local :relativenumber false))}]
        [:BufWinEnter {:command "setlocal formatoptions-=cro"}]
        [:FileType
         {:pattern :org
          :callback (fn []
                      (tset vim.opt_local :conceallevel 2)
                      (tset vim.opt_local :concealcursor :nc))}]
        [:FileType {:pattern :qf :command "set nobuflisted"}]
        [:FileType {:pattern [:gitcommit :markdown] :command "setlocal wrap"}]
        [:FileType
         {:pattern [:NeogitStatus
                    :NeogitCommitMessage
                    :NeogitNotification
                    :NeogitCommitView
                    :spectre_panel]
          :command "setlocal spell!"}]
        [:TermOpen
         {:pattern ["term://*toggleterm#*"] :command "setlocal spell!"}]
        [:VimResized {:command "tabdo wincmd ="}]
        [[:FocusGained :BufEnter :CursorHold :CursorHoldI]
         {:command :checktime}]
        [:TermOpen
         {:pattern "term://*toggleterm#*"
          :callback (fn []
                      (vim.keymap.set :t :<C-h> "<Cmd>wincmd h<CR>" {})
                      (vim.keymap.set :t :<C-j> "<Cmd>wincmd j<CR>" {})
                      (vim.keymap.set :t :<C-k> "<Cmd>wincmd k<CR>" {})
                      (vim.keymap.set :t :<C-l> "<Cmd>wincmd l<CR>" {}))}]
        [[:InsertLeave :WinEnter] {:callback cursorline.show}]
        [[:InsertEnter :WinLeave] {:callback cursorline.hide}]])

(each [_ autocmd (ipairs autocmds)]
  (match autocmd
    [event opts] (vim.api.nvim_create_autocmd event opts)))