summaryrefslogtreecommitdiffstats
path: root/lua/core/auto.lua
blob: 1a20612f88393732bfeebbdf54090fded210374e (plain) (blame)
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
local function auto(event, opts)
  a.nvim_create_autocmd(event, opts)
end

a.nvim_create_augroup('bufcheck', {clear = true})

-- highlight yanks
auto('TextYankPost', {
  group = 'bufcheck',
  pattern = '*',
  callback = function()
    vim.highlight.on_yank{ timeout = 250 }
  end
})

-- start git messages in insert mode
auto('FileType', {
  group = 'bufcheck',
  pattern = { 'gitcommit', 'gitrebase', },
  command = 'startinsert | 1'
})

-- return to last place
auto('BufRead', {
  pattern = '*',
  command = [[call setpos(".", getpos("'\""))]]
})

-- start terminal in insert mode
auto('TermOpen', {
  group    = 'bufcheck',
  pattern  = '*',
  callback = function()
    vim.cmd('startinsert | set winfixheight')
    o.winfixheight = true
    o.cmdheight = 0
  end
})

-- close terminal buffers after shell dies
auto('TermClose', {
  group    = 'bufcheck',
  pattern  = 'term://*',
  callback = function()
    vim.cmd('call nvim_input("<CR>")')
    o.cmdheight = 1
  end
})