-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
566 lines (540 loc) · 16 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
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
require("settings")
require("key-binding")
require("packer").startup(function(use)
use("wbthomason/packer.nvim") -- Package manager
use("tpope/vim-fugitive") -- Git commands in nvim
use("tpope/vim-rhubarb") -- Fugitive-companion to interact with github
use("numToStr/Comment.nvim") -- "gc" to comment visual regions/lines
use("p00f/nvim-ts-rainbow")
use("lewis6991/impatient.nvim")
-- use 'ludovicchabant/vim-gutentags' -- Automatic tags management
use("norcalli/nvim-colorizer.lua")
-- UI to select things (files, grep results, open buffers...)
use({ "nvim-telescope/telescope.nvim", requires = { "nvim-lua/plenary.nvim" } })
use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" })
use("navarasu/onedark.nvim") -- Theme inspired by Atom
use("nvim-lualine/lualine.nvim") -- Fancier statusline
-- Add indentation guides even on blank lines
use("lukas-reineke/indent-blankline.nvim")
-- Add git related info in the signs columns and popups
use({ "lewis6991/gitsigns.nvim", requires = { "nvim-lua/plenary.nvim" } })
-- Highlight, edit, and navigate code using a fast incremental parsing library
use("nvim-treesitter/nvim-treesitter")
-- Additional textobjects for treesitter
use("nvim-treesitter/nvim-treesitter-textobjects")
use({
"folke/todo-comments.nvim",
requires = "nvim-lua/plenary.nvim",
config = function()
require("todo-comments").setup({
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
})
end,
})
use("neovim/nvim-lspconfig") -- Collection of configurations for built-in LSP client
use("hrsh7th/nvim-cmp") -- Autocompletion plugin
use("hrsh7th/cmp-nvim-lsp")
use("hrsh7th/cmp-path")
use("saadparwaiz1/cmp_luasnip")
use("L3MON4D3/LuaSnip") -- Snippets plugin
use("tpope/vim-surround") -- vim surround
use("jose-elias-alvarez/null-ls.nvim")
use("lervag/vimtex")
use({
"kyazdani42/nvim-tree.lua",
requires = {
"kyazdani42/nvim-web-devicons", -- optional, for file icon
},
config = function() end,
})
use("windwp/nvim-autopairs")
use({ "CRAG666/code_runner.nvim", requires = "nvim-lua/plenary.nvim" })
end)
require("impatient")
local npairs = require("nvim-autopairs")
local Rule = require("nvim-autopairs.rule")
npairs.setup({
check_ts = true,
fast_wrap = {},
ts_config = {
lua = { "string" }, -- it will not add a pair on that treesitter node
javascript = { "template_string" },
java = false, -- don't check treesitter on java
},
})
npairs.add_rules({
Rule(" ", " "):with_pair(function(opts)
local pair = opts.line:sub(opts.col - 1, opts.col)
return vim.tbl_contains({ "()", "[]", "{}" }, pair)
end),
Rule("( ", " )")
:with_pair(function()
return false
end)
:with_move(function(opts)
return opts.prev_char:match(".%)") ~= nil
end)
:use_key(")"),
Rule("{ ", " }")
:with_pair(function()
return false
end)
:with_move(function(opts)
return opts.prev_char:match(".%}") ~= nil
end)
:use_key("}"),
Rule("[ ", " ]")
:with_pair(function()
return false
end)
:with_move(function(opts)
return opts.prev_char:match(".%]") ~= nil
end)
:use_key("]"),
})
--Set statusbar
require("lualine").setup({
options = {
icons_enabled = false,
theme = "onedark",
component_separators = "|",
section_separators = "",
},
})
require("nvim-tree").setup({
update_focused_file = {
enable = true,
update_cwd = true,
},
})
--Enable Comment.nvim
require("Comment").setup()
require("code_runner").setup({
term = {
position = "belowright",
size = 8,
mode = "",
},
filetype = {
java = "cd $dir && javac $fileName && java $fileNameWithoutExt",
python = "python ",
lua = "lua ",
typescript = "deno run",
rust = "cd $dir && mkdir -p .bin && rustc $fileName && $dir/$fileNameWithoutExt",
cpp = "cd $dir && mkdir -p .bin && g++ $fileName -o .bin/$fileNameWithoutExt && $dir/.bin/$fileNameWithoutExt",
c = "cd $dir && mkdir -p .bin && gcc $fileName -o .bin/$fileNameWithoutExt && $dir/.bin/$fileNameWithoutExt",
},
project = {
["~/playground/c++/open-gl"] = {
name = "open gl learning",
description = "repo to learn open gl",
file_name = "main.cpp",
command = "make -C build run",
},
["~/deno/example"] = {
name = "ExapleDeno",
description = "Project with deno using other command",
file_name = "http/main.ts",
command = "deno run --allow-net",
},
},
})
--Map blankline
require("indent_blankline").setup({
space_char_blankline = " ",
-- show_current_context = true,
max_indent_increase = 1,
filetype_exclude = { "help", "packer" },
buftype_exclude = { "terminal", "nofile" },
show_trailing_blankline_indent = false,
use_treesitter = true,
show_first_indent_level = false,
})
-- Gitsigns
require("gitsigns").setup({
signs = {
add = { text = "+" },
change = { text = "~" },
delete = { text = "_" },
topdelete = { text = "‾" },
changedelete = { text = "~" },
},
on_attach = function(bufnr)
local function map(mode, lhs, rhs, opts)
opts = vim.tbl_extend("force", { noremap = true, silent = true }, opts or {})
vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts)
end
-- Navigation
map("n", "]c", "&diff ? ']c' : '<cmd>Gitsigns next_hunk<CR>'", { expr = true })
map("n", "[c", "&diff ? '[c' : '<cmd>Gitsigns prev_hunk<CR>'", { expr = true })
-- Actions
map("n", "<leader>hs", ":Gitsigns stage_hunk<CR>")
map("v", "<leader>hs", ":Gitsigns stage_hunk<CR>")
map("n", "<leader>hr", ":Gitsigns reset_hunk<CR>")
map("v", "<leader>hr", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>hS", "<cmd>Gitsigns stage_buffer<CR>")
map("n", "<leader>hu", "<cmd>Gitsigns undo_stage_hunk<CR>")
map("n", "<leader>hR", "<cmd>Gitsigns reset_buffer<CR>")
map("n", "<leader>hp", "<cmd>Gitsigns preview_hunk<CR>")
map("n", "<leader>hb", '<cmd>lua require"gitsigns".blame_line{full=true}<CR>')
map("n", "<leader>tb", "<cmd>Gitsigns toggle_current_line_blame<CR>")
map("n", "<leader>hd", "<cmd>Gitsigns diffthis<CR>")
map("n", "<leader>hD", '<cmd>lua require"gitsigns".diffthis("~")<CR>')
map("n", "<leader>td", "<cmd>Gitsigns toggle_deleted<CR>")
-- Text object
map("o", "ih", ":<C-U>Gitsigns select_hunk<CR>")
map("x", "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
})
-- Telescope
require("telescope").setup({
defaults = {
mappings = {
i = {
["<C-u>"] = false,
["<C-d>"] = false,
},
},
},
})
-- Enable telescope fzf native
require("telescope").load_extension("fzf")
-- nvim-tree
require("nvim-tree").setup({
view = {
width = 30,
height = 30,
side = "left",
preserve_window_proportions = true,
mappings = {
list = {
{ key = { "<2-RightMouse>", "<C-]>" }, action = "cd" },
{ key = { "<CR>", "o", "<2-LeftMouse>", "l" }, action = "edit" },
{ key = { "-", "<Backspace>" }, action = "dir_up" },
},
},
},
filters = {
dotfiles = true,
},
})
--Add leader shortcuts
require("nvim-treesitter.configs").setup({
highlight = {
enable = true, -- false will disable the whole extension
},
rainbow = {
enable = true,
-- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for
extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
max_file_lines = nil, -- Do not enable for files with more than n lines, int
-- colors = {}, -- table of hex strings
-- termcolors = {} -- table of colour name strings
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
indent = {
enable = true,
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["]m"] = "@function.outer",
["]]"] = "@class.outer",
},
goto_next_end = {
["]M"] = "@function.outer",
["]["] = "@class.outer",
},
goto_previous_start = {
["[m"] = "@function.outer",
["[["] = "@class.outer",
},
goto_previous_end = {
["[M"] = "@function.outer",
["[]"] = "@class.outer",
},
},
},
})
-- Diagnostic keymaps
-- LSP settings
local lspconfig = require("lspconfig")
vim.lsp.set_log_level("error")
local on_attach = function(_, bufnr)
local opts = { noremap = true, silent = true }
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
vim.api.nvim_buf_set_keymap(
bufnr,
"n",
"<leader>wl",
"<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>",
opts
)
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
vim.api.nvim_buf_set_keymap(
bufnr,
"n",
"<leader>so",
[[<cmd>lua require('telescope.builtin').lsp_document_symbols()<CR>]],
opts
)
end
-- nvim-cmp supports additional completion capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
-- lspconfig.ccls.setup({
-- on_attach = on_attach,
-- capabilities = capabilities,
-- single_file_support = true,
-- init_options = {
-- -- compilationDatabaseDirectory = "build",
-- index = {
-- threads = 0,
-- multiVersion = 1,
-- multiVersionBlackList = "^/usr/include",
-- },
-- cache = {
-- directory = "", -- set to empty string to avoid disk writting
-- },
-- clang = {
-- extraArgs = { "-std=c++2a" },
-- excludeArgs = { "-frounding-math" },
-- },
-- },
-- })
lspconfig.pylsp.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
pylsp = {
plugins = {
configurationSources = { "flake8", "mypy" },
flake8 = { enabled = true, maxLineLength = 120 },
jedi_completion = {
enabled = true,
include_params = true,
},
mypy = { enabled = false },
pycodestyle = { enabled = false },
pyflakes = { enabled = false },
},
},
},
})
-- Enable the following language servers
local servers = { "rust_analyzer", "tsserver", "clangd", "texlab" }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup({
on_attach = on_attach,
capabilities = capabilities,
})
end
-- Example custom server
-- Make runtime files discoverable to the server
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
-- lspconfig.sumneko_lua.setup({
-- on_attach = function(client)
-- client.resolved_capabilities.document_formatting = false
-- client.resolved_capabilities.document_range_formatting = false
-- end,
-- capabilities = capabilities,
-- settings = {
-- Lua = {
-- completion = {
-- callSnippet = "Replace",
-- },
-- runtime = {
-- -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
-- version = "LuaJIT",
-- -- Setup your lua path
-- path = runtime_path,
-- },
-- diagnostics = {
-- enable = true,
-- -- Get the language server to recognize the `vim` global
-- globals = { "vim" },
-- },
-- workspace = {
-- -- Make the server aware of Neovim runtime files
-- library = vim.api.nvim_get_runtime_file("", true),
-- },
-- -- Do not send telemetry data containing a randomized but unique identifier
-- telemetry = {
-- enable = false,
-- },
-- },
-- },
-- })
-- luasnip setup
local luasnip = require("luasnip")
local types = require("luasnip.util.types")
require("luasnip").config.set_config({
history = true,
enable_autosnippets = true,
updateevents = "TextChanged,TextChangedP,TextChangedI",
-- region_check_events = "CursorMoved,CursorHold,InsertEnter",
region_check_events = "InsertEnter",
-- delete_check_events = "TextChangedI,TextChangedP,TextChanged",
delete_check_events = "InsertLeave,InsertEnter",
-- treesitter-hl has 100, use something higher (default is 200).
ext_base_prio = 300,
-- minimal increase in priority.
ext_prio_increase = 1,
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = { { "●", "MoreMsg" } },
},
},
[types.insertNode] = {
active = {
virt_text = { { "●", "ModeMsg" } },
},
},
},
store_selection_keys = "<tab>",
})
-- nvim-cmp setup
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
experimental = {
ghost_text = false,
},
mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-j>"] = cmp.mapping(function(fallback)
if luasnip.choice_active() then
luasnip.change_choice(1)
else
fallback()
end
end, { "i", "s" }),
["<C-k>"] = cmp.mapping(function(fallback)
if luasnip.choice_active() then
luasnip.change_choice(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
}, {
{ name = "luasnip" }, -- For luasnip users.
{ name = "buffer" },
{ name = "path" },
}),
})
-- null-ls setup
require("null-ls").setup({
sources = {
require("null-ls").builtins.formatting.stylua,
require("null-ls").builtins.formatting.jq,
require("null-ls").builtins.diagnostics.eslint,
},
})
vim.diagnostic.config({
virtual_text = false,
signs = true,
underline = true,
update_in_insert = false,
severity_sort = false,
})
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
-- vimtex setup
vim.g.tex_flavor = "latex"
vim.g.vimtex_view_automatic = 0
vim.g.vimtex_quickfix_mode = 0
vim.g.vimtex_imaps_leader = ";"
vim.g.vimtex_fold_enabled = 1
vim.g.vimtex_view_method = "zathura"
-- undofir in tmpfs
local undodir = "/tmp/.undodir_" .. os.getenv("USER")
if not (os.rename(undodir, undodir)) then
os.execute("mkdir " .. undodir)
end
vim.o.undodir = undodir
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
command = "setlocal formatoptions -=c formatoptions -=r formatoptions -=o ", --disable auto commenting
})
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = "*",
command = 'normal! g`"',
})
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = "*",
})
vim.api.nvim_set_hl(0, "Conceal", { guibg = none })
vim.api.nvim_set_hl(0, "DiagnosticVirtualTextWarn", { guibg = none })
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets" })