-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
663 lines (548 loc) · 21 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
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
" --------------
" VIMRC CONTENTS
" --------------
" 01. _EDITOR_CONFIGS_
" 02. _PLUGINS_
" 03. _PLUGIN_SETTINGS_
" 04. _FUNCTIONS_
" 05. _KEYBINDINGS_
" 06. _LATE_IMPORTS_
" ------------------
" # _EDITOR_CONFIGS_
" ------------------
" Set leader keys (must be on top because plugins use it)
let mapleader="\<Space>"
let maplocalleader = ","
" ## Set .config dir to use based on editor (vim vs nvim)
if !has('nvim')
let s:config_dir = $HOME . "/.vim"
else
let s:config_dir = $HOME . "/.config/nvim"
endif
" ## General options
set novisualbell " Disable screen flashes
set encoding=UTF-8 " Set character encoding
set timeoutlen=800 " Shrink the window for time-outable commands
set nofoldenable " Start with all folds open
set mouse=nvchr " Enable mouse for all modes except insert mode
set scrolloff=4 " Set number of screen lines to always keep above and below the cursor
set undofile " Enable undo history
if !isdirectory(s:config_dir . "/undodir")
:call mkdir(s:config_dir . "/undodir")
endif
let &undodir = s:config_dir . "/undodir" " Select the directory to keep undofiles
set splitright " Open vertical splits to right
set splitbelow " Open horizontal splits to below
set conceallevel=0 " Do not conceal text (e.g. Neorg symbols)
set ignorecase " By default ignore case when searching
set smartcase " If intentionally uppercase letters are used in search then override ignorecase
set hlsearch " Keep search highlight
set list " Show whitespace characters
set showcmd " show keypresses in status line
augroup editor_configs
autocmd!
" Do not continue newlines with comment character
autocmd FileType * setlocal formatoptions-=cro
" Set width to break lines
autocmd FileType * setlocal textwidth=120
" Set in which file types should lines auto break
autocmd FileType norg setlocal fo+=t
autocmd FileType toml setlocal fo-=t
" Set the filetype based on the file extension, overriding any
" 'filetype' that has already been set
autocmd BufRead,BufNewFile *.launch set filetype=xml
" Set which files will use highlight from start of file (fix for Javascript
" inside HTML syntax)
autocmd BufRead,BufNewFile *.html syntax sync fromstart
augroup END
" ## Colors
set termguicolors " enable true-color support
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum" " set foreground color
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" " set background color
set background=dark
" ## Line numbers
set relativenumber
set number
set nocursorline
set nocursorcolumn
" ## Whitespace settings
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set smartindent
" ### Set language-specific indendation
augroup lang_indentation_by_filetype
autocmd!
autocmd Filetype css,scss,javascript,typescript,html,json,xml,norg,cmake
\ setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd Filetype meson
\ setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd BufRead,BufNewFile *.html setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
augroup END
" ## Visual settings
set showtabline=2 " Always show tab line
" ## Configs recommended by CoC
set hidden
set updatetime=300
set nobackup " Disable backup files
set nowritebackup " Disable backup files
set shortmess+=c " Disable hit ENTER prompts for completion
set signcolumn=yes " Always show sign column, otherwise it will shift text
" ## Commands
command! V e $MYVIMRC | cd %:h
" -----------
" # _PLUGINS_
" -----------
" 1. Download plug.vim and put it in ~/.vim/autoload
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" 2. Download plugins with :PlugInstall
" 3. Downloaded plugins are located in ~/.vim/plugged
if !has('nvim')
" If plugin manager vim-plug isn't installed, install it automatically
if empty(glob('~/.vim/autoload/plug.vim'))
echo "Downloading junegunn/vim-plug to manage plugins..."
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
" ## Plugins shared with Neovim
Plug 'tpope/vim-repeat' " enable repeating supported plugin maps with "."
Plug 'tpope/vim-sensible'
Plug '907th/vim-auto-save'
Plug 'mhinz/vim-startify' " change default vim starting screen
Plug 'tpope/vim-surround' " change surroundings, :h surround
Plug 'preservim/nerdcommenter' " comment/uncomment lines
Plug 'jiangmiao/auto-pairs' " automatically add matching pairs for quotes, brackets, etc.
Plug 'voldikss/vim-floaterm' " floating terminal
Plug 'alvan/vim-closetag' " auto close HTML tags
Plug 'michaeljsmith/vim-indent-object' " adds an object to select everything at an indent level
Plug 'zef/vim-cycle' " ability to cycle through some group of words, easy edit
Plug 'lambdalisue/suda.vim' " suport for sudo in neovim
Plug 'itchyny/lightline.vim' " configurable statusline/tabline
Plug 'ryanoasis/vim-devicons' " lightline icons
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'vim-python/python-syntax', { 'for': 'python' } " python syntax highlight
Plug 'tpope/vim-fugitive'
Plug 'cdelledonne/vim-cmake'
Plug 'ntpeters/vim-better-whitespace'
Plug 'igankevich/mesonic' " meson build system integration
Plug 'mbbill/undotree' " the undo history visualizer for VIM
Plug 'catppuccin/nvim', { 'as': 'catppuccin' } " color theme
Plug 'NoahTheDuke/vim-just' " just command runner support
" ## Vim only plugins
Plug 'tpope/vim-vinegar'
call plug#end()
else
" Source Neovim plugins
source $HOME/.config/nvim/plugins.vim
endif
" -------------------
" # _PLUGIN_SETTINGS_
" -------------------
" 01. _catppuccin_
" 02. _dracula_
" 03. _vim_auto_save_
" 04. _vim_startify_
" 05. _vim_surround_
" 06. _nerdcommenter_
" 07. _auto_pairs_
" 08. _vim_floaterm_
" 09. _vim_closetag_
" 10. _vim_indent_object_
" 11. _vim_cycle_
" 12. _suda_vim_
" 13. _lightline_vim_
" 14. _vim_devicons_
" 15. _python_syntax_
" 16. _vim_fugitive_
" 17. _vim_cmake_
" 18. _vim_vinegar_
" 19. _vim_sensible_
" 20. _vim_better_whitespace_
" 21. _undotree_
" ---------------
" ## _catppuccin_
" ---------------
" ------------
" ## _dracula_
" ------------
" ------------------
" ## _vim_auto_save_
" ------------------
" ### Settings
let g:auto_save_silent = 1 " do not display the auto-save notification
let g:auto_save = 0 " auto-save off by default
let g:auto_save_events = ["InsertLeave", "TextChanged"] " set events to trigger auto-save
" ### Keybindings
noremap <M-s> :AutoSaveToggle<CR>
inoremap <M-s> <ESC>:AutoSaveToggle<CR>a
" -----------------
" ## _vim_startify_
" -----------------
" ### Settings
let g:startify_session_dir = s:config_dir . '/session'
let g:startify_session_persistence = 1
" -----------------
" ## _vim_surround_
" -----------------
" ### Keybindings
" Works with parentheses(), brackets [], quotes (double or single), XML tags <q> </q> and more
" NOTE: Use vS) instead of vS( to surround without space
" Example:
" cs'<q> : To change 'Hello' to <q>Hello</q>
" ds' : To remove delimiters from 'Hello'
" dst : To remove the surrounding tag
" cst<p> : To change the surrounding tag to <p>
" vS : In visual mode, S surrounds the selected (vSt for tag)
" ------------------
" ## _nerdcommenter_
" ------------------
" ### Settings
" Add spaces after comment delimiters by default
let g:NERDCreateDefaultMappings = 0
let g:NERDSpaceDelims = 1
augroup nerdcommenter_group
autocmd!
autocmd FileType python let g:NERDDefaultAlign = 'left'
augroup END
" ### Keybindings
" [count]<leader>cc : make lines commented
" [count]<leader>c<space> : toggle line's comment status (commented/uncommented)
map <leader>cc <plug>NERDCommenterComment
map <leader>cu <plug>NERDCommenterUncomment
map <leader>ct <plug>NERDCommenterToggle
map <leader>cm <plug>NERDCommenterMinimal
" ---------------
" ## _auto_pairs_
" ---------------
" ### Settings
augroup auto_pairs_group
autocmd!
autocmd FileType norg let g:AutoPairsMapSpace = 0
augroup END
" fix coc-snippets inserting newline when selecting a snippet with enter
let g:AutoPairsMapCR = 0
" ### Keybindings
" <M-p> : Toggle auto-pairs
" <M-e> : Insert () or {} or [] before something then hit <M-e> to fast wrap
" <M-n> : Jump to next closed pair
" Use Ctrl-V) to insert paren without trigerring plugin
" Use x or DEL to delete the character inserted by the plugin
" -----------------
" ## _vim_floaterm_
" -----------------
" ### Settings
" Go back to the NORMAL mode using <C-\><C-N>
let g:floaterm_gitcommit='floaterm'
let g:floaterm_width=0.9
let g:floaterm_height=0.9
let g:floaterm_autoclose=1
" ### Keybindings
let g:floaterm_keymap_toggle = '<C-f>'
" -----------------
" ## _vim_closetag_
" -----------------
" ### Settings
" These are the file types where this plugin is enabled.
let g:closetag_filetypes = 'html,xhtml,phtml,xml'
let g:closetag_filenames = '*.html,*.xhtml,*.phtml,*.xml'
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx'
" ### Keybindings
" Shortcut for closing tags, default is '>'
let g:closetag_shortcut = '>'
" ----------------------
" ## _vim_indent_object_
" ----------------------
" ### Keybindings
" Defines two new text objects to select only current indentation level
" <count>ai An Indentation level and line above.
" <count>ii Inner Indentation level (no line above).
" <count>aI An Indentation level and lines above/below.
" --------------
" ## _vim_cycle_
" --------------
" ### Settings
augroup vim_cycle_group
autocmd!
autocmd FileType python call AddCycleGroup('python', ['True', 'False'])
augroup END
" ### Keybindings
" Move cursor on a word and hit <C-n> or <C-m> to toggle between pair of
" words or even increment-decrement a number
let g:cycle_no_mappings = 1
nnoremap <C-b> <Plug>CyclePrevious
nnoremap <C-n> <Plug>CycleNext
" -------------
" ## _suda_vim_
" -------------
" ------------------
" ## _lightline_vim_
" ------------------
" ### Settings
function! CocCurrentFunction()
return get(b:, 'coc_current_function', '')
endfunction
function! GitStatus() abort
return get(g:, 'coc_git_status', '')
endfunction
function! LightlineFilename()
let filename = expand('%:t') !=# '' ? expand('%:p:.') : '[No Name]'
let modified = &modified ? ' +' : ''
return filename . modified
endfunction
let g:lightline = {
\ 'colorscheme': 'catppuccin',
\ 'active': {
\ 'left': [ [ 'mode', 'paste', 'readonly' ],
\ [ 'gitbranch', 'filename' ],
\ [ 'cocstatus' ] ],
\ 'right': [['percent', 'lineinfo'],
\ [ 'filetype', 'fileencoding' ],
\ [ 'currentfunction', 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ]]
\ },
\ 'component_function': {
\ 'cocstatus': 'coc#status',
\ 'gitbranch': 'GitStatus',
\ 'currentfunction': 'CocCurrentFunction',
\ 'filename': 'LightlineFilename',
\ },
\ 'component_expand': {
\ 'linter_checking': 'lightline#ale#checking',
\ 'linter_infos': 'lightline#ale#infos',
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ },
\ 'component_type': {
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ }
\ }
" -----------------
" ## _vim_devicons_
" -----------------
" ------------------
" ## _python_syntax_
" ------------------
" ### Settings
let g:python_highlight_all = 1
" -----------------
" ## _vim_fugitive_
" -----------------
" ### Keybindings
" Enter :Git and then do g? to checkout all hotkeys
" After :Git use cc to enter commit buffer
" to add the file under cursor to .gitignore use {anynumber}gI
" git status
nnoremap <leader>gs :G<CR>
" solving merge conflicts
nnoremap <leader>gj :diffget //3<CR>
nnoremap <leader>gf :diffget //2<CR>
" Diff against any and all direct ancestors (merge conflicts)
nnoremap <leader>gdf :Gvdiffsplit!<CR>
" --------------
" ## _vim_cmake_
" --------------
" ### Settings
let g:cmake_link_compile_commands = 1
let g:cmake_root_markers = ['.git', '.svn']
" let g:cmake_build_options = []
let g:cmake_generate_options = ["-D CMAKE_C_COMPILER=/usr/bin/gcc-12", "-D CMAKE_CXX_COMPILER=/usr/bin/g++-12"]
augroup vim_cmake_group
autocmd!
" autoclose vimcmake window after successful build
" repeat() function causes soft-wrap into two lines for ENTER prompt to show
autocmd User CMakeBuildSucceeded echo "CMake Build Succeeded!" . repeat(" ", &columns) | CMakeClose!
" Needed for graceful closing of CMake window
autocmd FileType vimcmake nnoremap <buffer><silent>qq :CMakeClose!<CR>
augroup END
" ### Keybindings
" Create Release config (default is Debug) :CMakeGenerate build -DCMAKE_BUILD_TYPE=Release
nnoremap <leader>cg :CMakeGenerate build -DCMAKE_BUILD_TYPE=Debug
nnoremap <leader>cb :CMakeBuild<CR>
nnoremap <leader>co :CMakeOpen<CR>
nnoremap <leader>cr :CMakeRun
" ----------------
" ## _vim_vinegar_
" ----------------
" -----------------
" ## _vim_sensible_
" -----------------
" -----------------------
" _vim_better_whitespace_
" -----------------------
" ### Settings
let g:better_whitespace_enabled=1
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=LightRed ctermfg=white guibg='#f9e2af' guifg=black
" ----------
" _undotree_
" ----------
" ### Keybindings
nnoremap <silent> <M-u> :UndotreeToggle<CR>
" -------------
" # _FUNCTIONS_
" -------------
" 01. _LongLineHighlightOn_
" 02. _ToggleBackground_
" 03. _TermForceCloseAll_
" ------------------------
" ## _LongLineHighlightOn_
" ------------------------
" https://gist.github.com/fgarcia/9704429#file-long_lines-vim
" https://stackoverflow.com/q/395114
function! LongLineHighlightOn()
if exists("w:llh")
call matchdelete(w:llh)
endif
highlight OverLength ctermbg=LightBlue ctermfg=black guibg='#89dceb' guifg=black
autocmd ColorScheme * highlight OverLength ctermbg=LightBlue ctermfg=black guibg='#89dceb' guifg=black
if &ft ==? 'css' || &ft ==? 'scss'
let l:length = 90
let w:llh = matchadd("OverLength", '\%' . (l:length + 1) . 'v')
elseif &ft != 'floaterm' && &ft != 'fzf'
let l:length = 120
let w:llh = matchadd("OverLength", '\%' . (l:length + 1) . 'v')
endif
endfunction
call LongLineHighlightOn()
" ---------------------
" ## _ToggleBackground_
" ---------------------
function! ToggleBackground()
if &background =~? 'dark'
echo "Changing to light theme"
set background=light " for the light version of the theme
let g:lightline.colorscheme = 'catppuccin'
let g:lightline#colorscheme#catppuccin#palette = {'inactive': {'right': [['#bcc0cc', '#eff1f5', 146, 231], ['#9ca0b0', '#eff1f5', 145, 231]], 'middle': [['#bcc0cc', '#eff1f5', 146, 231]], 'left': [['#1e66f5', '#eff1f5', 27, 231], ['#9ca0b0', '#eff1f5', 145, 231]]}, 'replace': {'left': [['e6e9ef', '#d20f39', 189, 161], ['#1e66f5', '#eff1f5', 27, 231]]}, 'normal': {'right': [['#9ca0b0', '#eff1f5', 145, 231], ['#1e66f5', '#ccd0da', 27, 188]], 'middle': [['#1e66f5', '#e6e9ef', 27, 189]], 'warning': [['#e6e9ef', '#df8e1d', 189, 172]], 'left': [['#e6e9ef', '#1e66f5', 189, 27], ['#1e66f5', '#eff1f5', 27, 231]], 'error': [['#e6e9ef', '#d20f39', 189, 161]]}, 'tabline': {'right': [['#bcc0cc', '#eff1f5', 146, 231], ['#9ca0b0', '#eff1f5', 145, 231]], 'middle': [['#bcc0cc', '#eff1f5', 146, 231]], 'left': [['#9ca0b0', '#eff1f5', 145, 231], ['#9ca0b0', '#eff1f5', 145, 231]], 'tabsel': [['#1e66f5', '#bcc0cc', 27, 146], ['#9ca0b0', '#eff1f5', 145, 231]]}, 'visual': {'left': [['#e6e9ef', '#8839ef', 189, 99], ['1e66f5', '#eff1f5', 27, 231]]}, 'insert': {'left': [['#e6e9ef', '#179299', 189, 30], ['#1e66f5', '#eff1f5', 27, 231]]}}
else
echo "Changing to dark theme"
set background=dark " for the dark version of the theme
let g:lightline.colorscheme = 'catppuccin'
let g:lightline#colorscheme#catppuccin#palette = {'inactive': {'right': [['#45475a', '#1e1e2e', 59, 16], ['#6c7086', '#1e1e2e', 60, 16]], 'middle': [['#45475a', '#1e1e2e', 59, 16]], 'left': [['#89b4fa', '#1e1e2e', 111, 16], ['#6c7086', '#1e1e2e', 60, 16]]}, 'replace': {'left': [['#181825', '#f38ba8', 16, 211], ['#89b4fa', '#1e1e2e', 111, 16]]}, 'normal': {'right': [['#6c7086', '#1e1e2e', 60, 16], ['#89b4fa', '#313244', 111, 59]], 'middle': [['#89b4fa', '#181825', 111, 16]], 'warning': [['#181825', '#f9e2af', 16, 223]], 'left': [['#181825', '#89b4fa', 16, 111], ['#89b4fa', '#1e1e2e', 111, 16]], 'error': [['#181825', '#f38ba8', 16, 211]]}, 'tabline': {'right': [['#45475a', '#1e1e2e', 59, 16], ['#6c7086', '#1e1e2e', 60, 16]], 'middle': [['#45475a', '#1e1e2e', 59, 16]], 'left': [['#6c7086', '#1e1e2e', 60, 16], ['#6c7086', '#1e1e2e', 60, 16]], 'tabsel': [['#89b4fa', '#45475a', 111, 59], ['#6c7086', '#1e1e2e', 60, 16]]}, 'visual': {'left': [['#181825', '#cba6f7', 16, 183], ['#89b4fa', '#1e1e2e', 111, 16]]}, 'insert': {'left': [['#181825', '#94e2d5', 16, 116], ['#89b4fa', '#1e1e2e', 111, 16]]}}
endif
try
call lightline#init()
call lightline#colorscheme()
call lightline#update()
catch
endtry
endfunction
command! ToggleBackground call ToggleBackground()
" ----------------------
" ## _TermForceCloseAll_
" ----------------------
" https://www.reddit.com/r/vim/comments/fwedfx/comment/fmnwar1
function! s:TermForceCloseAll() abort
let term_bufs = filter(range(1, bufnr('$')), 'getbufvar(v:val, "&buftype") == "terminal"')
for t in term_bufs
execute "bd! " t
endfor
endfunction
if !has('nvim')
" NOTE: If Floaterm term buffer is running it causes Vim to not close with :qall
augroup term_force_close_all
autocmd!
" TODO: it causes term to close when any window is closed even if you don't exit Vim
autocmd QuitPre * call <sid>TermForceCloseAll()
augroup END
endif
" ---------------
" # _KEYBINDINGS_
" ---------------
" Source $MYVIMRC
nnoremap <leader>ss :source $MYVIMRC<CR>
" Quit without saving
nnoremap qq :q<CR>
" Quit after saving
nnoremap qw :wq<CR>
" Save with Ctrl + S
noremap <C-s> :w<CR>
inoremap <C-s> <ESC>:w<CR>a
" Copy-paste bindings for system clipboard (+)
nnoremap <Leader>yy "+y
vnoremap <Leader>yy "+y
nnoremap <Leader>pp "+p
vnoremap <Leader>pp "+p
" Quickly insert an empty new line without entering insert mode
nnoremap <Leader>o o<Esc>k
nnoremap <Leader>O O<Esc>j
" Change vim window focus
map <C-h> <C-w>h
map <C-l> <C-w>l
map <C-j> <C-w>j
map <C-k> <C-w>k
" Move between tabs
nnoremap <silent> <C-M-l> :tabn<CR>
nnoremap <silent> <C-M-h> :tabp<CR>
" Resize vim windows
nnoremap <silent> <C-Down> :resize -2<CR>
nnoremap <silent> <C-Up> :resize +2<CR>
nnoremap <silent> <C-Left> :vertical resize -2<CR>
nnoremap <silent> <C-Right> :vertical resize +2<CR>
" Zoom into one pane
nnoremap <silent> <Leader>z :tabnew %<CR>
" 'cd' towards the directory in which the current file is edited
nnoremap <Leader>cd :cd %:h<CR>
" See changes before saving file
nnoremap <Leader>df :w !diff % -<CR>
" Better multiple lines tabbing with < and >
vnoremap < <gv
vnoremap > >gv
" See buffers
nnoremap <Leader>fb :Buffers!<CR>
" Open netrw
if !has('nvim')
nnoremap <C-c> :Lexplore 30<CR>
endif
" Move in quickfix list (copen)
nnoremap <silent> [c :cprevious<CR>
nnoremap <silent> ]c :cnext<CR>
" Move in location list (lopen)
nnoremap <silent> [l :lprevious<CR>
nnoremap <silent> ]l :lnext<CR>
" Clear highlighting of 'hlsearch' and call :diffupdate
nnoremap <silent> <leader>h :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><leader>h
" Toggle background theme between light and dark
nnoremap <silent> <M-t> :ToggleBackground<CR>
" Set bindings for default Vim autocompletion support
" :help ins-completion
" <C-n> : start word completion from file
" <C-x><C-o> : start omni completion
if !has('nvim')
" Exit pum without inserting with <Esc>
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
" Select with <CR>
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
" Use <Tab> and <S-Tab> to view completion suggestions
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : exists("g:loaded_snips")
\ ? "\<C-r>=TriggerSnippet()\<CR>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : exists("g:loaded_snips")
\ ? "\<C-r>=BackwardsSnippet()\<CR>" : "\<S-Tab>"
endif
" Fix meta keybindings in Vim
if !has('nvim')
execute "set <M-a>=\ea"
execute "set <M-e>=\ee"
execute "set <M-n>=\en"
execute "set <M-p>=\ep"
execute "set <M-s>=\es"
execute "set <M-t>=\et"
execute "set <M-u>=\eu"
endif
" Auto-indent whole file
nnoremap <silent> <localleader>== gg=G<C-o>
" ----------------
" # _LATE_IMPORTS_
" ----------------
" ## Set colorscheme and trigger highlight groups defined with "autocmd ColorScheme"
" (must be on the bottom to trigger autocmds)
colorscheme catppuccin
" ## Import settings not tracked by Git
if !has('nvim') && !empty(glob("$HOME/.vimrc.gitignore"))
source $HOME/.vimrc.gitignore
elseif has('nvim') && !empty(glob("$HOME/.config/nvim/gitignore.vim"))
source $HOME/.config/nvim/gitignore.vim
endif