-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
580 lines (444 loc) · 17.1 KB
/
init.vim
File metadata and controls
580 lines (444 loc) · 17.1 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
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
567
568
569
570
571
572
573
574
575
576
577
578
579
" ******************** PLUGINS ********************
if &compatible
set nocompatible
endif
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - For Vim: '.vim/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin(stdpath('data') . '/plugged')
" GitHub Copilot
" Plug 'github/copilot.vim'
Plug 'zbirenbaum/copilot.lua'
" Modeline security
Plug 'ciaranm/securemodelines'
" Treesitter
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Automatically update the parsers
" Plug 'nvim-treesitter/nvim-treesitter-refactor'
" Snippets
" follow latest release and install jsregexp.
Plug 'L3MON4D3/LuaSnip', {'tag': 'v2.*', 'do': 'make install_jsregexp'}
" load extra snippets
Plug 'rafamadriz/friendly-snippets'
" Completion (based on blink.cmp)
Plug 'nvim-tree/nvim-web-devicons'
Plug 'onsails/lspkind.nvim'
Plug 'Saghen/blink.cmp', { 'do': 'cargo build --release' }
Plug 'giuxtaposition/blink-cmp-copilot'
" LSP
Plug 'neovim/nvim-lspconfig'
" Plug 'mfussenegger/nvim-jdtls'
" Telescope
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
" Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.8' }
Plug 'nvim-telescope/telescope.nvim'
Plug 'BurntSushi/ripgrep'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
" Motion and searching extensions
Plug 'haya14busa/is.vim'
Plug 'smoka7/hop.nvim'
" Status line
Plug 'nvim-lualine/lualine.nvim'
" Easy align
Plug 'junegunn/vim-easy-align'
" Async testing
Plug 'janko-m/vim-test'
Plug 'neomake/neomake'
" Ruby support
Plug 'vim-ruby/vim-ruby'
" Tim Pope's stuff
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-projectionist'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-unimpaired'
" Rust support
Plug 'rust-lang/rust.vim'
" Zig support
Plug 'ziglang/zig.vim'
" Facilitate opening files from grep output
Plug 'bogado/file-line'
" Themes
Plug 'folke/tokyonight.nvim'
" Plug 'catppuccin/nvim'
call plug#end()
" Enable file type detection and language-dependent indenting.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
" Note: this is required by many different functions provided either by the
" editor or by plugins, such as vim-commentary.
filetype plugin indent on
" make test commands execute using dispatch.vim
let test#strategy = "neovim"
" ******************** GENERAL SETTINGS ********************
syntax enable
" Enable mouse
set mouse=a
" Improve the cursor visibility
set cursorline
" Show the cursor position all the time
set ruler
" Use line numbers
set number
" Set minimum width of number field
set numberwidth=5
" Be more liberal with hidden buffers
set hidden
" Enable local, i.e., per-project, .exrc configuration files.
set exrc
" Disable annoying K command, that attempts to display man pages
" (see http://blog.sanctum.geek.nz/vim-annoyances/)
nnoremap K <nop>
" Enable syntax based folding method
set foldmethod=syntax
" Effectively disable folds unless they are requested
set foldlevelstart=99
set foldlevel=99
" Prevents inserting two spaces after punctuation on a join (J)
set nojoinspaces
" Disable annoying conceal
set conceallevel=0
" Disable modelines, use securemodelines.vim instead
set nomodeline
" Allow to override the following settings via modelines
let g:secure_modelines_allowed_items = [
\ "syntax", "syn",
\ "textwidth", "tw",
\ "softtabstop", "sts",
\ "tabstop", "ts",
\ "shiftwidth", "sw",
\ "expandtab", "et", "noexpandtab", "noet",
\ "filetype", "ft",
\ "foldmethod", "fdm",
\ "readonly", "ro", "noreadonly", "noro",
\ "rightleft", "rl", "norightleft", "norl"
\ ]
" Use xdiff with patience algorithm (https://vimways.org/2018/the-power-of-diff/)
set diffopt=internal,algorithm:patience,indent-heuristic
" Always use system clipboard
set clipboard+=unnamedplus
" ******************** COLORS ********************
" Use true color
set termguicolors
" Set dark background
set background=dark
" Use a modern colorscheme
colorscheme tokyonight-moon
" colorscheme catpuccin
" ******************** EDITING ********************
" Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
" Use , as <Leader> special character
let g:mapleader=','
" Disable the hideous highlighting of matching paretheses
let g:loaded_matchparen=1
" Select previously pasted text
" (from: http://vim.wikia.com/wiki/Selecting_your_pasted_text)
nnoremap gp `[v`]
" ******************** INVISIBLE CHARACTERS ********************
" This configuration was taken from vimcasts.org (episode 1)
" Shortcut to rapidly toggle `set list`
nnoremap <leader>l :set list!<CR>
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
" Show invisible characters by default
set list
" ******************** WHITESPACE AND INDENTATION ********************
" This configuration is taken (in part) from vimcasts.org (episodes 4 and 5)
function! Preserve(command)
" Preparation: save last search, and cursor position.
let s:_s=@/
let s:l = line(".")
let s:c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=s:_s
call cursor(s:l, s:c)
endfunction
" Strip trailing spaces
nnoremap <silent> _$ :call Preserve("%s/\\s\\+$//e")<CR>
" Re-indent the whole file
" nnoremap <silent> _= :call Preserve("normal gg=G")<CR>
" Remove blank lines
" nnoremap <silent> __ :%g/^$/d<CR>
" ******************** MATCHIT ********************
" This configuration was taken from vimcasts.org
" (http://vimcasts.org/blog/2010/12/a-text-object-for-ruby-blocks/)
runtime macros/matchit.vim
" ******************** NEOVIM EXTENSIONS ********************
" Shows the effects of :substitute, :smagic, and :snomagic commands
" incrementally, as you type.
if exists('&inccommand')
set inccommand=nosplit
endif
lua <<EOF
-- ******************** GENERIC MAPPINGS ********************
-- Nvim provides a framework for displaying errors or warnings from external
-- tools, otherwise known as "diagnostics". These can come from language servers,
-- linters, or other sources. The following key mappings allow you to navigate and
-- interact with these diagnostics.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
-- ******************** GITHUB COPILOT ********************
require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false },
})
-- ******************** UI COLORS & HIGHLIGHTS ********************
-- Helper function to set highlight groups
local set_hl = function(group, opts)
vim.api.nvim_set_hl(0, group, opts)
end
-- Menu colors
-- Dark grey background with light grey text
set_hl('Pmenu', { bg = '#1c1c1c', fg = '#c0c0c0' })
-- Intense blue background with white bold text for selected item
set_hl('PmenuSel', { bg = '#004b72', fg = '#ffffff', bold = true })
-- Color for rounded border for the completion menu
set_hl('FloatBorder', { fg = '#505050', bg = '#1c1c1c' })
-- Color for ghost text (suggested text while typing)
set_hl('BlinkCmpGhostText', { fg = '#5c6370', italic = true })
-- Icon colors based on kind of completion item
-- GitHub Copilot Teal
set_hl('BlinkCmpKindCopilot', { fg = '#6CC644' })
-- Code element colors
set_hl('BlinkCmpKindFunction', { fg = '#61AFEF' }) -- Blu
set_hl('BlinkCmpKindMethod', { fg = '#61AFEF' }) -- Blu
set_hl('BlinkCmpKindVariable', { fg = '#E06C75' }) -- Red/Orange
set_hl('BlinkCmpKindField', { fg = '#E06C75' }) -- Red/Orange
set_hl('BlinkCmpKindClass', { fg = '#E5C07B' }) -- Yellow/Gold
set_hl('BlinkCmpKindInterface', { fg = '#E5C07B' }) -- Yellow/Gold
set_hl('BlinkCmpKindKeyword', { fg = '#C678DD' }) -- Purple
set_hl('BlinkCmpKindSnippet', { fg = '#56B6C2' }) -- Cyan
set_hl('BlinkCmpKindText', { fg = '#ABB2BF' }) -- Light Grey
-- ******************** BLINK.CMP ********************
local blink = require('blink.cmp')
blink.setup({
-- Snippets
snippets = { preset = 'luasnip' },
appearance = {
use_nvim_cmp_as_default = false,
-- nerd_font_variant = "mono",
kind_icons = {
-- Copilot = "",
Copilot = "", -- GitHub Icon
Text = '',
Method = '',
Function = '',
Constructor = '',
Field = '',
Variable = '',
Class = '',
Interface = 'This',
Module = '',
Property = '',
Unit = '',
Value = '',
Enum = '',
Keyword = '',
Snippet = '',
Color = '',
File = '',
Reference = '',
Folder = '',
EnumMember = '',
Constant = '',
Struct = '',
Event = '',
Operator = '',
TypeParameter = '',
},
},
completion = {
-- Auto brackets
accept = { auto_brackets = { enabled = true } },
-- Show documentation window
documentation = {
auto_show = true,
auto_show_delay_ms = 250,
treesitter_highlighting = true,
window = { border = "rounded" },
},
-- Ghost text: suggestion in grey while you write
ghost_text = { enabled = true },
menu = {
border = 'rounded',
draw = {
-- Column 1: Icon
-- Column 2: Label + Description
-- Column 3: Source (LSP, Copilot, Snippet) or Type (Function, Var)
columns = {
{ "kind_icon" },
{ "label", "label_description", gap = 1 },
{ "kind" }
},
-- Color icon according to the kind of completion item
treesitter = { 'lsp' },
},
}
},
keymap = {
preset = 'default',
["<C-space>"] = { "show", "show_documentation", "hide_documentation" },
["<C-e>"] = { "hide", "fallback" },
["<CR>"] = { "accept", "fallback" },
["<Tab>"] = {
function(cmp) return cmp.select_next() end,
"snippet_forward",
"fallback",
},
["<S-Tab>"] = {
function(cmp) return cmp.select_prev() end,
"snippet_backward",
"fallback",
},
["<Up>"] = { "select_prev", "fallback" },
["<Down>"] = { "select_next", "fallback" },
["<C-p>"] = { "select_prev", "fallback" },
["<C-n>"] = { "select_next", "fallback" },
},
-- Sources for completion items
sources = {
default = { 'lsp', 'path', 'snippets', 'buffer', 'copilot' },
providers = {
copilot = {
name = "copilot",
module = "blink-cmp-copilot",
score_offset = 100, -- High score to prioritize Copilot suggestions
async = true,
-- Copilot icon customization
transform_items = function(_, items)
local CompletionItemKind = require("blink.cmp.types").CompletionItemKind
local kind_idx = #CompletionItemKind + 1
CompletionItemKind[kind_idx] = "Copilot"
for _, item in ipairs(items) do
item.kind = kind_idx
end
return items
end,
},
},
},
})
-- ******************** LSP ********************
-- Get capabilities from blink.cmp
local capabilities = require('blink.cmp').get_lsp_capabilities()
-- Server setup
local servers = { 'clangd', 'solargraph', 'jdtls' }
for _, server in ipairs(servers) do
-- Register configuration for each server
vim.lsp.config(server, {
capabilities = capabilities,
on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
-- K shows the documentation for the symbol under the cursor
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
-- C-K shows the signature help for the symbol under the cursor
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
-- <space>wa - add a folder to the workspace (will prompt for folder name)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
-- <space>wr - remove a folder from the workspace (will prompt for folder name)
-- vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
-- <space>wl - lists folders in the workspace
-- vim.keymap.set('n', '<space>wl', function()
-- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
-- end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
-- <space>ca - select a code action at the current cursor position
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>f', vim.lsp.buf.format, bufopts)
end
})
-- Enable the server
vim.lsp.enable(server)
end
-- ******************** SNIPPETS ********************
-- Add VS Code style snippets from a plugin (i.e. rafamadriz/friendly-snippets)
require("luasnip.loaders.from_vscode").lazy_load()
-- ******************** TREESITTER ********************
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all"
ensure_installed = { "c", "java", "ruby", "lua", "rust", "zig" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = false,
highlight = {
-- `false` will disable the whole extension
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
-- ******************** TELESCOPE ********************
local ts_builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', ts_builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', ts_builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', ts_builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', ts_builtin.help_tags, {})
require('telescope').load_extension('fzy_native')
-- ******************** WEB DEVICONS ********************
require('nvim-web-devicons').setup {
-- globally enable different highlight colors per icon (default to true)
-- if set to false all icons will have the default icon's color
color_icons = true,
-- globally enable default icons (default to false)
-- will get overriden by `get_icons` option
default = true,
}
-- ******************** HOP.NVIM ********************
local hop = require('hop')
hop.setup()
local directions = require('hop.hint').HintDirection
vim.keymap.set('', 'f', function()
hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true })
end, {remap=true})
vim.keymap.set('', 'F', function()
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true })
end, {remap=true})
vim.keymap.set('', 't', function()
hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true, hint_offset = -1 })
end, {remap=true})
vim.keymap.set('', 'T', function()
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true, hint_offset = 1 })
end, {remap=true})
vim.keymap.set('', 's', function()
hop.hint_char2()
end, {remap=true})
-- Might want to add a shortcut to HopWord later on
-- ******************** LUALINE ********************
require('lualine').setup {
options = { theme = 'tokyonight' }
}
EOF
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
" ******************** Console Title ********************
set title
if has('title') && (has('gui_running') || &title)
set titlestring=%{v:progname}\ %t
endif