-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
legendary-autocmd-tables.txt
89 lines (82 loc) · 2.33 KB
/
legendary-autocmd-tables.txt
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
83
84
85
86
87
88
89
*legendary-autocmd-tables.txt* Last change: 2023 March 10
==============================================================================
AUGROUPS AND AUTOCMDS *legendary-autocmd-tables-augroups-and-autocmds*
`augroup` tables are very simple. They have a `name` property, and a `clear`
property which defaults to `true`. This will clear the `augroup` when creating
it, equivalent to `au!`. `autocmd` tables nested within `augroup` tables will
automatically be defined in the `augroup`.
>lua
local augroups = {
{
name = 'MyAugroupName',
clear = true,
-- you autocmd tables here
},
}
<
`autocmd` tables have an event or list of events, and a handler as the first
two elements, respectively. You can also specify options to be passed to the
`autocmd` via the `opts` property. The `opts` property defaults to `{ pattern
= '*', group = nil }`.
>lua
local autocmds = {
{
'FileType',
':setlocal conceallevel=0',
opts = {
pattern = { 'json', 'jsonc' },
},
},
{
{ 'BufRead', 'BufNewFile' },
':set filetype=jsonc',
opts = {
pattern = { '*.jsonc', 'tsconfig*.json' },
},
},
{
'BufWritePre',
vim.lsp.buf.formatting_sync,
-- include a description to execute it
-- like a command on-demand from the finder
description = 'Format on write with LSP',
},
{
'BufWritePre',
vim.lsp.buf.format_document,
-- or, if you want to include a description
description = 'Format on write with LSP',
-- but still not have it in the finder,
-- set
hide = true,
},
}
<
An example putting both together:
>lua
local augroups = {
{
name = 'LspOnAttachAutocmds',
clear = true,
{
'BufWritePre',
require('lsp.utils').format_document,
},
{
'CursorHold',
vim.diagnostic.open_float,
},
},
{
{ 'BufRead', 'BufNewFile' },
':set filetype=jsonc',
opts = {
-- you can also manually add an autocmd
-- to an existing augroup
group = 'filetypedetect',
pattern = { '*.jsonc', 'tsconfig*.json' },
},
},
}
<
vim:tw=78:ts=8:ft=help:norl: