-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
451 lines (383 loc) · 18.4 KB
/
init.lua
File metadata and controls
451 lines (383 loc) · 18.4 KB
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
-- [[ START OF kickstart.nvim SECTION ]]
-- Based on https://github.com/nvim-lua/kickstart.nvim
-- Set <space> as the leader key
-- See `:help mapleader`
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Set to true if you have a Nerd Font installed and selected in the terminal
vim.g.have_nerd_font = true
-- [[ Setting options ]]
-- See `:help vim.o`
-- NOTE: You can change these options as you wish!
-- For more options, you can see `:help option-list`
-- Make line numbers default
vim.o.number = false
-- You can also add relative line numbers, to help with jumping.
-- Experiment for yourself to see if you like it!
-- vim.o.relativenumber = true
-- Enable mouse mode, can be useful for resizing splits for example!
vim.o.mouse = 'a'
-- Don't show the mode, since it's already in the status line
vim.o.showmode = false
-- Sync clipboard between OS and Neovim.
-- Schedule the setting after `UiEnter` because it can increase startup-time.
-- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
vim.schedule(function()
vim.o.clipboard = 'unnamedplus'
end)
-- Enable break indent
vim.o.breakindent = true
-- Save undo history
vim.o.undofile = true
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
vim.o.ignorecase = true
vim.o.smartcase = true
-- Keep signcolumn on by default
vim.o.signcolumn = 'yes'
-- Decrease update time
vim.o.updatetime = 250
-- Configure how new splits should be opened
-- false+false let's your eyes stay focused on the cursor when splitting
vim.o.splitright = false
vim.o.splitbelow = false
-- Sets how neovim will display certain whitespace characters in the editor.
-- See `:help 'list'`
-- and `:help 'listchars'`
--
-- Notice listchars is set using `vim.opt` instead of `vim.o`.
-- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables.
-- See `:help lua-options`
-- and `:help lua-options-guide`
vim.o.list = false -- Enabling this can interfere with xterm copy-pasting.
vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }
-- Preview substitutions live, as you type!
vim.o.inccommand = 'split'
-- Show which line your cursor is on
vim.o.cursorline = true
-- Minimal number of screen lines to keep above and below the cursor.
vim.o.scrolloff = 6
-- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`),
-- instead raise a dialog asking if you wish to save the current file(s)
-- See `:help 'confirm'`
vim.o.confirm = true
-- [[ Basic Keymaps ]]
-- See `:help vim.keymap.set()`
-- Clear highlights on search when pressing <Esc> in normal mode
-- See `:help hlsearch`
vim.keymap.set('n', '<Esc>', function()
vim.cmd([[nohlsearch]])
if package.loaded['config-lsp.nes'] then
require('copilot-lsp.nes').clear()
end
end, { desc = "Clear highglights and suggestions" })
-- Diagnostic keymaps
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
vim.keymap.set('n', ']e', function () vim.diagnostic.goto_next({severity = 'error'}) end, { desc = 'Go to next diagnostic [E]rror message' })
vim.keymap.set('n', '[e', function () vim.diagnostic.goto_prev({severity = 'error'}) end, { desc = 'Go to previous diagnostic [E]rror message' })
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setqflist, { desc = 'Open diagnostic [Q]uickfix list' })
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
-- is not what someone will guess without a bit more experience.
--
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
-- or just use <C-\><C-n> to exit terminal mode
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
-- TIP: Disable arrow keys in normal mode
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
-- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
-- vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
-- vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
-- Keybinds to make split navigation easier.
-- Use CTRL+<hjkl> to switch between windows
--
-- See `:help wincmd` for a list of all window commands
vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
-- The above mappings may be overridden by vim-tmux-navigator, if enabled.
-- NOTE: Some terminals have colliding keymaps or are not able to send distinct keycodes
-- vim.keymap.set("n", "<C-S-h>", "<C-w>H", { desc = "Move window to the left" })
-- vim.keymap.set("n", "<C-S-l>", "<C-w>L", { desc = "Move window to the right" })
-- vim.keymap.set("n", "<C-S-j>", "<C-w>J", { desc = "Move window to the lower" })
-- vim.keymap.set("n", "<C-S-k>", "<C-w>K", { desc = "Move window to the upper" })
-- [[ Basic Autocommands ]]
-- See `:help lua-guide-autocommands`
-- Highlight when yanking (copying) text
-- Try it with `yap` in normal mode
-- See `:help vim.highlight.on_yank()`
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})
-- [[ END OF kickstart.nvim SECTION ]]
if vim.uv.fs_stat(vim.env.HOME .. '/.pyenv/versions/neovim/bin/python') then
vim.g.python3_host_prog = vim.env.HOME .. '/.pyenv/versions/neovim/bin/python'
-- Also set the PATH environment so tools will use this python3 version (Mason, for example, doesn't use `vim.g.python3_host_prog` anymore)
vim.env.PATH = vim.env.HOME .. '/.pyenv/versions/neovim/bin:' .. vim.env.PATH
end
-- Sane defaults
vim.o.expandtab = true
vim.o.shiftwidth = 4
vim.o.tabstop = 8
vim.o.softtabstop = -1 -- negative values use shiftwidth value
-- Initial folding state. Quickly toggle with `zi`
vim.o.foldenable = false
-- Speed up
vim.o.lazyredraw = true
-- Reuse windows
if false then
-- I don't use tabs, but this could be useful
vim.opt.switchbuf = { 'usetab', 'uselast' }
else
vim.opt.switchbuf = { 'useopen', 'uselast' }
end
-- I don't like to lose sight of modified buffers...
vim.o.hidden = false
-- For vim old-timers, disable autoread
vim.o.autoread = false
-- Workaround file change detection on resume (https://github.com/neovim/neovim/issues/2127)
vim.cmd([[autocmd BufEnter,VimResume * checktime]])
-- Always break hard links!!
vim.opt.backupcopy = { 'auto', 'breakhardlink' }
-- Quickfix keymaps
vim.keymap.set('n', '[q', ':cprev<CR>zv', { noremap = true, silent = true, desc = 'Go to previous [Q]uickfix position' })
vim.keymap.set('n', ']q', ':cnext<CR>zv', { noremap = true, silent = true, desc = 'Go to next [Q]uickfix position' })
vim.keymap.set('n', '<f4>', ':cnext<CR>zv', { noremap = true, silent = true, desc = 'Go to next [Q]uickfix position' })
function ToggleBoolOpt(option)
vim.o[option] = not vim.o[option]
vim.notify('Toggle ' .. option .. ': ' .. vim.inspect(vim.o[option]))
end
function ToggleSubOpt(option, subopt)
if string.find(vim.o[option], subopt) then
vim.opt[option]:remove(subopt)
else
vim.opt[option]:append(subopt)
end
vim.notify('Toggle ' .. option .. ' ' .. subopt .. ': ' .. vim.o[option])
end
vim.keymap.set('n', '<leader>tp', function () ToggleBoolOpt('paste') end, { desc = '[T]oggle [P]aste mode' })
vim.keymap.set('n', '<leader>t=', function () ToggleBoolOpt('spell') end, { desc = '[T]oggle spell mode' })
vim.keymap.set('n', '<leader>tw', function () ToggleBoolOpt('wrap') end, { desc = '[T]oggle [W]rap mode' })
vim.keymap.set('n', '<leader>tR', function () ToggleBoolOpt('autoread') end, { desc = '[T]oggle auto[R]ead mode' })
vim.keymap.set('n', '<leader>tW', function () ToggleBoolOpt('autowrite') end, { desc = '[T]oggle auto[W]rite mode' })
vim.keymap.set('n', '<leader>tL', function () ToggleBoolOpt('list') end, { desc = '[T]oggle [L]ist chars mode' })
-- Toggle 'signcolumn' mode using `<leader>ts...`
function ToggleSignColumn(width)
local win_id = vim.api.nvim_get_current_win()
if width then
if width == 0 then
if vim.wo.signcolumn ~= 'no' then
vim.api.nvim_win_set_var(win_id, "saved_signcolumn", vim.wo.signcolumn)
vim.wo.signcolumn = 'no'
end
elseif width == 1 then
vim.wo.signcolumn = 'yes'
else
vim.wo.signcolumn = 'yes:' .. tostring(width)
end
else
if vim.wo.signcolumn == 'no' then
local ok, saved_signcolumn = pcall(vim.api.nvim_win_get_var, win_id, "saved_signcolumn")
vim.wo.signcolumn = (ok and saved_signcolumn) or 'yes'
else
vim.api.nvim_win_set_var(win_id, "saved_signcolumn", vim.wo.signcolumn)
vim.wo.signcolumn = 'no'
end
end
vim.notify('Toggle signcolumn: ' .. vim.inspect(vim.wo.signcolumn))
end
vim.keymap.set('n', '<leader>ts<cr>', ToggleSignColumn, { desc = '[T]oggle [S]ign column' })
vim.keymap.set('n', '<leader>ts0', function () ToggleSignColumn(0) end, { desc = '[T]oggle [S]ign column: [0] wide (no/off)' })
vim.keymap.set('n', '<leader>ts1', function () ToggleSignColumn(1) end, { desc = '[T]oggle [S]ign column: [1] wide' })
vim.keymap.set('n', '<leader>ts2', function () ToggleSignColumn(2) end, { desc = '[T]oggle [S]ign column: [2] wide' })
vim.keymap.set('n', '<leader>ts3', function () ToggleSignColumn(3) end, { desc = '[T]oggle [S]ign column: [3] wide' })
vim.keymap.set('n', '<leader>tsn', function () ToggleBoolOpt('number') end, { desc = '[T]oggle [S]ign column line [N]umber' })
-- Toggle 'virtualedit' mode using `<leader>tv`
function ToggleVirtualEdit()
local win_id = vim.api.nvim_get_current_win()
local cur_virtualedit = vim.wo.virtualedit
if cur_virtualedit == "" then
-- "" uses global value
cur_virtualedit = vim.o.virtualedit
end
if not cur_virtualedit or cur_virtualedit == "" then
-- nil or "" at global level is the same as "none"
cur_virtualedit = "none"
end
if cur_virtualedit == 'none' then
local ok, saved_virtualedit = pcall(vim.api.nvim_win_get_var, win_id, "saved_virtualedit")
vim.wo.virtualedit = (ok and saved_virtualedit) or 'all'
else
vim.api.nvim_win_set_var(win_id, "saved_virtualedit", cur_virtualedit)
vim.wo.virtualedit = 'none'
end
vim.notify('Toggle virtualedit: ' .. vim.inspect(vim.wo.virtualedit))
end
vim.keymap.set('n', '<leader>tv', ToggleVirtualEdit, { desc = '[T]oggle [V]irtual edit' })
-- Toggle diff-related options using `<leader>td...`
local function ToggleDiffMode()
if vim.o.diff then
vim.cmd([[ diffoff ]])
else
vim.cmd([[ diffthis ]])
end
vim.notify('Toggle diff: ' .. vim.inspect(vim.o.diff))
end
vim.keymap.set('n', '<leader>td<cr>', ToggleDiffMode, { desc = '[T]oggle [D]iff mode' })
vim.keymap.set('n', '<leader>tdb', function () ToggleSubOpt('diffopt', 'iblank') end, { desc = '[T]oggle [D]iff ignore [B]lank lines' })
vim.keymap.set('n', '<leader>tdc', function () ToggleSubOpt('diffopt', 'icase') end, { desc = '[T]oggle [D]iff ignore [C]ase of text' })
vim.keymap.set('n', '<leader>tdw', function () ToggleSubOpt('diffopt', 'iwhite') end, { desc = '[T]oggle [D]iff ignore [W]hite spaces' })
-- Toggle diagnostics
local default_diagnostic_opts = {
underline = true, -- Neovim default is true
virtual_text = true, -- Neovim default is false
virtual_lines = false, -- Neovim default is false
signs = true, -- Neovim default is true
update_in_insert = false, -- Neovim default is false
severity_sort = true, -- Neovim default is false. {reverse = true} is also supported
}
vim.diagnostic.config(default_diagnostic_opts)
local function ToggleDiagnosticOpt(opt)
local new_value = not vim.diagnostic.config()[opt]
vim.diagnostic.config({ [opt] = new_value })
vim.notify('Toggle diagnostic ' .. opt .. ': ' .. vim.inspect(new_value))
end
local function DefaultDiagnosticOpts()
vim.diagnostic.config(default_diagnostic_opts)
vim.notify('Defaulted diagnostic opts')
end
local function ToggleDiagnostics()
local new_value = not vim.diagnostic.is_enabled()
vim.diagnostic.enable(new_value)
vim.notify('Toggle diagnostics: ' .. vim.inspect(new_value))
end
vim.keymap.set('n', '<leader>tlu', function() ToggleDiagnosticOpt('underline') end, { desc = '[T]oggle [L]SP diagnostics [U]nderline' })
vim.keymap.set('n', '<leader>tls', function() ToggleDiagnosticOpt('signs') end, { desc = '[T]oggle [L]SP diagnostics [S]igns' })
vim.keymap.set('n', '<leader>tsl', function() ToggleDiagnosticOpt('signs') end, { desc = '[T]oggle [S]ign column [L]SP diagnostics' })
vim.keymap.set('n', '<leader>tlv', function() ToggleDiagnosticOpt('virtual_text') end, { desc = '[T]oggle [L]SP diagnostics [V]irtual text' })
vim.keymap.set('n', '<leader>tlV', function() ToggleDiagnosticOpt('virtual_lines') end, { desc = '[T]oggle [L]SP diagnostics [V]irtual lines' })
vim.keymap.set('n', '<leader>tlp', function() ToggleDiagnosticOpt('update_in_insert') end, { desc = '[T]oggle [L]SP diagnostics information u[P]date while in insert mode' })
vim.keymap.set('n', '<leader>tld<cr>', function() ToggleDiagnostics() end, { desc = '[T]oggle all [L]SP diagnostics' })
vim.keymap.set('n', '<leader>tldd', function() DefaultDiagnosticOpts() end, { desc = '[T]oggle all [L]SP diagnostics back to [D]efaults (on, except overrides passed on init)' })
vim.keymap.set('n', '<leader>tldo', function() vim.diagnostic.enable(true) end, { desc = '[T]oggle all [L]SP [D]iagnostics [O]n' })
vim.keymap.set('n', '<leader>tldf', function() vim.diagnostic.enable(false) end, { desc = '[T]oggle all [L]SP [D]iagnostics o[F]f' })
-- Toggle 'laststatus'
local function ToggleLaststatus()
local meanings = {
[0] = "never",
[1] = "only when more than one window",
[2] = "always",
[3] = "global statusline",
}
local current_value = vim.o.laststatus
local new_value
if false then
-- Cycle among all values
new_value = (current_value + 1) % 4
else
-- Cycle between 2 (default) and 3
if current_value == 3 then
new_value = 2
else
new_value = 3
end
end
vim.o.laststatus = new_value
local meaning = meanings[new_value]
vim.notify('Set laststatus to: ' .. vim.inspect(new_value)
.. (meaning and (' (' .. meaning .. ')') or ''))
end
vim.keymap.set('n', '<leader>t_', ToggleLaststatus, { desc = '[T]oggle \'laststatus\' [_] option' })
-- Toggle 'conceallevel'
local function ToggleConceallevel()
local meanings = {
[0] = "text is shown normally",
[1] = "each block of concealed text is replaced with one character",
[2] = "concealed text is completely hidden unless it has a custom replacement character",
[3] = "concealed text is completely hidden",
}
local current_value = vim.o.conceallevel
local new_value
if false then
-- Cycle among all values
new_value = (current_value + 1) % 4
else
-- Cycle between 0 (default) and 3
if current_value == 3 then
new_value = 0
else
new_value = 3
end
end
vim.o.conceallevel = new_value
local meaning = meanings[new_value]
vim.notify('Set conceallevel to: ' .. vim.inspect(new_value)
.. (meaning and (' (' .. meaning .. ')') or ''))
end
vim.keymap.set('n', '<leader>tc', ToggleConceallevel, { desc = '[T]oggle [C]onceal level' })
vim.opt.diffopt:append('closeoff')
vim.opt.diffopt:append('hiddenoff')
vim.opt.diffopt:append('indent-heuristic')
vim.opt.diffopt:append('linematch:60')
-- Visual searching
vim.o.incsearch = true
-- Start horizontal scrolling before context runs out
vim.o.sidescrolloff = 5
-- Wrapped lines makes it hard to read, but breakindent makes this good again
vim.o.wrap = vim.o.breakindent
vim.go.laststatus = 3 -- global statusline to allow Avante windows to collapse seamlessly
vim.go.laststatus = 2 -- I prefer the statusline to always be visible
-- Tip #709 - If you create lots of shell scripts, this will make them executable
if vim.fn.has('unix') == 1 then
vim.cmd([[
au BufWritePost * if
\ expand('%:e') != 'in' &&
\ getline(1) =~# '^#!\(/[[:alnum:]._-]\+\)*/bin/[[:alnum:]._-]\+\>' &&
\ ! executable(expand('%:p'))
\ | exec 'silent !chmod u+x <afile>' | endif
]])
end
-- Use full wildmenu functionality but only complete to longest common string
vim.opt.wildmode = { 'longest:full' }
-- NOTE: Enable this to silence *temporarily* deprecated commands warning
-- vim.deprecate = function() end
-- [[ Load local config overrides before LSPs and plugins ]]
require('config.local')
-- [[ Make plugin choices ]]
vim.g.cmp_plugin = vim.fn.has('nvim-0.10.0') == 1 and 'blink.cmp' or 'nvim-cmp' -- 'blink.cmp', 'nvim-cmp'
vim.g.picker_plugin = vim.fn.has('nvim-0.9.4') == 1 and 'snacks.picker' or 'telescope' -- 'snacks.picker', 'telescope', 'fzf-lua'
-- [[ Add a neovim-specific bin directory to PATH ]]
-- `nvim-bin/` allows wrapper scripts or extra tools to override system tools when needed.
vim.env.PATH = vim.fn.stdpath('config') .. '/nvim-bin:' .. vim.env.PATH
-- [[ Configure and install plugins ]]
require('config.lazy')
-- vim.cmd 'colorscheme onedarker' -- From LazyVim/Colorschemes
vim.cmd 'colorscheme catppuccin' -- catppuccin-latte, catppuccin-frappe, catppuccin-macchiato, catppuccin-mocha
-- vim.cmd 'colorscheme tokyonight-night' -- tokyonight (=> tokyonight-moon), tokyonight-night, tokyonight-storm, tokyonight-day (light)
-- Colorscheme fixups?
if vim.g.colors_name == 'onedarker' then
-- onedarker doesn't set NonText so stuff like gitsigns's blame virtual text doesn't show
local c = require('onedarker.palette')
vim.api.nvim_set_hl(0, 'NonText', { fg = c.dark_gray, bg = 'NONE', italic = true })
end
-- JSON: Disable default syntax highlighting concealment
-- vim.g.vim_json_conceal = 0
-- Default is 'nc' which makes it hard to predict moves required to edit the current line or search matching patterns.
-- Conceiling only in visual mode makes it more consistent, IMO.
vim.o.concealcursor = 'v'
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
vim.opt_local.shiftwidth = 2 -- I prefer a more compact view. vim-sleuth will auto-adapt for existing files.
end
})
require('functions.diff')
-- vim: sw=2 et