-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
516 lines (471 loc) · 15.9 KB
/
Copy pathinit.lua
File metadata and controls
516 lines (471 loc) · 15.9 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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
vim.opt.shell = "/bin/zsh"
local lazy = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.uv.fs_stat(lazy) then
vim.fn.system({ "git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", lazy,
})
end
vim.opt.rtp:prepend(lazy)
require("lazy").setup({
"morhetz/gruvbox",
"tpope/vim-fugitive",
"mhinz/vim-startify",
"lifepillar/vim-solarized8",
"ibhagwan/fzf-lua",
"nvim-lualine/lualine.nvim",
"neovim/nvim-lspconfig",
"mason-org/mason.nvim",
"mason-org/mason-lspconfig.nvim",
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
},
"dense-analysis/ale",
{
"Saghen/blink.cmp",
dependencies = { "rafamadriz/friendly-snippets" },
version = "*",
build = "cargo build --release",
},
}, {
defaults = { lazy = false },
})
-- Share this repo (vimfiles) with Neovim so spell/colors/after files are found.
-- Must be AFTER lazy.setup() because lazy.nvim rebuilds the runtimepath.
for _, sub in ipairs({ "", "/after", "/spell", "/colors", "/autoload", "/ftplugin", "/plugin", "/snippets" }) do
vim.opt.rtp:prepend(vim.fn.expand("~/.vim") .. sub)
end
--==================================VIM CONFIG==================================
vim.opt.helplang = "en"
vim.opt.title = true
vim.opt.cursorline = true
vim.opt.cursorcolumn = true
-- Time to wait after ESC (default causes an annoying delay)
vim.opt.timeoutlen = 250
vim.opt.smartcase = true
vim.opt.hlsearch = true
-- show matches while typing
vim.opt.incsearch = true
-- Fix for Russian world
vim.opt.iskeyword = "@,48-57,_,192-255"
-- Number of visual spaces per TAB
vim.opt.tabstop = 4
-- Number of spaces in TAB when editing
vim.opt.softtabstop = 4
-- Tabs replaced on spaces
vim.opt.expandtab = true
vim.opt.smarttab = true
-- Show unprintable symbols with set list
vim.opt.listchars = "eol:$,tab:>-,trail:~,extends:>,precedes:<"
vim.opt.showmatch = true
vim.opt.autoindent = true
-- Show command in bottom bar
vim.opt.showcmd = true
-- перенос по словам, а не по буквам
vim.opt.linebreak = true
vim.opt.display = "lastline"
-- Show line number
vim.opt.number = true
-- Wrap lines by 200 char
vim.opt.wrap = true
vim.opt.textwidth = 200
vim.opt.colorcolumn = "200"
vim.opt.shiftwidth = 4
-- round indent to multiple of 'shiftwidth'
vim.opt.shiftround = true
vim.opt.mouse = "a"
-- Yanks go on clipboard instead
vim.opt.clipboard:append("unnamed")
vim.opt.modeline = true
vim.opt.modelines = 5
vim.opt.completeopt = "longest,menuone"
vim.opt.pumheight = 15
vim.opt.wildmode = "list:longest,full"
vim.opt.wildmenu = true
vim.opt.wildignore:append(".git,.svn")
vim.opt.wildignore:remove("deps")
vim.opt.wildoptions = "fuzzy"
vim.opt.history = 256
vim.opt.undodir = vim.fn.expand("~/.vim/nundodir/")
vim.opt.undofile = true
vim.opt.undolevels = 1000
vim.opt.undoreload = 10000
-- Backup
vim.opt.backup = true
vim.opt.backupdir:prepend("/tmp//")
vim.opt.directory:prepend("/tmp//")
vim.opt.writebackup = true
-- Required for operations modifying multiple buffers like rename.
vim.opt.hidden = true
-- default vertical split file browser
vim.g.netrw_preview = 1
vim.g.netrw_browse_split = 4
vim.g.netrw_altv = 1
vim.g.netrw_localrmdir = "rm -r"
vim.g.netrw_winsize = -23
vim.g.netrw_banner = 0
vim.g.netrw_liststyle = 3
-- Add Russian keyboard for commands
vim.opt.keymap = "russian-jcukenwin"
vim.opt.iminsert = 0
vim.opt.imsearch = 0
-- DTL / Erlang filetypes
local ftype_aug = vim.api.nvim_create_augroup("UserFiletypes", { clear = true })
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
group = ftype_aug,
pattern = { "*.dtl", "*.tmpl" },
callback = function()
vim.bo.filetype = "django"
end,
})
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
group = ftype_aug,
pattern = {
"*relx.config*",
"*rebar.config*",
"*sys.config*",
"*.appup",
"*.app",
"*.config",
"*.appup.src",
"*.app.src",
},
callback = function()
vim.bo.filetype = "erlang"
end,
})
-- Open file in last place
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = "*",
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
})
-- Folds
vim.opt.foldmethod = "syntax"
vim.opt.spell = true
vim.opt.spelllang = { "ru_yo", "en", "programming" }
vim.api.nvim_set_hl(0, "SpellBad", { reverse = true, ctermbg = 226 })
vim.api.nvim_set_hl(0, "SpellRare", { reverse = true, ctermbg = 226 })
vim.api.nvim_set_hl(0, "lCursor", { fg = "NONE", bg = "Cyan" })
local langmap = "ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ"
langmap = langmap .. ",фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz"
vim.opt.langmap = langmap
--=============================DELETE TRAILING SPACES===========================
local function strip_trailing_whitespace()
local cur = vim.api.nvim_win_get_cursor(0)
vim.cmd("%s/\\s\\+$//e")
vim.api.nvim_win_set_cursor(0, cur)
end
vim.api.nvim_create_autocmd("FileType", {
pattern = { "c", "cpp", "java", "erlang", "python" },
callback = function()
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = 0,
callback = strip_trailing_whitespace,
})
end,
})
local function append_modeline()
local ts = vim.opt.tabstop:get()
local sw = vim.opt.shiftwidth:get()
local tw = vim.opt.textwidth:get()
local et = vim.opt.expandtab:get() and "" or "no"
local modeline = string.format(" vim: set ts=%d sw=%d tw=%d %set :", ts, sw, tw, et)
local commentstring = vim.bo.commentstring or "%s"
modeline = vim.fn.substitute(commentstring, "%s", modeline, "")
vim.api.nvim_buf_set_lines(0, -1, -1, false, { modeline })
end
vim.keymap.set("n", "<leader>ml", append_modeline, { silent = true, desc = "Append modeline" })
--================================KEY BINDINGS==================================
vim.keymap.set("i", "jj", "<Esc>")
-- Open/close folds
vim.keymap.set("n", "<Space>", "za")
vim.keymap.set("v", "<CR>", "<Plug>(EasyAlign)")
-- turn off search highlight
vim.keymap.set("n", "<leader><space>", ":nohlsearch<CR>")
-- Edit vimrc
vim.keymap.set("n", "<leader>ev", ":vsp $MYVIMRC<CR>")
-- Load vimrc
vim.keymap.set("n", "<leader>sv", ":source $MYVIMRC<CR>")
vim.keymap.set("n", "<leader>u", ":UndotreeToggle<CR>")
-- Toggle netrw like NERDTree + misc commands/filters
vim.cmd([[
function! ToggleVExplorer()
if exists("t:expl_buf_num")
let expl_win_num = bufwinnr(t:expl_buf_num)
if expl_win_num != -1
let cur_win_nr = winnr()
exec expl_win_num . 'wincmd w'
close
unlet t:expl_buf_num
else
unlet t:expl_buf_num
endif
else
exec '1wincmd w'
Vexplore
let t:expl_buf_num = bufnr("%")
endif
endfunction
]])
vim.keymap.set("n", "-", ":call ToggleVExplorer()<CR>", { silent = true })
vim.cmd("command! W :execute ':silent w !sudo tee % > /dev/null' | :edit!")
vim.keymap.set("n", "<leader>jj", ":%!python -m json.tool<CR>")
--================================COLOR THEME===================================
vim.opt.termguicolors = true
vim.opt.background = "light"
vim.g.gruvbox_contrast_light = "hard"
vim.cmd("syntax enable")
vim.cmd.colorscheme("gruvbox")
--=================================FZF-LUA=====================================
local ok_fzf, fzf = pcall(require, "fzf-lua")
if ok_fzf then
fzf.setup {
fzf_bin = "fzf",
winopts = {
preview = {
layout = "right",
vertical = "down:40%",
flip_columns = 0.55,
},
},
files = {
-- если fd нет, fzf-lua автоматически переключится на find (игнорим git/deps)
fd_opts = "--color=never --type f --exclude .git",
},
-- integrações nativas (git, lsp, buffers) via fzf-lua
git = { status = { preview_pager = false } },
}
-- Mappings
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { desc = desc })
end
map("n", "<leader>b", fzf.buffers, "Buffers")
map("n", "<leader>g", fzf.live_grep, "Live grep")
map("n", "<C-p>", fzf.files, "Find files")
end
--===================================LUALINE====================================
local ok_lualine, lualine = pcall(require, "lualine")
if ok_lualine then
lualine.setup {
options = {
theme = "gruvbox",
component_separators = { left = "|", right = "|" },
section_separators = { left = "", right = "" },
disabled_filetypes = { statusline = { "dashboard", "alpha" } },
},
sections = {
lualine_a = { { "mode" } },
lualine_b = { "branch", "diff" },
lualine_c = { { "filename", path = 1 } },
lualine_x = { "diagnostics", "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" },
},
extensions = { "fugitive" },
}
end
--=================================STARTIFY=====================================
vim.g.startify_lists = {
{ type = "sessions", header = { " Sessions" } },
{ type = "dir", header = { " MRU " .. vim.fn.getcwd() } },
{ type = "files", header = { " MRU " } },
{ type = "bookmarks", header = { " Bookmarks" } },
}
-- Don't change dir for opening new file from start screen
vim.g.startify_change_to_dir = 0
vim.g.startify_files_number = 25
--================================TREESITTER====================================
local ok_treesitter, ts_configs = pcall(require, "nvim-treesitter.configs")
if ok_treesitter then
ts_configs.setup {
ensure_installed = { "bash", "c", "lua", "go", "python" },
sync_install = false,
auto_install = true,
ignore_install = {},
highlight = {
enable = true,
disable = {},
additional_vim_regex_highlighting = false,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
indent = {
enable = true,
},
}
end
--=================================MASON (LSP INSTALLER)========================
-- Automatically installs LSP servers, including lua-language-server
local ok_mason, mason = pcall(require, "mason")
if ok_mason then
mason.setup({})
end
local ok_mason_lspconfig, mason_lspconfig = pcall(require, "mason-lspconfig")
if ok_mason_lspconfig then
mason_lspconfig.setup({
ensure_installed = { "lua_ls" },
automatic_installation = true,
})
end
--======================================LSP=====================================
-- Modern nvim 0.11+ API (vim.lsp.config / vim.lsp.enable via nvim-lspconfig)
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.documentationFormat = {
"markdown",
"plaintext",
}
-- Enable diagnostics via LSP
vim.diagnostic.config({
virtual_text = true,
signs = true,
update_in_insert = false,
})
local on_attach = function(client, bufnr)
local nmap = function(keys, func, desc)
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc })
end
nmap("gd", vim.lsp.buf.definition, "Go to definition")
nmap("gr", vim.lsp.buf.references, "Find references")
nmap("gD", vim.lsp.buf.declaration, "Go to declaration")
nmap("gi", vim.lsp.buf.implementation, "Go to implementation")
nmap("K", vim.lsp.buf.hover, "Hover")
nmap("<leader>rn", vim.lsp.buf.rename, "Rename symbol")
nmap("<leader>ca", vim.lsp.buf.code_action, "Code action")
nmap("[g", vim.diagnostic.goto_prev, "Previous diagnostic")
nmap("]g", vim.diagnostic.goto_next, "Next diagnostic")
nmap("<leader>tq", vim.lsp.buf.type_definition, "Type definition")
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end
-- Golang
if vim.fn.executable("gopls") then
vim.lsp.config("gopls", {
cmd = { "gopls" },
capabilities = capabilities,
on_attach = on_attach,
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
usePlaceholders = true,
completeUnimported = true,
},
},
})
vim.lsp.enable("gopls")
vim.api.nvim_create_autocmd("FileType", {
pattern = "go",
callback = function()
vim.keymap.set("n", "gT", ":e %:r_test.go<CR>", { buffer = 0, desc = "Open test file" })
end,
})
end
-- Python via pyright if available
vim.lsp.config("pyright", {
cmd = { "pyright-langserver", "--stdio" },
capabilities = capabilities,
on_attach = on_attach,
})
vim.lsp.enable("pyright")
-- Lua via lua-language-server (installed by Mason)
vim.lsp.config("lua_ls", {
capabilities = capabilities,
on_attach = on_attach,
settings = {
Lua = {
runtime = { version = "LuaJIT" },
diagnostics = { globals = { "vim" } },
workspace = {
library = {
vim.env.VIMRUNTIME,
vim.fn.expand("$VIMRUNTIME/lua"),
vim.fn.expand("$VIMRUNTIME/lua/vim/lsp"),
},
},
telemetry = { enable = false },
},
},
})
vim.lsp.enable("lua_ls")
--=======================================ALE=====================================
vim.g.ale_open_list = 1
vim.g.ale_completion_enabled = 0
vim.g.ale_linters = {
go = { "golangci-lint" },
zsh = { "shellcheck" },
sh = { "shellcheck" },
bash = { "shellcheck" },
python = { "pyright", "pyflakes", "mypy" },
yaml = {},
}
vim.g.ale_go_golangci_lint_package = 1
--==================================== BLINK.CMP ===============================
-- Popup-автодополнение при наборе текста (поверх native nvim LSP)
local ok_blink, blink = pcall(require, "blink.cmp")
if ok_blink then
blink.setup({
appearance = {
use_nvim_cmp_as_default = false,
nerd_font_variant = "mono",
},
completion = {
documentation = { auto_show = true },
menu = {
border = "rounded",
draw = {
columns = {
{ "label", gap = 1 },
{ "kind_icon", gap = 1 },
{ "kind" },
},
},
},
},
sources = {
default = { "lsp", "path", "buffer" },
},
signature = { enabled = true },
keymap = {
preset = "default",
["<C-Space>"] = { "show" },
["<C-e>"] = { "hide" },
["<Tab>"] = { "select_next", "fallback" },
["<S-Tab>"] = { "select_prev", "fallback" },
["<C-b>"] = { "scroll_documentation_down" },
["<C-f>"] = { "scroll_documentation_up" },
},
cmdline = {
keymap = { preset = "default" },
},
})
end
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(event)
local opts = { buffer = event.buf, desc = "Go to Implementation" }
-- Map 'gi' in Normal mode to jump to the implementation
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
end,
})