-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
169 lines (143 loc) · 5.05 KB
/
init.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
setmetatable(_G, { __index = vim })
local function augroup(name, autocmds)
local group = api.nvim_create_augroup(name, {})
for event, opts in pairs(autocmds) do
opts.group = group
api.nvim_create_autocmd(event, opts)
end
end
-- Load basic configuration
cmd.runtime 'vimrc'
do -- Appearance
opt.statusline = '%2{mode()} | %f %m %r %= %{&spelllang} %y #%{bufnr()} %8(%l,%c%) %8p%%'
cmd.colorscheme 'melange'
augroup('Highlights', { TextYankPost = { callback = function() highlight.on_yank() end } })
-- Set cursor hints according to mode
augroup('Enter', {
InsertEnter = { command = 'set cursorline' },
ModeChanged = { command = 'set cursorcolumn', pattern = '*:[vV\x16]*' },
})
augroup('Leave', {
InsertLeave = { command = 'set nocursorline' },
ModeChanged = { command = 'set nocursorcolumn', pattern = '[vV\x16]*:*' },
})
end
do -- "Focus" mode
local active = false
local function focus_toggle()
active = not active
opt.colorcolumn = active and '' or '100'
opt.conceallevel = active and 2 or 0
opt.foldcolumn = active and '0' or '1'
opt.list = not active
opt.number = not active
end
api.nvim_create_user_command('Focus', focus_toggle, {})
keymap.set('n', '<leader>z', focus_toggle)
end
do -- Spelling
-- NOTE: Use i_CTRL-X_s to correct spelling of previous misspelled word
keymap.set('n', '<leader>l', function()
ui.select({ 'en', 'es', 'de' }, {}, function(lang)
opt.spell = lang ~= nil
opt.spelllang = lang
end)
end)
end
----- Plugins ------------------------------------------------------------------
do -- Paq
keymap.set('n', '<leader>pq', function()
package.loaded.paq = nil
package.loaded.plugins = nil
require('plugins').sync_all()
end)
keymap.set('n', '<leader>pg', function() cmd.edit(fn.stdpath 'config' .. '/lua/plugins.lua') end)
end
do -- Markup
g.disable_rainbow_hover = true
g.latex_to_unicode_file_types = { 'julia', 'typst' }
g.markdown_enable_conceal = true
g.markdown_enable_insert_mode_mappings = false
g.wiki_root = '~/Documents/wiki'
g.wiki_link_creation = {
md = {
url_transform = function(txt) return txt:lower():gsub('%s+', '-') end,
},
}
--- TODO: Refactor
api.nvim_create_user_command('WikiPick', function()
MiniPick.builtin.grep_live(nil, { source = { cwd = g.wiki_root } })
end, {})
end
do -- Tree-sitter
opt.foldmethod = 'expr'
opt.foldexpr = 'nvim_treesitter#foldexpr()'
require('nvim-treesitter.configs').setup {
-- ensure_installed = { 'c', 'html', 'julia', 'lua', 'python', 'query', 'rust', 'typescript', 'markdown', 'markdown_inline' },
highlight = { enable = true },
indent = { enable = true },
incremental_selection = {
enable = true,
keymaps = { init_selection = '+', node_incremental = '+', node_decremental = '_' },
},
textobjects = {
select = {
enable = true,
keymaps = {
['ac'] = '@call.outer',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ak'] = '@conditional.outer',
['at'] = '@class.outer',
},
},
},
}
end
do -- LSP & Diagnostics
local lspconfig = require 'lspconfig'
for _, ls in ipairs {
'clangd',
'rust_analyzer',
'denols',
-- 'svelte',
-- 'tsserver',
} do
lspconfig[ls].setup {}
end
local function on_attach(args)
-- Disable virtual text
diagnostic.config {
float = { focus = false },
virtual_text = false,
}
-- stylua: ignore
for name, fn in pairs {
Diagnostic = diagnostic.show,
LspAction = lsp.buf.code_action,
LspSymbols = lsp.buf.document_symbol,
LspFormat = lsp.buf.format,
LspImpls = lsp.buf.implementation,
LspRefs = lsp.buf.references,
LspRename = lsp.buf.rename,
} do
api.nvim_create_user_command(name, function(_) fn() end, {})
end
keymap.set('n', '[d', diagnostic.goto_prev)
keymap.set('n', ']d', diagnostic.goto_next)
keymap.set('n', 'gd', lsp.buf.definition)
augroup('Lsp', {
BufWritePre = { buffer = args.buf, callback = function(_) lsp.buf.format() end },
CursorHold = { buffer = args.buf, callback = function(_) diagnostic.open_float() end },
})
end
augroup('LspConfig', { LspAttach = { callback = on_attach } })
end
do -- Auto-completion
require('mini.completion').setup()
keymap.set('i', '<Tab>', [[pumvisible() ? "\<C-n>" : "\<Tab>"]], { expr = true })
keymap.set('i', '<S-Tab>', [[pumvisible() ? "\<C-p>" : "\<S-Tab>"]], { expr = true })
end
require('mini.diff').setup()
require('mini.pick').setup()
require('mini.trailspace').setup()