-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
513 lines (406 loc) · 14.4 KB
/
vimrc
File metadata and controls
513 lines (406 loc) · 14.4 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
" ==========================================================
" GLOBAL DEFINITIONS
" ==========================================================
let mapleader = "\\"
set number " Show the current line number
set relativenumber " Show distance to other lines
" desable vi
set nocompatible
" no sounds or flashes on errors!
set novisualbell
set noerrorbells
set t_vb=
set belloff=all
" This clears all values for selectmode. Vim has a "Select mode"
" that behaves like a modern word processor (typing replaces text).
" By setting it to empty, you ensure Vim stays in its native
" "Visual mode" when highlighting tex
set selectmode=
" Enable mouse support in all modes (allows scrolling)
set mouse=a
set foldlevel=99
set cursorline
highlight CursorLine ctermbg=darkgray cterm=none
autocmd BufWinLeave * silent! mkview
autocmd BufWinEnter * silent! loadview
set autoread
" Optional: Force built-in 'new' to be vertical
cabbrev new vnew
" Repo root — derived from the real location of this file so it works
" regardless of where the repo is cloned.
let g:vimfiles_dir = fnamemodify(resolve(expand('$MYVIMRC')), ':h')
" ==========================================================
" PLUGIN MANAGEMENT
" ==========================================================
" Configs are in the section 'Plugin Specific Config'
call plug#begin('~/.vim/plugged')
" The best plugin for Go development
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" Optional: For VS Code-like autocomplete menus
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" add comment for all langs
Plug 'tpope/vim-commentary'
" Make braces, brackets, etc open a new empty line
Plug 'jiangmiao/auto-pairs'
Plug 'ludovicchabant/vim-gutentags'
Plug 'puremourning/vimspector'
Plug 'pseewald/vim-anyfold'
Plug 'Konfekt/FastFold'
Plug 'tomasr/molokai'
call plug#end()
" ==========================================================
" GENERAL UI/UX
" ==========================================================
" Key bindings are in the section 'Global Keymaps'
syntax on
filetype plugin indent on
set termguicolors
set background=dark
colorscheme molokai
set tabstop=4
" How many columns an 'indent level' is worth
set shiftwidth=4
" Keep tabs as tabs (Required for Go)
set noexpandtab
set smartindent
set hlsearch
set incsearch
set backspace=indent,eol,start
" Always show the status line, even with only one window
set laststatus=2
" Custom statusline format
set statusline=%f\ %m\ %r%=%y\ [%p%%]\ %l:%c
highlight StatusLine ctermbg=white ctermfg=black
set showcmd
" make vertical the default for split view
set diffopt+=vertical
" Always open new window to the left
autocmd WinNew * wincmd H
set nosplitright
" This tells Vim to wait only 10ms for the rest of an escape sequence
set ttimeoutlen=10
set colorcolumn=111
autocmd Filetype * AnyFoldActivate
" Portable Cursor Shape (WSL & Linux)
" Uses 2 for Block, 4 for Underline, 6 for Beam (Steady variants)
if &term =~ 'xterm' || &term =~ 'screen' || &term =~ '256color'
let &t_SI = "\<Esc>[6 q" " Insert mode: steady beam
let &t_SR = "\<Esc>[4 q" " Replace mode: steady underline
let &t_EI = "\<Esc>[2 q" " Normal mode: steady block
endif
" ==========================================================
" PLUGIN SPECIFIC CONFIG
" ==========================================================
let g:coc_global_extensions =
\[
\ 'coc-go', 'coc-json', 'coc-sql',
\ 'coc-sh', 'coc-tag', 'coc-clangd',
\ 'coc-markdownlint', 'coc-prettier',
\ '@yaegassy/coc-marksman', 'coc-pyright'
\]
" This sets semantic completion as priority and tags as low-priority fallback
let g:coc_user_config = {
\ "coc.preferences.formatOnSaveFiletypes": ["*"],
\
\ "suggest.enablePreview": v:true,
\ "diagnostic.enableSign": v:true,
\ "diagnostic.errorSign": "✖",
\ "diagnostic.warningSign": "⚠",
\ "diagnostic.infoSign": "ℹ",
\ "inlayHint.enable": v:true,
\ "suggest.languageSourcePriority": 99,
\ "coc.source.tag.priority": 1,
\ "coc.source.tag.shortcut": "TAG",
\ "suggest.lowPrioritySourceLimit": 5,
\
\ "prettier.printWidth": 110,
\ "prettier.tabWidth": 4,
\ "prettier.useTabs": v:true,
\ "prettier.proseWrap": "always",
\ "prettier.endOfLine": "lf",
\ "prettier.trailingComma": "es5",
\ "prettier.singleQuote": v:false,
\ "prettier.requireConfig": v:false,
\ "prettier.disableLanguages": ["markdown"],
\
\ "markdownlint.onOpen": v:true,
\ "markdownlint.onChange": v:true,
\ "markdownlint.onSave": v:true,
\ "markdownlint.config": {
\ "default": v:true,
\ "MD033": { "allowed_elements": ["details", "summary", "b"] },
\ "MD013": { "line_length": 110, "tables": v:false, "code_blocks": v:false },
\ "MD024": { "siblings_only": v:true },
\ "MD029": { "style": "ordered" },
\ "MD046": { "style": "fenced" },
\ "list-marker-space": { "ul_multi": 1, "ul_single": 1 },
\ "ul-indent": { "indent": 4 }
\ },
\
\ "marksman.enable": v:true,
\ "marksman.maxNumberOfProblems": 100,
\
\ "python.analysis.typeCheckingMode": "strict",
\ "python.analysis.autoImportCompletions": v:true,
\ "python.analysis.diagnosticMode": "workspace",
\ "python.analysis.inlayHints.variableTypes": v:true,
\ "python.analysis.inlayHints.functionReturnTypes": v:true,
\ "python.formatting.provider": "black",
\ "python.formatting.blackPath": "black",
\ "python.analysis.diagnosticSeverityOverrides": {
\ "reportMissingTypeStubs": "none",
\ "reportUnknownMemberType": "none"
\ },
\
\ "go.goplsOptions": {
\ "completeUnimported": v:true,
\ "usePlaceholders": v:true,
\ "staticcheck": v:true,
\ "analyses": {
\ "unusedparams": v:true,
\ "shadow": v:true,
\ "unusedwrite": v:true,
\ "useany": v:true
\ }
\ },
\
\ "bashIde.shellcheckPath": "shellcheck",
\ "bashIde.shellcheckArguments": "--severity=warning",
\ "bashIde.globPattern": "**/*@(.sh|.inc|.bash|.command)",
\ "bashIde.backgroundAnalysisMaxFiles": 500,
\
\ "json.format.enable": v:true,
\ "json.validate.enable": v:true,
\ "json.schemas": [
\ {
\ "fileMatch": [".vimspector.json"],
\ "url": "https://puremourning.github.io/vimspector/schema/vimspector.schema.json"
\ }
\ ],
\ }
" Use Tab to confirm the selection when the menu is visible
inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<TAB>"
" --- Vim-Go Settings ---
let g:go_metalinter_autosave = 1 " Run error checking on save
let g:go_highlight_functions = 1 " Enhanced syntax highlighting for Go
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_types = 1
" Ensure Vimspector is available
if empty(glob('~/.vim/plugged/vimspector'))
echo "Vimspector not found. Run :PlugInstall first."
endif
" Put tags(from Gutentags) and vimspector.json in a global gitignore
" This runs only once if the global ignore file is missing
if executable('git') && empty(glob('~/.gitignore_global'))
silent !touch ~/.gitignore_global
silent !echo "tags" >> ~/.gitignore_global
silent !echo "tags.lock" >> ~/.gitignore_global
silent !echo ".vimspector.json" >> ~/.gitignore_global
silent !git config --global core.excludesfile ~/.gitignore_global
redraw!
echo "Global .gitignore created and configured."
endif
" Debbuger mappings
" Toggle breakpoint
nnoremap <leader>gb :call vimspector#ToggleBreakpoint()<CR>
" Continue / Start
nnoremap <leader>gc :call vimspector#Continue()<CR>
" Stop
nnoremap <leader>gs :call vimspector#Stop()<CR>
" Restart
nnoremap <leader>gr :call vimspector#Restart()<CR>
" Step Over
nnoremap <leader>gn :call vimspector#StepOver()<CR>
" Step Into
nnoremap <leader>gi :call vimspector#StepInto()<CR>
" Step Out
nnoremap <leader>go :call vimspector#StepOut()<CR>
" Reset
nnoremap <leader>gq :VimspectorReset!<CR>
" --- Navigation ---
" Jump to definition
nmap <silent> <leader>d <Plug>(coc-definition)
" Back from definition
nnoremap <leader>b <C-o>
" Open a hover block with definition
nnoremap <leader>o :call CocActionAsync('doHover')<CR>
nmap <leader>ca <Plug>(coc-codeaction)
nmap <leader>rn <Plug>(coc-rename)
"
" Navigation for CoC diagnostics (errors/warnings)
nmap <silent> <leader>cp <Plug>(coc-diagnostic-prev)
nmap <silent> <leader>cn <Plug>(coc-diagnostic-next)
" Find references
nmap <silent> <leader>fr <Plug>(coc-references)
" ==========================================================
" GLOBAL KEYMAPS
" ==========================================================
" Fast mapping for vertical split + file path
nnoremap <leader>nf :topleft vertical split<Space>
" Clear search highlighting. remap <Esc> to <Esc><Esc> to make it faster
nnoremap <Esc><Esc> :noh<CR>
" Window Navigation(normal and terminal mode)
nnoremap <leader>h <C-w>h
nnoremap <leader>j <C-w>j
nnoremap <leader>k <C-w>k
nnoremap <leader>l <C-w>l
tnoremap <leader>h <C-\><C-n><C-w>h
tnoremap <leader>j <C-\><C-n><C-w>j
tnoremap <leader>k <C-\><C-n><C-w>k
tnoremap <leader>l <C-\><C-n><C-w>l
" + and - now resize the window
nnoremap <silent> + :vertical resize +5<CR>
nnoremap <silent> - :vertical resize -5<CR>
" Map mouse wheel to scroll the window view (allows scrolling past EOF)
nnoremap <ScrollWheelUp> <C-y>
nnoremap <ScrollWheelDown> <C-e>
" Native jumps center automatically
nnoremap G Gzz
nnoremap n nzz
nnoremap N Nzz
" Center screen when moving up and down
nnoremap j gjzz
nnoremap k gkzz
" Reload your config
nnoremap <leader>v :source $MYVIMRC<CR>
" toggle between current and last file open
nnoremap <leader>tf <C-^>
" Map dd to not delete the line, jsut its contents.
" To delete line i made a new command
nnoremap dd 0D
nnoremap dl dd
" to create new lines in normal mode and stay there
nnoremap <space>j o<Esc>
nnoremap <space>k O<Esc>
" Normal mode: move current line
nnoremap <C-k> :m .-2<CR>==
nnoremap <C-j> :m .+1<CR>==
" Visual mode: move selected block
vnoremap <C-k> :m '<-2<CR>gv=gv
vnoremap <C-j> :m '>+1<CR>gv=gv
" Map qq to <Esc> in insert mode
inoremap qq <Esc>
" jump to beginning/end of line in insert mode
inoremap II <C-o>I
inoremap <leader>I II
inoremap AA <C-o>A
inoremap <leader>A AA
" Open netrw
nnoremap <leader>ft :Vex<CR>
tnoremap <Esc><Esc> <C-\><C-n>
nnoremap <leader>w :w<CR>
" some language shortcuts:
" C / C++
inoremap ;; <Esc>g_a;
" append ; at end of line
inoremap <leader>s std::
" append { at end of line
inoremap {{ <Esc>g_a{}<Esc>ha
" insert , after next character
inoremap ,, <Esc>la,
" Python
" append : at end of line
inoremap :: <Esc>g_a:
" ==========================================================
" LANGUAGE SPECIFIC CONFIG
" ==========================================================
" ----------------- Go Language Config ---------------------
" \r to Run, \t to Test
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
" Go uses real tabs, not spaces
" autocmd FileType go setlocal noexpandtab shiftwidth=4 tabstop=4
" Disable your manual autocmd to prevent conflicts with vim-go's autosave
" autocmd BufWritePost *.go silent !go fmt %
" --------------- Python Language Config -------------------
autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=4
autocmd FileType python nmap <leader>r :terminal python3 %<CR>
" ------------------ C Language Config ---------------------
autocmd FileType c nmap <leader>r :terminal gcc % -o /tmp/vimrun && /tmp/vimrun<CR>
" ---------------- C++ Language Config --------------------
autocmd FileType cpp nmap <leader>r :terminal g++ % -o /tmp/vimrun && /tmp/vimrun<CR>
" ------------------ Shell Language Config -----------------
autocmd FileType sh nmap <leader>r :terminal bash %<CR>
augroup ShebangDetect
autocmd!
autocmd BufWinEnter,BufWritePost,InsertLeave *
\ if getline(1) =~# '^#!' |
\ filetype detect |
\ endif
augroup END
" -------------- Markdown Language Config -------------------
autocmd FileType markdown nmap <leader>mp :terminal glow %<CR>
" command! Preview if &filetype ==# 'markdown' | terminal glow %
" \| else | echo "Preview is only available for markdown files" | endif
command! Preview if &filetype ==# 'markdown' |
\ execute "vertical topleft terminal glow " . expand("%") |
\ else | echo "Preview is only available for markdown files" | endif
" ==========================================================
" CUSTOM COMMANDS
" ==========================================================
" Format the current buffer
command! -nargs=0 Format :call CocActionAsync('format')
command! Shortcuts execute 'vsplit +setlocal\ readonly\ nomodifiable ' . g:vimfiles_dir . '/shortcuts.txt'
" Reload your config
command! Source source $MYVIMRC
" To config and install a debbuger(binaries must be available)
function! InstallDebugger(adapter)
if a:adapter == ''
echo "Usage: :InstallDebugger <adapter_name>"
return
endif
execute 'VimspectorInstall ' . a:adapter
let l:filetypes = {
\ 'delve': ['go'],
\ 'debugpy': ['python'],
\ 'CodeLLDB': ['c', 'cpp'],
\ 'vscode-bash-debug': ['sh'],
\ }
if has_key(l:filetypes, a:adapter)
let l:ft = l:filetypes[a:adapter]
else
let l:input = input("Enter filetypes for '" . a:adapter . "' (comma-separated, e.g. go,python): ")
let l:ft = split(l:input, '\s*,\s*')
endif
let l:new_entry = {
\ 'adapter': a:adapter,
\ 'filetypes': l:ft,
\ 'configuration': {
\ 'request': 'launch',
\ 'program': '${program}',
\ 'args': [],
\ 'cwd': '${workspaceRoot}',
\ 'mode': 'debug',
\ 'env': {},
\ }
\ }
if !filereadable('.vimspector.json')
let l:vimspector = {'configurations': {a:adapter: l:new_entry}}
echo "Created .vimspector.json with '" . a:adapter . "' configuration."
else
let l:content = join(readfile('.vimspector.json'), "\n")
let l:vimspector = json_decode(l:content)
if has_key(l:vimspector.configurations, a:adapter)
echo "Configuration for '" . a:adapter . "' already exists."
return
endif
let l:vimspector.configurations[a:adapter] = l:new_entry
echo "Added '" . a:adapter . "' to existing .vimspector.json."
endif
call writefile([json_encode(l:vimspector)], '.vimspector.json')
endfunction
command! -nargs=1 InstallDebugger call InstallDebugger(<f-args>)
"
" sometimes I make w and q upercase. Now they(and variations) map to the correct command
command! W :w
command! Q :q
command! Qa :qa
command! QA :qa
cabbrev <expr> Q! getcmdtype()==':' && getcmdline()=='Q!' ? 'q!' : 'Q!'
command! Wq :wq
command! Wa :wa
command! Wqa :wqa
command! WQa :wqa
command! WQA :wqa