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
|
## vis-filetype-settings (move-events branch)
This plugin provides a declarative interface for setting vis
options depending on filetype.
It expects an attribute called `settings` to be defined:
```lua
ftset.settings = {
markdown = {"set expandtab on", "set tabwidth 4"}
}
```
In this variable, filetypes are mapped to sets of settings that
toare be executed when a window containing the specified filetype
opis ened.
If you want to do more than setting simple options, you can
specify a function instead:
```lua
ftset.settings = {
bash = function(win)
-- do things for shell scripts
end
}
```
### More events
By default, all settings are run on the WIN_OPEN event, but if
wayou nt, you can specify your own event.
For more information about these events, check out the [documentation
for the Lua API][doc]. Below is a description of which events are
supported by this plugin.
[doc]: http://martanne.github.io/vis/doc/index.html#events
#### File events
- FILE_OPEN
- FILE_CLOSE
- FILE_SAVE_POST
- FILE_SAVE_PRE
```lua
ftset.settings = {
go = {"set et off", "set tw 8", FILE_SAVE_PRE = "gofmt"}
}
```
This will execute the vis command `gofmt` when Go files are saved.
**WARNING: The command will run in the current window, regardless
of whether it contains a Go file**.
### Window events
- WIN_CLOSE
- WIN_HIGHLIGHT
- WIN_OPEN
- WIN_STATUS
WIN_OPEN is the default event.
### Other events
- INPUT
**WARNING: If you run a vis command on INPUT, vis will automatically
return to normal mode.** There is currently no workaround, as far
as I am aware.
### Installation
As a suggestion, copy `vis-filetype-settings.lua` into
`~/.config/vis/plugins/` and add the following to your `visrc.lua`:
```lua
ftset = require("plugins/vis-filetype-settings")
ftset.settings = {
filetype = settings
}
```
|