Skip to content

Commit f85def4

Browse files
feat(nvim): append() and remove() for opt.set, and formatoptions fix
1 parent c7a4a64 commit f85def4

File tree

5 files changed

+77
-8
lines changed

5 files changed

+77
-8
lines changed

.config/nvim/lua/opt.lua

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
local opt = require('util.opt')
2+
local t = require('util.table')
23

34
if vim.fn.has('termguicolors') then
4-
opt.set {termguicolors = true}
5+
opt.set {
6+
termguicolors = true,
7+
winblend = 5
8+
}
59
end
610

711
vim.cmd.colors('habamax')
@@ -34,7 +38,9 @@ opt.set {
3438
ignorecase = true,
3539
smartcase = true,
3640

37-
backspace = 'indent,eol,start',
41+
showmatch = true,
42+
43+
backspace = {'indent', 'eol', 'start'},
3844

3945
dir = '/private/tmp',
4046
backup = true,
@@ -46,7 +52,20 @@ opt.set {
4652

4753
wildoptions = {'pum', 'tagfile', 'fuzzy'},
4854
virtualedit = {'block'},
55+
56+
matchpairs = t.append {'<:>'},
57+
shortmess = t.append {'l'},
58+
formatoptions = t.remove {'r', 'o'},
4959
}
5060

51-
vim.opt.formatoptions:remove('r')
52-
vim.opt.formatoptions:remove('o')
61+
local fo_group = vim.api.nvim_create_augroup('formatoptions', {clear = true})
62+
vim.api.nvim_create_autocmd('FileType', {
63+
group = fo_group,
64+
pattern = '*',
65+
desc = 'sets formatoptions because someone, in their infinite wisdom, decided to overwrite them in nearly every default ftplugin',
66+
callback = function ()
67+
opt.setlocal {
68+
formatoptions = t.remove {'r', 'o'},
69+
}
70+
end
71+
})

.config/nvim/lua/remaps.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ vim.keymap.set('n', 'k', 'gk')
99
vim.keymap.set('v', 'k', 'gk')
1010

1111
vim.keymap.set('n', '<leader><Space>', vim.cmd.noh)
12-
vim.keymap.set('n', ';;', 'A;<esc>')
13-
vim.keymap.set('n', ',,', 'A,<esc>')
12+
vim.keymap.set('n', '<leader>;', 'A;<esc>')
13+
vim.keymap.set('n', '<leader>,', 'A,<esc>')
1414
vim.keymap.set('t', '<S-Space>', '<Space>')
1515

1616
vim.keymap.set('n', 'gh', '<NOP>')

.config/nvim/lua/util/opt.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local function table_set(into)
99
end
1010

1111
M.set = table_set(vim.opt)
12+
M.setlocal = table_set(vim.opt_local)
1213
M.let_g = table_set(vim.g)
1314
M.g = table_set(vim.g)
1415

.config/nvim/lua/util/table.lua

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,60 @@ local M = {}
66
--- @return table merged the merged tables
77
function M.merge_table(into, from)
88
for k, v in pairs(from) do
9-
into[k] = v
9+
if type(v) == 'function' then
10+
v(into, from, k)
11+
else
12+
into[k] = v
13+
end
1014
end
1115

1216
return into
1317
end
1418

19+
--- Merges two lua-lists and returns the result (non-mutating)
20+
--- @param a table
21+
--- @param b table
22+
--- @return table merged the merged values
23+
function M.cat(a, b)
24+
return vim.iter({a, b}):flatten(1):totable()
25+
end
26+
27+
--- For use with M.merge_table, this function is a convenient way of calling tbl:append() on objects in vim.opt
28+
function M.append(v)
29+
return function (into, _, k)
30+
local ty = type(v)
31+
32+
if ty == 'table' then
33+
for _, val in ipairs(v) do
34+
into[k]:append(val)
35+
end
36+
elseif ty ~= 'nil' then
37+
into[k]:append(v)
38+
end
39+
end
40+
end
41+
42+
--- For use with M.merge_table, this function is a convenient way of calling tbl:remove() on objects in vim.opt
43+
function M.remove(v)
44+
return function (into, _, k)
45+
local ty = type(v)
46+
47+
if ty == 'table' then
48+
for _, val in ipairs(v) do
49+
into[k]:remove(val)
50+
end
51+
elseif ty ~= 'nil' then
52+
into[k]:remove(v)
53+
end
54+
end
55+
end
56+
57+
--- Similar to M.append and M.remove, this combines the two into (append, remove) so items can be added and removed in one call
58+
function M.append_remove(a, r)
59+
return function (...)
60+
M.append(a)(...)
61+
M.remove(r)(...)
62+
end
63+
end
64+
1565
return M

.zshenv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ typeset -U PATH path
55

66
path=(
77
$HOME/scripts
8-
$HOME/.yarn/bin
98
$HOME/.local/bin
109
$HOME/Library/pnpm
1110
$HOME/go

0 commit comments

Comments
 (0)