-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
461 lines (435 loc) · 16.7 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
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
452
453
454
455
456
457
458
459
460
461
-- =======================================================================
-- Utils
-- =======================================================================
function Map(mode, lhs, rhs, opts)
local options = { noremap = true, silent = true, unique = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.keymap.set(mode, lhs, rhs, options)
end
-- =======================================================================
-- Bootstrap lazy.nvim
-- =======================================================================
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--branch=stable",
lazyrepo,
lazypath,
})
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
-- =======================================================================
-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
-- =======================================================================
-- Options
-- =======================================================================
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
vim.filetype.add({
extension = { tex = "tex", zir = "zir" },
pattern = { ["[jt]sconfig.*.json"] = "jsonc" },
})
vim.o.autoindent = true
vim.o.autoread = true
vim.o.backspace = "eol,start,indent"
vim.o.backup = false
vim.o.cindent = true
vim.o.cmdheight = 2 -- Height of the command bar
vim.o.conceallevel = 0
vim.o.cursorline = true -- highlight current line
vim.o.errorbells = false
vim.o.expandtab = true
vim.o.fileencoding = "utf-8" -- the encoding written to a file
vim.o.foldcolumn = "1" -- Add a bit extra margin to the left
vim.o.foldenable = true -- enable folding
vim.o.foldlevelstart = 10 -- open most folds by default
vim.o.foldmethod = "syntax" -- fold based on indent level
vim.o.foldnestmax = 10 -- 10 nested fold max
vim.o.hidden = true -- if hidden is not set, TextEdit might fail.
vim.o.hlsearch = true -- highlight matches
vim.o.ignorecase = true -- ignore case in search patterns
vim.o.incsearch = true -- search as characters are entered
vim.o.lazyredraw = true -- redraw only when we need to.
vim.o.linebreak = true
vim.o.mat = 2 -- How many tenths of a second to blink when matching brackets
vim.o.number = true
vim.o.numberwidth = 3
vim.o.relativenumber = true
vim.o.ruler = true -- Always show current position
vim.o.scrolloff = 0 -- minimal number of screen lines to keep above and below the cursor.
vim.o.sessionoptions = "blank,curdir,folds,tabpages,winsize,winpos,terminal"
vim.o.shiftwidth = 2
vim.o.showcmd = true -- show command in bottom bar
vim.o.showmatch = true -- Show matching brackets when text indicator is over them
vim.o.showmode = false -- we don't need to see things like -- INSERT -- anymore
vim.o.sidescrolloff = 8 -- minimal number of screen lines to keep left and right of the cursor.
vim.o.signcolumn = "yes:1"
vim.o.smartcase = true -- smart case
vim.o.smartindent = true
vim.o.softtabstop = 2
vim.o.statuscolumn = "%l %s"
vim.o.swapfile = false
vim.o.tabstop = 2
vim.o.termguicolors = true
vim.o.textwidth = 80
vim.o.timeoutlen = 600
vim.o.ttyfast = true
vim.o.updatetime = 300 -- You will have bad experience for diagnostic messages when it's default 4000.
vim.o.visualbell = false
vim.o.whichwrap = "b,s,<,>,h,l,[,]"
vim.o.wildignore =
"*/node_modules/*,*/tmp/*,tags,*.jpg,*.png,*.pyc,*.min.js,*/dist/*,*/json/*,*/csv/*,*/target/*,node_modules,*.json,*.csv,*.txt,*.tsv"
vim.o.wildmenu = true -- visual autocomplete for command menu
vim.o.wrap = true
vim.o.writebackup = false -- Some servers have issues with backup files, see #649
vim.opt.list = false
vim.opt.listchars:append("eol:↴")
vim.opt.listchars:append("space:⋅")
vim.opt.shortmess:append("I") -- don't show the default intro message
vim.opt.shortmess:append("c") -- don't show redundant messages from ins-completion-menu
vim.opt.spelllang:append("cjk") -- disable spellchecking for asian characters (VIM algorithm does not support it)
-- =======================================================================
-- Setup lazy.nvim
-- =======================================================================
require("lazy").setup({
{ "ravibrock/spellwarn.nvim", event = "VeryLazy", config = true },
{
"ibhagwan/fzf-lua",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("fzf-lua").setup({})
end,
opts = { "skim" },
},
{
"lewis6991/gitsigns.nvim",
opt = {},
config = function()
require("gitsigns").setup({
signs = {
add = { text = "+" },
change = { text = "~" },
delete = { text = "-" },
topdelete = { text = "-" },
changedelete = { text = "~" },
untracked = { text = "┆" },
},
signcolumn = false, -- Toggle with `:Gitsigns toggle_signs`
numhl = true, -- Toggle with `:Gitsigns toggle_numhl`
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
watch_gitdir = { interval = 1000, follow_files = true },
attach_to_untracked = true,
current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
virt_text = true,
virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align'
delay = 1000,
ignore_whitespace = false,
},
current_line_blame_formatter = "<author>, <author_time:%Y-%m-%d> - <summary>",
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
max_file_length = 40000, -- Disable if file is longer than this (in lines)
preview_config = {
-- Options passed to nvim_open_win
border = "rounded",
style = "minimal",
relative = "cursor",
row = 0,
col = 2,
},
on_attach = function(bufnr)
local gitsigns = require("gitsigns")
local opts = { buffer = bufnr }
local fn_next = function()
if vim.wo.diff then
vim.cmd.normal({ "]g", bang = true })
else
gitsigns.nav_hunk("next")
end
end
local fn_prev = function()
if vim.wo.diff then
vim.cmd.normal({ "[g", bang = true })
else
gitsigns.nav_hunk("prev")
end
end
-- Navigation
Map("n", "]g", fn_next, opts)
Map("n", "[g", fn_prev, opts)
-- Actions
Map("n", "<leader>gb", "<cmd>Gitsigns blame<CR>", opts)
Map("n", "<leader>gd", gitsigns.diffthis, opts)
-- Text object
Map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", opts)
end,
})
-- https://vim.fandom.com/wiki/Xterm256_color_names_for_console_Vim
vim.cmd([[
augroup gitsigns_colors
autocmd!
autocmd ColorScheme * hi DiffAdd gui=none guibg=NONE guifg=DarkOliveGreen3
autocmd ColorScheme * hi DiffChange gui=none guibg=NONE guifg=RoyalBlue1
autocmd ColorScheme * hi DiffDelete gui=none guibg=NONE guifg=IndianRed
autocmd ColorScheme * hi DiffText gui=none guibg=NONE guifg=yellow
autocmd ColorScheme * hi GitSignsAdd gui=none guibg=NONE guifg=DarkOliveGreen3
autocmd ColorScheme * hi GitSignsChange gui=none guibg=NONE guifg=RoyalBlue1
autocmd ColorScheme * hi GitSignsDelete gui=none guibg=NONE guifg=IndianRed
autocmd ColorScheme * hi GitSignsUntracked gui=none guibg=NONE guifg=grey69
augroup END
]])
end,
},
{
"m4xshen/hardtime.nvim",
dependencies = { "MunifTanjim/nui.nvim" },
opts = {},
},
{ "ntpeters/vim-better-whitespace", opt = {} },
{ "p7g/vim-bow-wob", opt = {} },
{ "tpope/vim-surround", opt = {} },
{ "windwp/nvim-autopairs", event = "InsertEnter", config = true },
{
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("lualine").setup({
options = {
icons_enabled = false,
theme = "codedark",
component_separators = { left = "|", right = "|" },
section_separators = { left = "", right = "" },
disabled_filetypes = { statusline = {}, winbar = {} },
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = { statusline = 1000, tabline = 1000, winbar = 1000 },
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "buffers" },
lualine_x = { "encoding", "fileformat", "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" },
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { "filename" },
lualine_x = { "location" },
lualine_y = {},
lualine_z = {},
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {},
})
end,
},
{
"folke/lazydev.nvim",
ft = "lua", -- only load on lua files
opts = {
library = {
-- See the configuration section for more details
-- Load luvit types when the `vim.uv` word is found
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
},
}, -- =======================================================================
-- Completions
-- =======================================================================
{
"saghen/blink.cmp",
event = { "LspAttach" },
dependencies = {
"rafamadriz/friendly-snippets",
"nvim-tree/nvim-web-devicons",
},
version = "*",
opts = {
completion = {
ghost_text = { enabled = true },
list = { selection = { preselect = true, auto_insert = true } },
menu = { border = "single" },
documentation = { window = { border = "single" } },
},
signature = { enabled = true, window = { border = "single" } },
-- https://cmp.saghen.dev/configuration/keymap.html#default
keymap = { preset = "default" },
appearance = {
highlight_ns = vim.api.nvim_create_namespace("blink_cmp"),
use_nvim_cmp_as_default = true,
nerd_font_variant = "mono",
},
sources = {
default = { "lazydev", "lsp", "path", "snippets", "buffer" },
providers = {
lazydev = {
name = "LazyDev",
module = "lazydev.integrations.blink",
-- make lazydev completions top priority (see `:h blink.cmp`)
score_offset = 100,
},
},
},
},
opts_extend = { "sources.default" },
},
{
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"j-hui/fidget.nvim",
"saghen/blink.cmp",
},
opts = {
servers = {
lua_ls = {
settings = {
Lua = {
diagnostics = {
globals = { "vim", "it", "describe", "before_each", "after_each" },
},
},
},
},
},
},
-- =======================================================================
-- Lsp Config
-- =======================================================================
config = function()
local blink_capabilities = require("blink.cmp").get_lsp_capabilities()
local capabilities =
vim.tbl_deep_extend("force", {}, vim.lsp.protocol.make_client_capabilities(), blink_capabilities)
require("fidget").setup({})
require("mason").setup()
require("mason-lspconfig").setup({
automatic_installation = true,
ensure_installed = { "lua_ls", "rust_analyzer" },
handlers = {
function(server_name)
require("lspconfig")[server_name].setup({ capabilities = capabilities })
end,
},
})
-- =======================================================================
-- Diagnostics
-- =======================================================================
vim.diagnostic.config({
float = { border = "rounded" },
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "✘",
[vim.diagnostic.severity.WARN] = "▲",
[vim.diagnostic.severity.HINT] = "⚑",
[vim.diagnostic.severity.INFO] = "»",
},
},
})
-- =======================================================================
-- LspAttach
-- =======================================================================
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(event)
local opts = {
noremap = true,
unique = false,
silent = false,
buffer = event.buf,
}
Map("n", "<leader>f", "<cmd>lua vim.lsp.buf.format({async = true})<cr>", opts)
Map("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>", opts)
Map("n", "go", "<cmd>lua vim.lsp.buf.type_definition()<cr>", opts)
-- Check :h lsp-defaults
-- 'formatexpr' is set to |vim.lsp.formatexpr()|, so you can format lines via |gq| if the language server supports it.
-- Map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts) -- :h K
-- Map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts) -- :h CTRL-], CTRL-W_], CTRL-W_}
-- Map('n', 'grn', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
-- Map('n', 'gra', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
-- Map('n', 'grr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
-- Map('n', 'gri', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
-- Map('n', 'gO', '<cmd>lua vim.lsp.buf.document_symbol()<cr>', opts)
-- Map('i', '<C-s>', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
end,
})
end,
},
})
-- =======================================================================
-- Commands
-- =======================================================================
vim.cmd("colorscheme bow-wob")
vim.cmd("highlight SignColumn guibg=bow-wob")
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
-- :h fzf-lua-coming-from-fzf.vim?
vim.cmd(":FzfLua setup_fzfvim_cmds")
-- :h better-whitespace-:EnableWhitespace
vim.cmd(":EnableWhitespace")
-- =======================================================================
-- AutoCommands
-- =======================================================================
-- :h vim.hl
vim.api.nvim_set_hl(0, "YankHighlight", { bg = "#c30049", fg = "#ffffff" })
vim.api.nvim_create_autocmd("TextYankPost", {
desc = "Highlight when yanking (copying) text",
group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }),
callback = function()
vim.highlight.on_yank({ higroup = "YankHighlight", timeout = 300 })
end,
})
-- =======================================================================
-- Remaps
-- Please check out the default-mappings in :h default-mappings
-- =======================================================================
-- search
-- Map('n', '<leader>h', ':nohlsearch<CR>') -- :h CTRL-L-default
-- wrap and list
Map("n", "<leader>w", ":set wrap!<CR>") -- Toggle wrap
Map("n", "<leader>l", ":set list!<CR>") -- Toggle list
-- diagnostics
-- Map('n', '<C-W>d', vim.diagnostic.open_float) -- :h CTRL-W_d-default
-- Map('n', '[d', vim.diagnostic.goto_prev) -- :h [d-default
-- Map('n', ']d', vim.diagnostic.goto_next) -- :h ]d-default
Map("n", "<leader>q", vim.diagnostic.setloclist)
-- move text on visual mode
Map("v", "J", ":m '>+1<CR>gv=gv")
Map("v", "K", ":m '<-2<CR>gv=gv")
-- buffers
Map("n", "<TAB>", ":bn<CR>")
Map("n", "<S-TAB>", ":bp<CR>")
-- center screen on search and screen movement
Map("n", "<C-d>", "<C-d>zz")
Map("n", "<C-u>", "<C-u>zz")
Map("n", "n", "nzzzv")
Map("n", "N", "Nzzzv")
-- resize windows
Map("n", "<C-Up>", ":resize -2<CR>")
Map("n", "<C-Down>", ":resize +2<CR>")
Map("n", "<C-Left>", ":vertical resize -2<CR>")
Map("n", "<C-Right>", ":vertical resize +2<CR>")