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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
-- vim: fdm=marker fdl=0
local g = vim.g
g.mapleader = ' ' -- <leader> key to <space>
g.maplocalleader = '\\'
-- OPTIONS -- {{{
local opt = vim.opt
opt.backspace = 'indent,eol,start'
opt.clipboard:prepend({ 'unnamedplus' })
opt.cmdheight = 1
opt.colorcolumn = '+1'
opt.formatoptions:remove('t')
-- opt.complete = '.,w,b,u'
opt.completeopt = { 'menu', 'menuone', 'noinsert' }
opt.concealcursor = ''
opt.conceallevel = 2
opt.cursorline = true
opt.expandtab = false
opt.exrc = true
opt.fillchars:append({
fold = '─',
horiz = '─',
})
opt.foldenable = true
opt.foldmethod = 'expr'
opt.foldexpr = 'nvim_treesitter#foldexpr()'
-- opt.foldlevel = 0
opt.foldlevelstart = 1
opt.hidden = true
opt.hlsearch = false
opt.ignorecase = true
opt.inccommand = 'split'
opt.incsearch = true
-- 3; https://github.com/neovim/neovim/pull/17266
opt.laststatus = 3
opt.lazyredraw = true
opt.list = true
opt.listchars:append({
trail = '¬',
tab = '> ',
-- space/lead = '⋅',
})
opt.mouse = 'a'
opt.number = true
opt.relativenumber = false
opt.pumheight = 0 -- use available screenspace
opt.redrawtime = 1500
opt.ruler = true
opt.scrolloff = 3
opt.shiftround = true
opt.shortmess:append({ c = true })
opt.breakindent = true
opt.breakindentopt = { shift = 2 }
opt.showbreak = '↪ '
opt.showcmd = false
opt.showmode = true
opt.showmatch = true
opt.signcolumn = 'auto'
opt.smartcase = true
opt.spell = false
opt.spelllang = { 'en_gb' }
-- opt.splitkeep = 'topline'
opt.termguicolors = true
opt.textwidth = 80
opt.timeoutlen = 400
opt.title = true
opt.ttimeoutlen = 10
opt.undolevels = 1000
opt.updatetime = 200
opt.wrap = true
opt.path = { '', '.', '.;$HOME', '/usr/include/**' }
opt.isfname:remove(':')
opt.guicursor = {
-- block shape in normal/visual/command
'n-c-v:block',
-- bar in insert/cmdline-insert/visual-exclusive
'i-ci-ve:ver15',
-- underline in replace/cmdline-replace/operator-pending
'r-cr-o:hor10',
-- 'sm:block-blinkwait175-blinkoff150-blinkon175',
-- 'a:blinkwait700-blinkoff400-blinkon250-Cgrsor/lCursor',
-- 'a:blinkon0-Cursor',
}
-- configure :grep to use ripgrep if it's available
if vim.fn.executable('rg') then
opt.grepprg = 'rg --vimgrep --smart-case --hidden'
opt.grepformat = '%f:%l:%c:%m'
end
-- persistent undo
local undodir = vim.fn.stdpath('cache') .. '/undodir'
if vim.fn.isdirectory(undodir) == 0 then
vim.fn.mkdir(undodir, 'p', '0700')
end
g.undodir = undodir
opt.undofile = true
-- }}}
g.do_filetype_lua = true
-- g.do_legacy_filetype = false
-- g.did_load_filetypes = 0
vim.g.night_and_day = 'night'
require('_globals')
require('plugins')
require('internal.align').setup({ bindings = true })
require('internal.hardmode')
-- DIAGNOSITIC {{{
vim.diagnostic.config({
signs = true,
underline = {
severity = { min = vim.diagnostic.severity.WARN },
},
float = {
severity = { min = vim.diagnostic.severity.INFO },
focusable = false,
source = 'always',
prefix = '',
scope = 'cursor',
},
virtual_text = {
severity = { max = vim.diagnostic.severity.HINT },
source = true,
prefix = '',
},
-- virtual_lines = { prefix = '⬐ ' },
update_in_insert = false,
severity_sort = true,
})
vim.fn.sign_define({
{ name = 'DiagnosticSignError', text = '✗', texthl = 'DiagnosticSignError' },
-- {name='DiagnosticSignWarn', text='⚡', texthl='DiagnosticSignWarn'},
{ name = 'DiagnosticSignWarn', text = '⚐', texthl = 'DiagnosticSignWarn' },
{ name = 'DiagnosticSignInfo', text = 'ℹ', texthl = 'DiagnosticSignInfo' },
{ name = 'DiagnosticSignHint', text = '🞶', texthl = 'DiagnosticSignHint' },
})
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'next diagnostic' })
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'prev diagnostic' })
vim.keymap.set(
'n',
'<localleader>d',
vim.diagnostic.open_float,
{ desc = 'show line diagnositics' }
)
vim.keymap.set('n', '<leader>D', function()
if not _G.diagnostic_hidden then
vim.diagnostic.hide()
else
vim.diagnostic.show()
end
_G.diagnostic_hidden = not _G.diagnostic_hidden
end, { desc = 'toggle diagnositics' })
-- }}}
-- KEY BINDS -- {{{
vim.keymap.set('n', 'Q', [[ :quitall<cr> ]], { silent = true })
vim.keymap.set('n', 'gb', [[ :bnext<cr> ]], { silent = true })
vim.keymap.set('n', 'gB', [[ :bprevious<cr> ]], { silent = true })
vim.keymap.set('n', '<tab>', [[ :normal za<cr> ]], { silent = true })
-- vim.keymap.set('n', '<tab>', [[ :exe 'normal za' | IndentBlanklineRefresh<cr> ]], {silent = true})
-- swap gf and gF
-- vim.keymap.set('n', 'gf', [[ :e <cfile><cr> ]])
-- vim.keymap.set('v', 'gf', [[ :e <cfile><cr> ]])
vim.keymap.set({ 'n', 'v' }, 'gf', function(a)
local Path = require('plenary.path')
local cfile = Path:new(vim.fn.expand('<cfile>'))
if not cfile:is_absolute() then
cfile = Path:new(vim.fn.expand('%:p:h'), cfile):normalize()
end
vim.cmd.edit(cfile)
end, { desc = 'extends `:e <cfile>` with path normalization' })
vim.keymap.set('n', '{', [[ {zz ]])
vim.keymap.set('n', '}', [[ }zz ]])
-- this makes c<anything> jump to the start of the line
-- vim.keymap.set({'n', 'v'}, 'c', '_c')
-- vim.keymap.set({'n', 'v'}, 'C', '_C')
vim.keymap.set('t', '<esc>', [[ <c-\><c-n> ]])
vim.keymap.set('t', '<leader>qq', [[ <c-\><c-n> :bdelete!<cr> ]])
vim.keymap.set('v', 'T', function()
vim.cmd([[retab!]])
vim.api.nvim_input('<esc>')
end)
local misc = require('internal.misc')
vim.keymap.set('n', 'gd', function()
misc.open_under_cursor(nil, true)
end, { desc = 'open under cursor' })
vim.keymap.set('n', 'gx', function()
misc.open_under_cursor('url-launcher')
end, { desc = 'url-launcher' })
vim.keymap.set('n', 'gu', function()
misc.open_under_cursor('url-launcher')
end, { desc = 'url-launcher' })
-- vim.keymap.set('n', '<localleader>gs', function() misc.word_under_cursor(function(s) vim.fn.feedkeys(':%s/' .. s .. '//g'); cmd [[ call feedkeys("\<left>\<left>") ]] end) end)
vim.keymap.set('n', '<leader>r', misc.live_grep, { desc = 'live grep (rg)' })
vim.keymap.set('n', '<leader>f', misc.find_files, { desc = 'find files (fd)' })
vim.keymap.set('n', '<localleader>dgl', 'diffget LOCAL', { desc = 'diff get local' })
vim.keymap.set('n', '<localleader>dgr', 'diffget REMOTE', { desc = 'diff get remote' })
vim.keymap.set('n', '<localleader>dpl', 'diffpush LOCAL', { desc = 'diff push local' })
vim.keymap.set('n', '<localleader>dpr', 'diffpush REMOTE', { desc = 'diff push remote' })
vim.keymap.set(
'x',
'<localleader>f',
[[<ESC><CMD>lua require("internal.misc").fold_block()<CR>]],
{ noremap = true, silent = true, desc = 'fold block' }
)
-- vim.keymap.set('v', '<c-r>', [[y:%s/<c-r>h//gc<left><left><left>]], { noremap = true, silent = true })
vim.keymap.set('n', 'yP', function()
local fnln = (vim.fn.expand('%:p') .. ':' .. vim.fn.line('.'))
vim.fn.setreg('+', fnln)
vim.notify(fnln)
end, { desc = 'yank absolute file path' })
vim.keymap.set('n', 'yT', function()
local fnln = (vim.fn.expand('%:t') .. ':' .. vim.fn.line('.'))
vim.fn.setreg('+', fnln)
vim.notify(fnln)
end, { desc = 'yank file name' })
-- }}}
-- AUTO GROUPS -- {{{
local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
autocmd('TextYankPost', { callback = vim.highlight.on_yank })
do
local group = augroup('ObviousActiveWin', { clear = true })
autocmd('WinEnter', { command = 'set cul', group = group })
autocmd('WinLeave', { command = 'set nocul', group = group })
end
do
local group = augroup('OpenQuickFix', { clear = true })
autocmd('QuickFixCmdPost', {
callback = function()
local qf = vim.fn.getqflist({ qfbufnr = true, size = true })
if (not qf == vim.empty_dict()) and qf and qf.size > 0 then
-- check if the quickfix buffer is already open
for bufnr in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_get_option(bufnr, 'buftype') == 'quickfix' then
return
end
end
vim.cmd.copen()
end
end,
group = group,
})
autocmd('BufEnter', {
pattern = 'qf',
command = [[silent normal! G]],
group = group,
})
end
do
local group = augroup('ManualCommentString', { clear = true })
autocmd('FileType', {
pattern = 'i3config',
callback = function()
vim.opt_local.commentstring = '# %s'
end,
group = group,
})
autocmd('FileType', {
pattern = 'jsonc',
callback = function()
vim.opt_local.commentstring = '// %s'
end,
group = group,
})
end
do
local group = augroup('ManualFolds', { clear = true })
autocmd('VimEnter', {
pattern = 'vim/*',
callback = function()
vim.opt_local.foldenable = true
end,
group = group,
})
autocmd('FileType', {
pattern = 'json,jsonc,yaml,toml',
callback = function()
vim.opt_local.foldenable = false
end,
group = group,
})
end
do
local group = augroup('EasyQuit', { clear = true })
autocmd('FileType', {
pattern = 'help,neorg,dap-float,qf',
callback = function()
vim.keymap.set('n', 'q', '<cmd>close<cr>', { silent = true, buffer = 0 })
end,
group = group,
})
autocmd('FileType', {
pattern = 'alpha',
callback = function()
vim.keymap.set('n', 'q', '<cmd>bdel<cr>', { silent = true, buffer = 0 })
end,
group = group,
})
autocmd('TermClose', {
pattern = 'term://*',
command = [[ if !v:event.status | exe 'bdelete! '..expand('<abuf>') | endif ]],
group = group,
})
end
autocmd({ 'BufRead', 'BufNewFile' }, {
pattern = '/home/robert/bin/*',
callback = function()
vim.opt_local.filetype = 'sh'
end,
group = augroup('DetectBinDir', {}),
})
autocmd({ 'TermOpen' }, {
pattern = 'term://*',
callback = function()
local bufnr = vim.api.nvim_get_current_buf()
vim.opt_local.number = false
vim.opt_local.relativenumber = false
vim.opt_local.signcolumn = 'no'
vim.cmd.split('#0') -- split the previous window
vim.api.nvim_win_set_height(vim.fn.win_findbuf(bufnr)[1], 20)
vim.cmd.startinsert()
end,
group = augroup('CustomizeTermBuffer', {}),
})
-- }}}
-- USER COMMANDS -- {{{
vim.api.nvim_create_user_command('Make', function(opts)
require('internal.job').make(opts.fargs)
end, { nargs = '*', desc = 'run make target' })
vim.api.nvim_create_user_command('Sh', function(opts)
require('internal.job').sh(table.concat(opts.fargs, ' '))
end, { nargs = '*', desc = 'run shell command' })
require('internal.misc').setup({
grep = true,
find = true,
sortline = true,
})
-- }}}
_G.statusline_enable_notifysend = false
require('internal.statusline')
require('internal.job').setup({})
-- TODO: remove eventually
local is_gotmpl = function(bufnr)
for ln = 1, vim.api.nvim_buf_line_count(bufnr), 1 do
local line = vim.api.nvim_buf_get_lines(bufnr, ln - 1, ln, true)
if #line == 0 then
break
end
if line[1]:match('{{.+}}') then
return true
end
end
return false
end
vim.filetype.add({
extension = {
ha = 'hare',
html = function(_, bufnr)
return is_gotmpl(bufnr) and 'gotmpl.html' or 'html'
end,
yaml = function(_, bufnr)
return is_gotmpl(bufnr) and 'gotmpl.yaml' or 'yaml'
end,
},
filename = {
['Caddyfile'] = 'conf',
},
})
|