-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
382 lines (310 loc) · 10.5 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
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Keep Plugin commands between vundle#begin/end.
Plugin 'altercation/vim-colors-solarized'
Plugin 'luochen1990/rainbow'
Plugin 'ryanoasis/vim-devicons'
Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim'}
"Plugin 'vim-airline/vim-airline'
"Plugin 'vim-airline/vim-airline-themes'
Bundle 'Valloric/YouCompleteMe'
Plugin 'Valloric/ListToggle'
Plugin 'preservim/nerdcommenter'
Plugin 'tiagofumo/vim-nerdtree-syntax-highlight'
Plugin 'scrooloose/nerdtree'
Plugin 'preservim/tagbar'
Plugin 'mileszs/ack.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'airblade/vim-gitgutter'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'fatih/vim-go'
Plugin 'hashivim/vim-terraform'
Plugin 'github/copilot.vim'
call vundle#end() " required
filetype plugin indent on " required
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
" === Vundle End ===
let mapleader = " "
" Toggle Background Color (dark/light)
call togglebg#map("<F5>")
"let g:solarized_termcolors=256
set background=dark
colorscheme solarized
" Change cursor shape between insert and normal mode in iTerm2.app
if $TERM_PROGRAM =~ "iTerm"
let &t_ti = "\<Esc>]50;CursorShape=0\x7" " Start as block in normal mode
let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
let &t_te = "\<Esc>]50;CursorShape=1\x7" " Back to vertical bar on exit
set ttimeoutlen=50 " Timeout in ms for Escape (back quickly to normal mode)
endif
" General
set encoding=utf-8
set mouse=a " Scroll with mouse
set visualbell
"set timeoutlen=500
set cursorline
set scrolloff=5
" Syntax highlighting
let python_highlight_all=1
syntax on
" Unset background color to use iTerm background color instead
" (must be set after enabling syntax highlighting)
highlight Normal ctermbg=NONE
" Highlight matching () {} []
set showmatch
let g:rainbow_active = 1
" Highlight search results
set hlsearch
nnoremap <leader>. :set hlsearch!<cr>
" Search settings
set incsearch " Search while typing
set ignorecase
set smartcase
" Line numbers
set number
"set relativenumber
highlight CursorLineNr ctermfg=2 ctermbg=NONE cterm=NONE
" Copy & Paste from a system buffer
vnoremap <leader>c "*y
noremap <leader>v "*P
" Show/hide whitespaces
set lcs+=space:⥗
nnoremap <leader>w :set list!<CR>
" Highlight redundant whitespaces
highlight ExtraWhitespace ctermbg=red guibg=red
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
" Block folding
set foldmethod=indent
set foldlevel=99
map <leader>f za
nnoremap <leader>F zM
nnoremap <leader>FF zR
" Code comments
let g:NERDDefaultAlign = 'both'
map <leader>/ <plug>NERDCommenterToggle
" Merge conflicts
nnoremap <leader>cj :/<<<<<<<<CR>
nnoremap <leader>ck :?<<<<<<<<CR>
" Shortcuts
map <F1> :!<CR>
map <F2> :!!<CR>
" Run Python with the current file or wait for args
map <F3> :w<CR>:!python %<CR>
map <F4> :w<CR>:!python %
map <leader>r :w<CR>:!python %<CR>
map <leader>R :w<CR>:!python %
" Map Special-Key (Insert) to F4
" iTerm -> Keys -> Send Escape Sequence: 02P
"map <S-F1> <F4>
" Powerline
set guifont=MesloLGS\ NF:h13
let g:powerline_pycmd = 'py3'
let g:Powerline_symbols = 'fancy'
set t_Co=256
set laststatus=2
set noshowmode
let g:airline_powerline_fonts = 1
" Ack
cnoreabbrev Ack Ack!
nnoremap <leader>a :Ack!<space>
" YouCompleteMe
" Auto-completion
let g:ycm_java_binary_path = systemlist('brew --prefix openjdk@17')[0] . '/bin/java'
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
" Errors navigation (YCM + ListToggle)
let g:ycm_always_populate_location_list = 1
let g:lt_location_list_toggle_map = '<leader>l'
let g:lt_quickfix_list_toggle_map = '<leader>q'
let g:lt_height = 6
noremap <leader>j :lnext<CR>
noremap <leader>k :lprevious<CR>
" Objects Explorer (Tagbar)
nnoremap <silent> <leader>e :TagbarToggle<CR>
let g:tagbar_position = 'topleft vertical'
let g:tagbar_map_togglefold = ["o", "za", "<leader>f"]
let g:tagbar_compact = 1
let g:tagbar_show_tag_linenumbers = 1
let g:tagbar_show_tag_count = 1
let g:tagbar_zoomwidth = 0
" File Browser (NERDTree)
let NERDTreeIgnore=['\.pyc$', ]
let g:NERDTreeLimitedSyntax = 1
let g:NERDTreeFileExtensionHighlightFullName = 1
let g:NERDTreeExactMatchHighlightFullName = 1
let g:NERDTreePatternMatchHighlightFullName = 1
let g:NERDTreeHighlightFolders = 1 " enables folder icon highlighting using exact match
let g:NERDTreeHighlightFoldersFullName = 1 " highlights the folder name
nnoremap <leader>b :call NERDTreeFindOrToggle()<CR>
function! NERDTreeFindOrToggle()
if exists("g:NERDTree") && g:NERDTree.IsOpen()
execute("NERDTreeClose")
else
let s = execute("NERDTreeFind")
if strtrans(s) == "^@NERDTree: no file for the current buffer"
execute("NERDTreeToggle")
endif
endif
endfunction
" FZF
set rtp+=/opt/homebrew/opt/fzf
map <leader>t :call FZFWithDevIcons()<CR>
function! FZFWithDevIcons()
let l:files_limit = 3000 " higher values can slow down the command
let l:fzf_files_options = ' -m --bind ctrl-f:preview-page-down,ctrl-b:preview-page-up --preview "bat --color always --style numbers {2..}"'
function! s:files()
let files = split(system($FZF_VIM_COMMAND), '\n')
return s:prepend_icon(l:files)
endfunction
function! s:prepend_icon(candidates)
let result = []
for candidate in a:candidates
let filename = substitute(candidate, '\e\[[0-9;]\{-}m', '', 'g')
let filename = fnamemodify(filename, ':p:t')
let icon = WebDevIconsGetFileTypeSymbol(filename, isdirectory(filename))
call add(result, printf("%s %s", icon, candidate))
endfor
return result
endfunction
function! s:edit_file(items)
let items = a:items
let i = 1
let ln = len(items)
while i < ln
let item = items[i]
let parts = split(item, ' ')
let file_path = get(parts, 1, '')
let items[i] = file_path
let i += 1
endwhile
call s:Sink(items)
endfunction
let counter = len(split(system($FZF_VIM_COMMAND . ' --max-results ' . l:files_limit), '\n'))
if counter >= l:files_limit
call fzf#run(fzf#wrap({}))
else
let opts = fzf#wrap({})
let opts.source = <sid>files()
let s:Sink = opts['sink*']
let opts['sink*'] = function('s:edit_file')
let opts.options .= l:fzf_files_options
call fzf#run(opts)
endif
endfunction
" GitGutter
"nmap ]h <Plug>(GitGutterNextHunk)
"nmap [h <Plug>(GitGutterPrevHunk)
nmap <leader>hj <Plug>(GitGutterNextHunk)
nmap <leader>hk <Plug>(GitGutterPrevHunk)
nmap <leader>ha <Plug>(GitGutterStageHunk)
nmap <leader>hr <Plug>(GitGutterUndoHunk)
nnoremap <leader>hf :GitGutterFold<CR>
nnoremap <leader>hh :GitGutterLineHighlightsToggle<CR>
highlight SignColumn ctermbg=NONE
highlight LineNr ctermbg=NONE
highlight CursorLineNr ctermbg=NONE
"function! SignColumnToggleTrigger() abort
" let visible = &signcolumn ==# 'yes'
" if &signcolumn ==# 'auto'
" let visible = len(sign_getplaced('%', {'group': '*'})[0].signs)
" endif
" if visible
" highlight LineNr ctermbg=NONE
" highlight CursorLineNr ctermbg=NONE
" augroup numbertoggle
" autocmd!
" autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | hi CursorLineNr ctermfg=2 ctermbg=NONE cterm=NONE | endif
" autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | hi CursorLineNr ctermfg=11 ctermbg=NONE cterm=underline | endif
" augroup END
" else
" " Distinct background for LineNr if no SignColumn
" highlight LineNr ctermbg=0
" highlight CursorLineNr ctermbg=0
" augroup numbertoggle
" autocmd!
" autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | hi CursorLineNr ctermfg=2 ctermbg=0 cterm=NONE | endif
" autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | hi CursorLineNr ctermfg=11 ctermbg=NONE cterm=underline | endif
" augroup END
" endif
"endfunction
"augroup SignColumnToggleTrigger
" autocmd!
" autocmd BufEnter,BufWinEnter * call SignColumnToggleTrigger()
" autocmd User GitGutter call SignColumnToggleTrigger()
"augroup END
" vim-go
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
" Swap & backup files
"
" Store .swp files in ~/.vim/swap
if filewritable("$HOME/.vim/swap") != 2 && (has("unix") || has("win32unix"))
call system("mkdir -p -m 0700 $HOME/.vim/swap")
endif
set dir=$HOME/.vim/swap
function! s:DeleteOldBackups()
let l:DayTreshold = 45
let l:Old = (60 * 60 * 24 * l:DayTreshold)
let l:BackupFiles = split(glob(&backupdir."*", 1)."\n".glob(&backupdir.".[^.]*",1), "\n")
let l:Now = localtime()
for l:File in l:BackupFiles
if (l:Now - getftime(l:File)) > l:Old
echon "- Deleting backup file (older than " l:DayTreshold " days): " l:File
call delete(l:File)
echon "\t[Done]\n"
endif
endfor
endfunction
" Delete backups over 45 days old on exit
au VimLeave * call <SID>DeleteOldBackups()
" Timestamped backups
au BufWritePre * let &backupext = '.bak' . localtime()
" Store .bak files in ~/.vim/backup
if filewritable("$HOME/.vim/backup") != 2 && (has("unix") || has("win32unix"))
call system("mkdir -p -m 0700 $HOME/.vim/backup")
endif
set backup
set backupdir=$HOME/.vim/backup// " double trailing slash to rename backup file with full path
set backupext=.bak
set backupcopy=yes
set writebackup
" Filetypes (Golang set by vim-go plugin)
set textwidth=0
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set autoindent
autocmd Filetype python,php setlocal
\ textwidth=79
\ fileformat=unix
" Go set by vim-go plugin
"autocmd Filetype go setlocal
" \ softtabstop=0
" \ noexpandtab
autocmd Filetype sh,javascript,typescript,html,css,htmldjango,sql setlocal
\ tabstop=2
\ softtabstop=2
\ shiftwidth=2
autocmd Filetype proto setlocal
\ textwidth=80
\ tabstop=2
\ softtabstop=2
\ shiftwidth=2
\ smartindent
autocmd Filetype make setlocal
\ noexpandtab
autocmd Filetype markdown setlocal
\ textwidth=79
\ noautoindent