-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdot_vimrc
More file actions
632 lines (497 loc) · 17.2 KB
/
dot_vimrc
File metadata and controls
632 lines (497 loc) · 17.2 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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
" Use different vim runtime based on whether we're on remote (SSH) or local
if $IS_SSH == '1'
" Remote: use minimal SSH-friendly vim config
let s:vimruntime = expand('~/.ssh-dotfiles/.vim')
else
" Local: use full vim config
let s:vimruntime = expand('~/.vim')
endif
if isdirectory(s:vimruntime)
" Clear default vim paths to avoid duplicates
set runtimepath-=~/.vim
set runtimepath-=~/.vim/after
set packpath-=~/.vim
set packpath-=~/.vim/after
" Add our chosen runtime path
execute 'set runtimepath^=' . s:vimruntime
execute 'set packpath^=' . s:vimruntime
" Load plugins
execute 'packloadall'
endif
" autocmd to add commentstring for filetypes not already supported by `vim-commentary`
" autocmd FileType python setlocal commentstring=#\ %s
" Disable terminal flow control in Vim (prevents Ctrl-S from freezing)
silent! execute "!stty -ixon"
autocmd VimLeave * silent! execute "!stty ixon"
" Fix term bg color in Vim bug: https://www.reddit.com/r/vim/comments/o9irr1/terminal_background_overrides_nontext_vim/
let &t_ut=''
colorscheme catppuccin_mocha_compat
if has("termguicolors")
" Required for catppuccin themes
set termguicolors
colorscheme catppuccin_mocha
endif
" Set so we can yank from SSH remote to our local
" We must select w/ mouse and not visual
set clipboard=unnamedplus
" Mouse support must also be turned off so that selection is made in the term
" not in vim
" When doing this, we can `:set nonum` for cleaner multi-line copying
set mouse=
" Airline config (statusline and tabline)
let g:airline#extensions#tabline#enabled = 1
let g:airline_theme='catppuccin_mocha'
" GUI config
" Change cursor shape on insert mode
let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
" reset the cursor on start (for older versions of vim, usually not required)
augroup myCmds
au!
autocmd VimEnter * silent !echo -ne "\e[2 q"
augroup END
syntax on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" ██╗ ██╗██╗███╗ ███╗██████╗ ██████╗
" ██║ ██║██║████╗ ████║██╔══██╗██╔════╝
" ██║ ██║██║██╔████╔██║██████╔╝██║
" ╚██╗ ██╔╝██║██║╚██╔╝██║██╔══██╗██║
" ╚████╔╝ ██║██║ ╚═╝ ██║██║ ██║╚██████╗
" ╚═══╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"------------------SETTINGS------------------
set autoread " detect when a file has been modified externally
set autoindent " Use current indent for new lines.
set smartindent
" set ruler " Show the ruler in the statusline.
set hidden " stops vim asking to save the file when switching buffer.
set scrolloff=8 " scroll page when cursor is 8 lines from top/bottom
set splitbelow " split go below
set splitright " vertical split to the right
set expandtab " expand tab to spaces so that tabs are spaces
" Disable compatibility with vi which can cause unexpected issues.
set nocompatible
" Disable the vim bell (disable flash at EOF)
" set visualbell
set t_vb=
" Disable auto commenting in a new line
autocmd Filetype * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" Setting the character encoding of Vim to UTF-8
set encoding=UTF-8
" Enable type file detection. Vim will be able to try to detect the type of file is use.
filetype on
" Enable spell check
" set spell
" Smart tab
set smarttab
" Search down to subfolders
set path+=**
" Enable plugins and load plugin for the detected file type.
filetype plugin on
" Load an indent file for the detected file type.
filetype indent on
" Turn syntax highlighting on.
syntax on
" Add numbers to the file.
set number relativenumber
" Mouse functionality
" set mouse=a
" Color scheme
" colorscheme slate
" Highlight cursor line underneath the cursor horizontally.
set cursorline
" Highlight cursor line underneath the cursor vertically.
" set cursorcolumn
" Set shift width to 4 spaces.Set tab width to 4 columns.
set shiftwidth=4
set tabstop=4
" Better whitespace visualization (only show trailing spaces and nbsp, not tabs)
set nolist
set listchars=trail:-,nbsp:·
" Better wrapping behavior
set linebreak
set breakindent
set breakindentopt=shift:2,min:20
" Minimal window heights (better splits)
set winheight=1
set winminheight=1
" Hide mouse while typing
set mousehide
" Include hyphen in keywords (useful for CSS, HTML)
set iskeyword+=-
" If the current file type is HTML, set indentation to 2 spaces.
autocmd Filetype html setlocal tabstop=2 shiftwidth=2 expandtab
autocmd Filetype markdown setlocal tabstop=2 shiftwidth=2 expandtab
" Do not save backup files.
set nobackup
" Do wrap lines.
set wrap
" While searching though a file incrementally highlight matching characters as you type.
set incsearch
set hlsearch
" Ignore capital letters during search.
set ignorecase
set smartcase
" Show partial command you type in the last line of the screen.
set showcmd
" Show the mode you are on the last line.
" set showmode
" Show matching words during a search.
set showmatch
" Set the commands to save in history default number is 20.
set history=1000
" Setting the split window to open as i like (like in a WM - qtile)
set splitbelow splitright
" Enable auto completion menu after pressing TAB.
set wildmenu
" There are certain files that we would never want to edit with Vim.
" Wild menu will ignore files with these extensions.
set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx
" If Vim version is equal to or greater than 7.3 enable undo file.
" This allows you to undo changes to a file even after saving it.
if version >= 703
set undodir=~/.vim/backup
set undofile
set undoreload=10000
endif
" File Browsing settings (netrw - no plugins needed!)
let g:netrw_banner=0 " Hide banner
let g:netrw_liststyle=3 " Tree view
let g:netrw_showhide=1 " Show hidden files
let g:netrw_winsize=30 " Width when opened in vsplit
let g:netrw_browse_split=4 " Open files in previous window (not in netrw window)
let g:netrw_altv=1 " Open vsplit to the right
let g:netrw_keepdir=0 " Keep current directory in sync with browsing
" Simple - keybinding to open netrw (like vinegar's '-' but better)
nnoremap - :Lex<CR>
" Auto Completion - Enable Omni complete features
set omnifunc=syntaxcomplete#Complete
" Enable Spelling Suggestions for Auto-Completion:
set complete+=k
set completeopt=menu,menuone,noinsert
" Minimalist-Tab Complete
inoremap <expr> <Tab> TabComplete()
fun! TabComplete()
if getline('.')[col('.') - 2] =~ '\K' || pumvisible()
return "\<C-N>"
else
return "\<Tab>"
endif
endfun
" Minimalist-Autocomplete
inoremap <expr> <CR> pumvisible() ? "\<C-Y>" : "\<CR>"
autocmd InsertCharPre * call AutoComplete()
fun! AutoComplete()
if v:char =~ '\K'
\ && getline('.')[col('.') - 4] !~ '\K'
\ && getline('.')[col('.') - 3] =~ '\K'
\ && getline('.')[col('.') - 2] =~ '\K' " last char
\ && getline('.')[col('.') - 1] !~ '\K'
call feedkeys("\<C-N>", 'n')
end
endfun
" Closing compaction in insert mode
inoremap [ []<left>
inoremap ( ()<left>
inoremap { {}<left>
inoremap /* /**/<left><left>
"------------------STATUS_LINE------------------
" Status line
" set laststatus=2
" set statusline=
" set statusline+=%2*
" set statusline+=%{StatuslineMode()}
" set statusline+=\
" set statusline+=%{SpellCheckStatus()}
" set statusline+=%1*
" set statusline+=\
" set statusline+=%3*
" set statusline+=<
" set statusline+=-
" set statusline+=\
" set statusline+=%f
" set statusline+=\
" set statusline+=-
" set statusline+=>
" set statusline+=\
" set statusline+=%4*
" set statusline+=%m
" set statusline+=%=
" set statusline+=%h
" set statusline+=%r
" set statusline+=%4*
" set statusline+=%c
" set statusline+=/
" set statusline+=%l
" set statusline+=/
" set statusline+=%L
" set statusline+=\
" set statusline+=%1*
" set statusline+=|
" set statusline+=%y
" set statusline+=\
" set statusline+=%4*
" set statusline+=%P
" set statusline+=\
" set statusline+=%3*
" set statusline+=t:
" set statusline+=%n
" set statusline+=\
" " Colors
" hi User2 ctermbg=lightgreen ctermfg=black guibg=lightgreen guifg=black
" hi User1 ctermbg=brown ctermfg=white guibg=black guifg=white
" hi User3 ctermbg=brown ctermfg=lightcyan guibg=black guifg=lightblue
" hi User4 ctermbg=brown ctermfg=green guibg=black guifg=lightgreen
" Mode
" function! StatuslineMode()
" let l:mode=mode()
" if l:mode==#"n"
" return "NORMAL"
" elseif l:mode==#"V"
" return "VISUAL LINE"
" elseif l:mode==?"v"
" return "VISUAL"
" elseif l:mode==#"i"
" return "INSERT"
" elseif l:mode ==# "\<C-V>"
" return "V-BLOCK"
" elseif l:mode==#"R"
" return "REPLACE"
" elseif l:mode==?"s"
" return "SELECT"
" elseif l:mode==#"t"
" return "TERMINAL"
" elseif l:mode==#"c"
" return "COMMAND"
" elseif l:mode==#"!"
" return "SHELL"
" else
" return "VIM"
" endif
" endfunction
"
"
" " Spell Check Status
" function! SpellCheckStatus()
" if &spell
" return " [SPELL]"
" else
" return ''
" endif
" endfunction
"------------------KEY_BINDINGS------------------
" Spell-check on\off
" map <C-z> :setlocal spell! spelllang=en_us<CR>
" Type jj to exit insert mode quickly.
" inoremap jj <Esc>
" Format a paragraph into lines
" map Q gq<CR>
" Set the comma as the leader key and space as local leader
let mapleader = ","
let maplocalleader = ' '
noremap <space> <Nop>
" Select all the text
nnoremap <leader>ya ggVGy
" File explorer (netrw)
" Toggle netrw sidebar on left (Lex = Lexplore)
nnoremap <leader>e :Lex<CR>
" Open in current window
nnoremap <leader>E :Explore<CR>
" " Opening a terminal window
" map <c-/> :ter<CR>
" " Closing the terminal window
" if v:version >= 800
" tnoremap <c-t> exit<CR>
" endif
" " CTRL+I OR Esc to make the terminal scrollable and I to input mode
" tnoremap <c-i> <c-w><s-n>
" tnoremap <Esc> <C-\><C-n>
" Switch buffers with H/L
nnoremap H :bprev<CR>
nnoremap L :bnext<CR>
" You can split the window in Vim. y - in the y access , x - in the x access
map <leader>ws :split<CR>
map <leader>wv :vsplit<CR>
" Navigate the split view easier by pressing CTRL+j, CTRL+k, CTRL+h, or CTRL+l.
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" Alternative leader-based window navigation (always works)
nnoremap <leader>wj <c-w>j
nnoremap <leader>wk <c-w>k
nnoremap <leader>wh <c-w>h
nnoremap <leader>wl <c-w>l
" Ensure Ctrl-h/l work in netrw buffers
augroup netrw_mapping
autocmd!
autocmd FileType netrw nnoremap <buffer> <c-h> <c-w>h
autocmd FileType netrw nnoremap <buffer> <c-l> <c-w>l
augroup END
" Delete window buffer
map <leader>wd :q<CR>
" Delete buffer
map <leader>bd :bd<CR>
nnoremap <C-q> :bd<CR>
" Resize split windows using arrow keys by pressing:
" CTRL+UP, CTRL+DOWN, CTRL+LEFT, or CTRL+RIGHT.
noremap <a-up> <c-w>+
noremap <a-down> <c-w>-
noremap <a-left> <c-w>>
noremap <a-right> <c-w><
" Moving between tabs
" map <leader>t gt
" Opening\Creating a file in a new tab - write the tab to open
nnoremap <leader>c :tabedit<space>
" Saving a file using CTRL+S
nnoremap <C-s> :w<CR>
inoremap <C-s> <Esc>:w<CR>
vnoremap <C-s> <Esc>:w<CR>
" Quitting and saving a file using CTRL+S
" map <C-q> :wq<CR>
" Quit all
map <leader>qq :qa!<CR>
" Surround word with a wanted character
nnoremap <leader>sw <cmd>echo "Press a character: " \| let c = nr2char(getchar()) \| exec "normal viwo\ei" . c . "\eea" . c . "\e" \| redraw<CR>
" Replace all occurrences of a word
nnoremap <leader>rw :%s/\<<c-r><c-w>\>//g<left><left>
" Map V-Block to not confuse with Past
" noremap <leader>v <C-v>
" For copy and past
" map <C-V> "+P
" vnoremap <C-C> "*y :let @+=@*<CR>
" If not in Linux replace the keybinding in above line with: vnoremap <C-C> "+y
" Seeing the registers
nnoremap <leader>" <cmd>registers<CR>
" Moving lines in visual mode
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '>-2<CR>gv=gv
" Wrap-aware movement (move on display lines)
nnoremap ^ g^
nnoremap $ g$
xnoremap ^ g^
xnoremap $ g$
" " Smart dd - don't yank empty lines to register
" nnoremap <expr> dd (getline('.')=~'^\s*$')?'"_dd':'dd'
"
" " Toggle center-cursor mode (scrolloff 999 vs 8)
" nnoremap <C-g> :set scrolloff=<C-r>=&scrolloff==999?8:999<CR><CR>
" Tab navigation
nnoremap ]<tab> :tabnext<CR>
nnoremap [<tab> :tabprevious<CR>
" " Clear quickfix list
" nnoremap <leader>xc :call setqflist([])<CR>
" Unbind Ctrl-Z (suspend) - annoying in SSH
noremap! <C-z> <Nop>
"------------------PLUGIN_CONFIG------------------
" vim-which-key configuration
" Enable which-key for leader and localleader
nnoremap <silent> <leader> :<c-u>WhichKey ','<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual ','<CR>
vnoremap <silent> <localleader> :<c-u>WhichKeyVisual '<Space>'<CR>
set timeoutlen=250
" CtrlP configuration (fuzzy finder - no external binary needed)
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'ra' " Start from repo root
let g:ctrlp_show_hidden = 1
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](\.(git|hg|svn)|node_modules|target|dist|build)$',
\ 'file': '\v\.(exe|so|dll|pyc|swp)$',
\ }
" Use ripgrep if available (faster)
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg --files --hidden --glob "!.git/*" %s'
let g:ctrlp_use_caching = 0
endif
" vim-commentary configuration
" Cmd-/ for commenting (works in terminals that support <D-/>)
" This requires terminal support - works in Ghostty, Kitty, WezTerm
" For terminals without Cmd support, use gcc in normal mode or gc in visual
autocmd FileType python setlocal commentstring=#\ %s
autocmd FileType bash,sh setlocal commentstring=#\ %s
autocmd FileType fish setlocal commentstring=#\ %s
autocmd FileType lua setlocal commentstring=--\ %s
autocmd FileType javascript,typescript setlocal commentstring=//\ %s
"------------------PLUGIN_KEYBINDINGS------------------
" CtrlP (fuzzy finder - pure vimscript, no dependencies!)
" Leader-space for find files (matches nvim)
nnoremap <leader><space> :CtrlP<CR>
nnoremap <leader>ff :CtrlP<CR>
nnoremap <leader>fb :CtrlPBuffer<CR>
nnoremap <leader>fm :CtrlPMRU<CR>
nnoremap <leader>fl :CtrlPLine<CR>
" Ctrl-P also works
nnoremap <C-p> :CtrlP<CR>
" Grep functionality (leader-/ matches nvim)
" Configure grep to use ripgrep if available
" if executable('rg')
" set grepprg=rg\ --vimgrep\ --smart-case\ --hidden\ --glob\ '!.git'
" set grepformat=%f:%l:%c:%m
" " Leader-/ to grep across all files
" nnoremap <leader>/ :grep<Space>
" " Search for word under cursor across all files
" nnoremap <leader>* :grep "\b<C-R><C-W>\b"<CR>:copen<CR>
" else
" set grepprg=grep\ -rn\ $*\ .
" nnoremap <leader>/ :grep<Space>
" nnoremap <leader>* :grep -r "\b<C-R><C-W>\b" .<CR>:copen<CR>
" endif
" Open/close quickfix (grep results)
nnoremap <leader>qo :copen<CR>
nnoremap <leader>qc :cclose<CR>
" vim-commentary (commenting)
" gcc - Toggle comment on current line
" gc{motion} - Comment motion (e.g. gcap for paragraph)
" gc in visual mode - Comment selection
" Cmd-/ for terminal emulators that support it (Ghostty, Kitty)
" nnoremap <D-/> gcc
" xnoremap <D-/> gc
" inoremap <D-/> <Esc>gcc
" vim-fugitive (git integration)
nnoremap <leader>gg :Git<CR>
nnoremap <leader>gd :Gdiffsplit<CR>
nnoremap <leader>gc :Git commit<CR>
nnoremap <leader>gb :Git blame<CR>
nnoremap <leader>gl :Git log<CR>
nnoremap <leader>gp :Git push<CR>
nnoremap <leader>gP :Git pull<CR>
"------------------CUSTOM_FUNCTIONS------------------
" Delete mark on current line
function! DeleteCurrentLineMark()
let line = line('.')
let marks = 'abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
for mark in split(marks, '\zs')
let pos = getpos("'" . mark)
if pos[1] == line
execute 'delmarks ' . mark
echom 'Deleted mark ' . mark
return
endif
endfor
echom 'No mark found on current line.'
endfunction
nnoremap <leader>'d :call DeleteCurrentLineMark()<CR>
nnoremap <leader>'f :delmarks a-z<CR>
nnoremap <leader>'g :delmarks A-Z<CR>
" Remove item from quickfix list with dd
function! RemoveQFItem()
let idx = line('.') - 1
let qf = getqflist()
if idx < len(qf)
call remove(qf, idx)
call setqflist(qf, 'r')
if len(qf) == 0 | cclose | endif
endif
endfunction
autocmd FileType qf nnoremap <buffer> dd :call RemoveQFItem()<CR>
"------------------AUTOCOMMANDS------------------
" Trim trailing whitespace on save
autocmd BufWritePre * %s/\s\+$//e
" Help windows open in vertical split
autocmd BufWinEnter * if &buftype == 'help' | wincmd L | endif
"------------------END_KEY------------------