~yerinalexey/dotfiles

ref: 3bb7991839c26fe59674184fc6822f7477751f93 dotfiles/vis/visrc.lua -rw-r--r-- 1.3 KiB
3bb79918Alexey Yerin river: decrease wob height 5 months ago
                                                                                
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
-- Standard vis module, providing parts of the Lua API
require('vis')
require('mail_detect')

-- Optional require
pcall(function() require('secret_detect') end)

-- Standard widths
vis.ftdetect.filetypes.markdown.cmd = { "set cc 80" };
vis.ftdetect.filetypes.text.cmd     = { "set cc 80" };
vis.ftdetect.filetypes.ansi_c.cmd   = { "set cc 80" };
vis.ftdetect.filetypes.diff.cmd     = { "set cc 72" };
vis.ftdetect.filetypes.rust.cmd = {
	"set cc 80",
	"set expandtab",
	"set tabwidth 4",
};

vis.events.subscribe(vis.events.INIT, function()
	vis:command('set theme onedark')
end)

vis.events.subscribe(vis.events.WIN_OPEN, function(win)
	-- Line numbers
	vis:command('set nu')
	vis:command('set rnu')

	-- Auto indent
	vis:command('set ai')

	-- Many have problems reading atomically rename()d files
	vis:command('set savemethod inplace')
end)

vis.events.subscribe(vis.events.FILE_SAVE_PRE, function()
	-- Delete trailing whitespace
	-- TODO: disable when it breaks something :)

	local vp = vis.win.viewport

	local sel = vis.win.selection
	local s_line = sel.line
	local s_col = sel.col

	local lines = vis.win.file.lines
	for i=1, #lines do
		local new_line = lines[i]:gsub("^(.-)%s*$", "%1")
		if lines[i] ~= new_line then
			lines[i] = new_line
		end
	end

	sel:to(s_line, s_col)
	vis.win.viewport = vp
end)