-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
542 lines (453 loc) · 16.8 KB
/
.vimrc
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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Marciovmf (N)VIM config
" https://github.com/marciovmf/vimstuff
" @version: 2.01
" @changelog:
" - fold metod for /**/ displays the content of the first non-empty line
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" -NEOVIDE---------------------------------------------------------------------
"let g:neovide_cursor_vfx_mode = ""
let g:neovide_cursor_animate_command_line = v:true
let g:neovide_scroll_animation_length = 0.3
let g:neovide_cursor_vfx_particle_lifetime = 2.0
let g:neovide_cursor_vfx_particle_density = 40.0
let g:neovide_cursor_vfx_particle_speed = 20.0
function! ToggleFullscreen()
let g:neovide_fullscreen = !g:neovide_fullscreen
endfunction
noremap <silent> <A-CR> :silent call ToggleFullscreen()<CR>
" -VIMRC MISC------------------------------------------------------------------
let $VIMHOME = $HOME."/.vim"
let $SWAPDIR = $VIMHOME."/swap//"
augroup vimrc
autocmd!
autocmd! BufWritePost $MYVIMRC source $MYVIMRC "Automatically source .vimrc when saving it
autocmd! BufWritePost "~/.vimrc" source "~/.vimrc" "Automatically source .vimrc when saving it
" -GLOBAL SETTINGS-------------------------------------------------------------
filetype plugin on
set encoding=UTF-8
set title "We can change the tile of the window
set syntax
set noswapfile "Turn off swap file generation
set clipboard=unnamed "Use the OS clipboard for copying/pasting
set nu "Show file numbers
set foldmethod=syntax
set foldlevelstart=99
set expandtab "Never use hard tabs
set nojoinspaces "Avoid double spaces when joining lines
set shiftwidth=2 "One tab = 2 spaces (auto indent)
set shiftround "Only ident to multiple of shiftwidth
set tabstop=2
set softtabstop=2 "Tab key inserts 2 spaces
set textwidth=80 "Maximum characters before wrapping
set wrap "Wrap line after textwidth characters
set hlsearch "Highlight search matches
"'set listchars=tab:»·,nbsp:+,trail:·,extends:→,precedes:←
set listchars=tab:»\ ,extends:›,precedes:‹,nbsp:·,trail:·
set autoindent
set smartindent
set ignorecase
set smartcase
set cindent
set exrc "Enable per directory .exrc file
set laststatus=2 "Always show status bar
set cursorline "Enable highlighting the cursor line
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P\ %y\ %(\ %m%)\ %{&ft}\ \ %l:\ %L,\ col:%c\ %s
" -PLUGINS---------------------------------------------------------------------
call plug#begin('~/.vim/plugged')
" -SMOOTH SCROLLING-------------
" Plug 'joeytwiddle/sexy_scroller.vim'
" -CURSOR WORD------------------
Plug 'xiyaowong/nvim-cursorword'
let g:cursorword_disable_at_startup = v:true
let g:cursorword_min_width = 3
let g:cursorword_max_width = 50
hi default CursorWord cterm=underline gui=underline
" -VIMFILER---------------------
Plug 'Shougo/unite.vim'
Plug 'Shougo/vimfiler.vim'
let g:vimfiler_as_default_explorer = 1
" -FLOAT TERM-------------------
Plug 'voldikss/vim-floaterm' " Float term
nnoremap <silent> <c-F7> :FloatermNew<CR>
tnoremap <silent> <c-F7> <C-\><C-n>:FloatermNew<CR>
nnoremap <silent> <c-F8> :FloatermPrev<CR>
tnoremap <silent> <c-F8> <C-\><C-n>:FloatermPrev<CR>
nnoremap <silent> <c-F9> :FloatermNext<CR>
tnoremap <silent> <c-F9> <C-\><C-n>:FloatermNext<CR>
nnoremap <silent> <c-F12> :FloatermToggle<CR>
tnoremap <silent> <c-F12> <C-\><C-n>:FloatermToggle<CR>
" -BBye ------------------------
Plug 'moll/vim-bbye'
map <c-k>k :Bdelete!<cr>
command! Clear :%bd!
" -LSP ------------------------
Plug 'neovim/nvim-lspconfig' " Required
Plug 'williamboman/mason.nvim', {'do': ':MasonUpdate'} " Optional
Plug 'williamboman/mason-lspconfig.nvim' " Optional
" -Autocompletion---------------
Plug 'hrsh7th/nvim-cmp' " Required
Plug 'hrsh7th/cmp-nvim-lsp' " Required
Plug 'hrsh7th/cmp-buffer' " Optional
Plug 'hrsh7th/cmp-path' " Optional
"Plug 'saadparwaiz1/cmp_luasnip' " Optional
Plug 'hrsh7th/cmp-nvim-lua' " Optional
" -Snippets----------------------
Plug 'L3MON4D3/LuaSnip' " Required
"Plug 'rafamadriz/friendly-snippets' " Optional
Plug 'VonHeikemen/lsp-zero.nvim', {'branch': 'v1.x'}
" -Telescope---------------------
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'BurntSushi/ripgrep'
Plug 'sharkdp/fd'
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'ryanoasis/vim-devicons'
" -Colorscheme-------------------
Plug 'ewk/blue_in_green'
Plug 'habamax/vim-habamax'
Plug 'Alligator/accent.vim'
Plug 'jacoborus/tender.vim'
Plug 'kxzk/skull-vim'
call plug#end()
" -Keybindings-----------------------------------------------------------------
nmap <c-s> :update<cr> " Save with C-s
nnoremap <esc> :nohlsearch<cr>
" TEXT SELECTION WITH ARROWS
nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
" LINE DRAGGING WITH ALT ARROWS
nnoremap <A-down> :m .+1<CR>==
nnoremap <A-up> :m .-2<CR>==
inoremap <A-down> <Esc>:m .+1<CR>==gi
inoremap <A-up> <Esc>:m .-2<CR>==gi
vnoremap <A-down> :m '>+1<CR>gv=gv
vnoremap <A-up> :m '<-2<CR>gv=gv
" LINE DRAGGING WITH ALT HJKL:
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==gi
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv
" Buffer access
nnoremap <C-k>g :Telescope live_grep<CR>
nnoremap <C-K>s :Telescope lsp_document_symbols<CR>
nnoremap <C-k>b :Telescope buffers<CR>
nnoremap <C-K>f :Telescope find_files<CR>
nnoremap <tab> :buffer *
nnoremap <C-K>h :ClangdSwitchSourceHeader<CR>
" FONT size adjust command
nnoremap <C-Up> :silent! let &guifont = substitute(&guifont, ':h\zs\d\+', '\=eval(submatch(0)+1)', 'g')<CR>
nnoremap <C-Down> :silent! let &guifont = substitute(&guifont, ':h\zs\d\+', '\=eval(submatch(0)-1)', 'g')<CR>
" Toggle completion on/off with F2 key
nnoremap <F2> :call ToggleCompletion()<CR>
let g:nvimCmpEnabled = v:true
function! ToggleCompletion()
if g:nvimCmpEnabled
lua require('cmp').setup{ enabled = false }
let g:nvimCmpEnabled = v:false
else
lua require('cmp').setup{ enabled = true }
let g:nvimCmpEnabled = v:true
endif
call UpdateTitleBar()
endfunction
" Toggle LSP on/off with F2 key
nnoremap <F3> :call ToggleLSP()<CR>
let g:nvimLSPEnabled = v:true
let g:nvimPrevCMPEnabledValue = g:nvimCmpEnabled
function! ToggleLSP()
if g:nvimLSPEnabled
:LspStop
let g:nvimLSPEnabled = v:false
let g:nvimPrevCMPEnabledValue = g:nvimCmpEnabled
let g:nvimCmpEnabled = v:false
else
:LspStart
let g:nvimLSPEnabled = v:true
let g:nvimCmpEnabled = g:nvimPrevCMPEnabledValue
endif
call UpdateTitleBar()
endfunction
" Based on https://coderwall.com/p/usd_cw/a-pretty-vim-foldtext-function
set foldtext=FoldText()
function! FoldText()
" Calculate padding for the fold text
let l:lpadding = &fdc
let l:extra_padding = 0
redir => l:signs
execute 'silent sign place buffer='.bufnr('%')
redir End
let l:lpadding += l:signs =~ 'id=' ? 2 : 0
if exists("+relativenumber")
if (&number)
let l:lpadding += max([&numberwidth, strlen(line('$'))]) + 1
elseif (&relativenumber)
let l:lpadding += max([&numberwidth, strlen(v:foldstart - line('w0')), strlen(line('w$') - v:foldstart), strlen(v:foldstart)]) + 1
endif
else
if (&number)
let l:lpadding += max([&numberwidth, strlen(line('$'))]) + 1
endif
endif
" Calculate the info text (fold size) and its length
let l:info = ' (' . (v:foldend - v:foldstart + 1) . ')'
let l:infolen = strlen(l:info)
" Initialize variables for start and end lines of the fold
let l:start = substitute(getline(v:foldstart), '\t', repeat(' ', &tabstop), 'g')
let l:end = substitute(getline(v:foldend), '\t', repeat(' ', &tabstop), 'g')
let l:custom_fold_display = 0
" Check if the fold starts with "/*" to apply specific formatting
if l:start =~ '^\s*/\*'
" Find the first non-empty line within the fold after the start line
let l:found = ''
for l:line in range(v:foldstart + 1, v:foldend)
let l:current_line = substitute(getline(l:line), '\t', repeat(' ', &tabstop), 'g')
if l:current_line !~ '^\s*$' " Check for a non-empty line
let l:found = l:current_line
break
endif
endfor
" If a non-empty line was found, format it for display
if l:found != ''
" Remove leading "*" if present, along with any leading whitespace
let l:found = substitute(l:found, '^\s*\*\s*', '', '')
" Format the start line to show "/* <first non-empty line> */"
let l:start = '/* ' . l:found . ' */'
let l:end = ''
let l:extra_padding = 2
let l:custom_fold_display = 1
endif
endif
" Calculate the maximum width available for fold text, including padding for `(nn)`
let l:width = winwidth(0) - l:lpadding - l:extra_padding
" Handle fold text formatting separately for custom `/* ... */` folds
if l:custom_fold_display
" Truncate `l:start` to fit within the width, leaving exact space for `(nn)`
let l:width_adjusted = l:width - l:infolen - 1
let l:start = strpart(l:start, 0, l:width_adjusted)
let l:text = l:start
else
" For non-`/* ... */` folds, use the standard "start … end" format
let l:separator = ' … '
let l:separatorlen = strlen(l:separator)
let l:start = strpart(l:start, 0, l:width - l:infolen - l:separatorlen - strlen(l:end) - 1)
let l:text = l:start . l:separator . l:end
endif
" Return the formatted fold text with line count right-aligned
return l:text . repeat(' ', l:width - strlen(l:text) - l:infolen) . l:info
endfunction
" -Building--------------------------------------------------------------------
compiler msvc
function! Build()
:silent make clean
:silent make
:cw
:redraw!
endfunction
function! Clean()
:silent make clean
endfunction
function! SetCMakeMakeprg()
set makeprg=cmake
endfunction
function! SetNMakeMakeprg()
set makeprg=nmake
endfunction
function! SetMakeMakeprg()
set makeprg=make
endfunction
function! Clean()
:silent make clean
endfunction
function! Build()
":silent cmake --build .\build --target clean
:silent make
:silent call ShowBuildOutput()
endfunction
function! Rebuild()
:silent call Clean()
:silent call Build()
endfunction
function! ShowBuildOutput()
:cw
:redraw!
endfunction
call SetMakeMakeprg() " Use Make as default make program
set errorformat+=\\\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m
set errorformat+=,%f:\ error\ %s:%m
set errorformat+=,%f:\ fatal\ error\ %s:%m
autocmd VimResized * :wincmd =
" Rebuild
nmap <F9> :silent call Build()<cr>
nmap <F10> :silent call Rebuild()<cr>
nmap <script> <silent> <F4> :call ToggleQuickfix()<cr>
" Quickfix
function! ToggleQuickfix()
let found = 0
let num_splits = winnr('$')
for i in range(1, num_splits)
let bufnr = winbufnr(i)
if getbufvar(bufnr, '&buftype') ==# 'quickfix'
execute i . 'wincmd w'
Bdelete!
let found = 1
endif
endfor
if (found == 0)
call OpenPrefixWindow()
endif
endfunction
function! OpenPrefixWindow()
"This function opens the Quickfix buffe on the rightmost vertical split.
"If there are less than 3 splis, it will create another one.
"If there are 3 or more, the quickfix window will replace the rightmost existing split
let num_splits = winnr('$')
if num_splits >= 3
execute num_splits . "wincmd w"
wincmd q
endif
vertical copen
wincmd L
wincmd =
endfunction
au QuickFixCmdPost * :call OpenPrefixWindow()
" -TODO extraction-------------------------------------------------------------
function! ExtractTodo()
silent cgete system('todo.bat') | wincmd L
endfunction
silent command! Todo call ExtractTodo()
" -Colorscheme and font--------------------------------------------------------
" Hide split line
function! OnThemeReload()
highlight VertSplit guibg=bg guifg=bg
set fillchars+=vert:\
endfunction
colo simple
"set guifont=FiraCode\ Nerd\ Font:h9
set guifont=Fira\ Code:h9
autocmd ColorScheme * call OnThemeReload()
" -Project file loading--------------------------------------------------------
let g:project#name = ""
let g:vimprj#currentProjectName = ""
function! UpdateTitleBar()
let l:completionStatus = ""
if g:nvimCmpEnabled == v:true
let l:completionStatus = "\t[ 🧩 Autocompletion enabled ]"
endif
if g:nvimLSPEnabled == v:true
let l:completionStatus .= "\t[ 🧩 LSP enabled ]"
endif
let iconList = { 'qf':'🔧', 'help':'🎓', 'netrw':'📁', 'default':'🗒️', '':'❓' }
let icon = iconList["default"]
if has_key(iconList, &filetype)
let icon = iconList[&filetype]
endif
let l:fileName = expand("%t")
if len(l:fileName) == 0
let l:fileName = &filetype
endif
let l:fileName = icon . l:fileName
let &titlestring = g:vimprj#currentProjectName . " :: " . l:fileName . l:completionStatus
endfunction
function! CheckProjectVim()
let file_path = getcwd() . "/project.vim"
if filereadable(file_path)
execute "source" file_path
let g:vimprj#currentProjectName = g:project#name
else
let g:vimprj#currentProjectName = nr2char(0x1F4C1) . getcwd()
endif
call UpdateTitleBar()
endfunction
function! LoadProjectCommand(path)
Clear
execute "cd " . a:path
let sessionFile = a:path . "/Session.vim"
execute "source " . sessionFile
call CheckProjectVim()
endfunction
augroup dirchange
autocmd!
autocmd! dirChanged * call CheckProjectVim()
autocmd BufEnter * call UpdateTitleBar()
augroup END
command! -nargs=1 Project :silent! call LoadProjectCommand(<q-args>)
call CheckProjectVim()
"--Skeleton files -------------------------------------------------------------
function! UpdateSkeletonBuffer(extension)
"Header file
let bufname = substitute(fnamemodify(bufname('%'), ':t'), '[^[:alnum:]]', '_', 'g')
if a:extension == "h"
silent! execute '%s/%header_name%/' . toupper(bufname) . '/g'
let l:namespace = g:project#defaultNamespace
if len(l:namespace) == 0
let l:namespace = "my_name_space"
endif
silent! execute '%s/%namespace%/' . l:namespace . '/g'
if search('%cursor%', 'c') > 0
normal diW
endif
silent! execute '%s/%%/' . g:project#defaultNamespace . '/g'
endif
" set the buffer as modified. We don't want to get confused thinking it's an existing file
call setbufvar(bufnr(), '&modified', 1)
endfunction
augroup skeletons
au!
autocmd BufNewFile *.* silent! execute '0r ~/.vim/templates/skeleton.'.expand("<afile>:e") | call UpdateSkeletonBuffer(expand("<afile>:e"))
autocmd BufNewFile CMakeLists.txt execute '0r ~/.vim/templates/CMakeLists.txt' | call UpdateSkeletonBuffer("<afile>:e")
autocmd BufNewFile project.vim execute '0r ~/.vim/templates/project.vim' | call UpdateSkeletonBuffer("<afile>:e")
augroup END
"--File type autocmd-----------------------------------------------------------
autocmd BufEnter Pass :Bdelete!
autocmd BufEnter *.c setfiletype c
autocmd BufEnter *.cpp setfiletype cpp
autocmd BufEnter *.h setfiletype cpp
autocmd BufEnter *.md setfiletype md
autocmd BufEnter *.xml setfiletype xml
autocmd BufEnter *.json setfiletype json
autocmd BufWritePost *.c setfiletype c
autocmd BufWritePost *.cpp setfiletype cpp
autocmd BufWritePost *.h setfiletype cpp
autocmd BufWritePost *.md setfiletype md
autocmd BufWritePost *.xml setfiletype xml
autocmd BufWritePost *.json setfiletype json
let g:cmp_widget_border = 'rounded'
"--LUA based configurations----------------------------------------------------
lua <<EOF
-- LSP-ZERO
local lsp = require('lsp-zero').preset({
name = 'minimal',
set_lsp_keymaps = true,
manage_nvim_cmp = true,
suggest_lsp_servers = false,
virtual_text = true
})
local cmp = require('cmp')
lsp.setup_nvim_cmp({
mapping = lsp.defaults.cmp_mappings({
-- Do not capture TAB key!
['<Tab>'] = vim.NIL,
})
})
lsp.setup()
vim.diagnostic.config({
-- Use keybinding 'gl' to display diagnostics if this is disabled
virtual_text = false,
signs = true,
update_in_insert = false,
underline = true,
severity_sort = false,
float = true,
})
EOF
" End of vimrc