-
Notifications
You must be signed in to change notification settings - Fork 117
/
autocmds.lua
82 lines (68 loc) · 2.18 KB
/
autocmds.lua
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
-----------------------------------------------------------
-- Autocommand functions
-----------------------------------------------------------
-- Define autocommands with Lua APIs
-- See: :h api-autocmd, :h augroup
-- https://neovim.io/doc/user/autocmd.html
local augroup = vim.api.nvim_create_augroup -- Create/get autocommand group
local autocmd = vim.api.nvim_create_autocmd -- Create autocommand
-----------------------------------------------------------
-- General settings
-----------------------------------------------------------
-- Highlight on yank
augroup('YankHighlight', { clear = true })
autocmd('TextYankPost', {
group = 'YankHighlight',
callback = function()
vim.highlight.on_yank({ higroup = 'IncSearch', timeout = '1000' })
end
})
-- Remove whitespace on save
autocmd('BufWritePre', {
pattern = '',
command = ":%s/\\s\\+$//e"
})
-- Don't auto commenting new lines
autocmd('BufEnter', {
pattern = '',
command = 'set fo-=c fo-=r fo-=o'
})
-----------------------------------------------------------
-- Settings for filetypes
-----------------------------------------------------------
-- Disable line length marker
augroup('setLineLength', { clear = true })
autocmd('Filetype', {
group = 'setLineLength',
pattern = { 'text', 'markdown', 'html', 'xhtml', 'javascript', 'typescript' },
command = 'setlocal cc=0'
})
-- Set indentation to 2 spaces
augroup('setIndent', { clear = true })
autocmd('Filetype', {
group = 'setIndent',
pattern = { 'xml', 'html', 'xhtml', 'css', 'scss', 'javascript', 'typescript',
'yaml', 'lua'
},
command = 'setlocal shiftwidth=2 tabstop=2'
})
-----------------------------------------------------------
-- Terminal settings
-----------------------------------------------------------
-- Open a Terminal on the right tab
autocmd('CmdlineEnter', {
command = 'command! Term :botright vsplit term://$SHELL'
})
-- Enter insert mode when switching to terminal
autocmd('TermOpen', {
command = 'setlocal listchars= nonumber norelativenumber nocursorline',
})
autocmd('TermOpen', {
pattern = '',
command = 'startinsert'
})
-- Close terminal buffer on process exit
autocmd('BufLeave', {
pattern = 'term://*',
command = 'stopinsert'
})