-
Notifications
You must be signed in to change notification settings - Fork 58
/
.vimrc
382 lines (307 loc) · 12.1 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
" ---------------------------------------------------------------------------- "
" Plugins "
" ---------------------------------------------------------------------------- "
let g:polyglot_disabled = ['autoindent', 'sensible']
call plug#begin('~/.vim/plugged')
Plug 'ervandew/supertab'
Plug 'ap/vim-buftabline'
Plug 'itchyny/lightline.vim'
Plug 'junegunn/fzf', { 'do': 'yes \| ./install' }
Plug 'junegunn/fzf.vim'
Plug 'mbbill/undotree'
Plug 'moll/vim-bbye'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-sleuth'
if has('nvim')
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/nvim-cmp'
Plug 'ishan9299/nvim-solarized-lua'
Plug 'lewis6991/gitsigns.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
else
Plug 'lifepillar/vim-solarized8'
Plug 'mhinz/vim-signify'
Plug 'sheerun/vim-polyglot'
endif
Plug 'chiel92/vim-autoformat', { 'on': 'Autoformat' }
Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' }
Plug 'vim-scripts/doxygentoolkit.vim', { 'for': 'cpp' }
Plug 'jdevlieghere/llvm.vim', { 'for': 'llvm' }
Plug 'racer-rust/vim-racer', { 'for': 'rust' }
Plug 'lervag/vimtex', { 'for': 'tex' }
call plug#end()
" ---------------------------------------------------------------------------- "
" General Settings "
" ---------------------------------------------------------------------------- "
filetype plugin indent on
set background=dark
if has("termguicolors")
let &t_8f="\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b="\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
try
if has('nvim')
colorscheme solarized
else
colorscheme solarized8
endif
catch
endtry
if !exists("g:syntax_on")
syntax enable
endif
set autoread " Auto reload file after external command
set backspace=indent,eol,start " Delete over line breaks
set colorcolumn=80,120 " Show ruler columns
set encoding=utf-8 " Use UTF-8 encoding
set hidden " Hide buffers instead of closing them
set laststatus=2 " Always display the status line
set nofoldenable " Disable folding
set lazyredraw " Use lazy redrawing
set noshowmode " Don't show mode
set number " Show line numbers
set pastetoggle=<F2> " Toggle paste mode with F2
set ruler " Show ruler
set showcmd " Show current command
set showmatch " Show matching bracket/parenthesis/etc
set showmode " Show current mode
set tags=tags; " Find tags recursively
set title " Change terminal title
set ttyfast " Fast terminal
set wildmenu " Visual autocomplete for command menu
set clipboard^=unnamed,unnamedplus
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%)
" Temp Files
set nobackup " No backup file
set noswapfile " No swap file
" Search
set incsearch " Incremental search
set hlsearch " Highlight matches
set ignorecase " Case-insensitive search...
set smartcase " ...unless search contains uppercase letter
" Indentation
set smarttab " Better tabs
set smartindent " Insert new level of indentation
set autoindent " Copy indentation from previous line
set tabstop=2 " Columns a tab counts for
set softtabstop=2 " Columns a tab inserts in insert mode
set shiftwidth=2 " Columns inserted with the reindent operations
set shiftround " Always indent by multiple of shiftwidth
set expandtab " Always use spaces instead of tabs
" Key sequence timeout
set ttimeout " Enable time out
set ttimeoutlen=0 " Disable key code delay
" Wrapping
set nowrap " Don't wrap long lines
set linebreak " When wrapping, only at certain characters
set textwidth=0 " Turn off physical line wrapping
set wrapmargin=0 " Turn off physical line wrapping
" Joining
set nojoinspaces " Only one space when joining lines
set formatoptions+=j " Remove comment leader when joining lines
" Scroll
set sidescrolloff=3 " Keep at least 3 lines left/right
set scrolloff=3 " Keep at least 3 lines above/below
" Mouse
set mousehide " Hide mouse when typing
set mouse=nicr " Disable mouse
" Disable bell
set visualbell " Disable visual bell
set noerrorbells " Disable error bell
" Treat given characters as a word boundary
set iskeyword-=. " Make '.' end of word designator
set iskeyword-=# " Make '#' end of word designator
" Splits
set splitbelow " Horizontal split below
set splitright " Vertical split right
" Spell checking
set spelllang=en_us " English as default language
set spell " Enable by default
" Invisible characters
set nolist
set listchars=eol:¬,tab:▶\ ,trail:~,extends:⟩,precedes:⟨,nbsp:␣
set showbreak=↳\ \ \ "
" Make completion menu behave like an IDE
set completeopt=longest,menuone,preview
" Don't give ins-completion-menu messages
set shortmess+=c
" Disable modelines as a security precaution
set modelines=0
set nomodeline
" Encryption
if has("crypt-blowfish2")
set cm=blowfish2
endif
" History
set history=1000 " Remember more commands
if has("persistent_undo")
set undofile " Persistent undo
set undodir=~/.vim/undo " Location to store undo history
set undolevels=1000 " Max number of changes
set undoreload=10000 " Max lines to save for undo on a buffer reload
endif
" Neovim
if has("nvim")
set wildoptions+=pum,tagfile
set inccommand=split
endif
" ---------------------------------------------------------------------------- "
" Colors & User Interface "
" ---------------------------------------------------------------------------- "
" Same color for sign column and line numbers
highlight clear SignColumn
" Custom spell-checking highlighting
highlight SpellBad cterm=underline term=underline gui=underline
highlight SpellCap cterm=underline term=underline gui=underline
highlight SpellRare cterm=underline term=underline gui=underline
highlight SpellLocal cterm=underline term=underline gui=underline
" Tab line
highlight TabLine cterm=NONE ctermfg=33 ctermbg=235 guifg=#268bd2 guibg=#073642
highlight TabLineFill cterm=NONE ctermfg=33 ctermbg=235 guifg=#268bd2 guibg=#073642
highlight TabLineSel cterm=NONE ctermfg=235 ctermbg=33 guifg=#073642 guibg=#268bd2
" Italics for comments
highlight Comment cterm=italic
" ---------------------------------------------------------------------------- "
" Key Mappings "
" ---------------------------------------------------------------------------- "
" Typos
cnoreabbrev E e
cnoreabbrev Q q
cnoreabbrev Qa qa
cnoreabbrev W w
" Save file which you forgot to open with sudo
cnoremap w!! w !sudo tee % >/dev/null
" Wrap the current visual selection
vnoremap Q gq
" Wrap the current paragraph
nnoremap Q gqap
" Search for current visual selection
vnoremap // y/\V<C-R>"<CR>
" Move between open buffers
nnoremap <C-n> :bnext<CR>
nnoremap <C-p> :bprev<CR>
" Redraw the screen and remove highlighting
nnoremap <silent> <C-l> :nohl<CR><C-l>
" ---------------------------------------------------------------------------- "
" Leader Mappings "
" ---------------------------------------------------------------------------- "
let mapleader=" "
" Clear search highlight
nnoremap <leader><space> :noh<CR>
" Yank
nnoremap <leader>yp :let @+=expand("%:p")<CR>
nnoremap <leader>yl :let @+=expand('%:t') . ':' . line(".")<CR>
nnoremap <leader>yc :let @+=expand('%:t') . ':' . line( "."). ':' . col(".")<CR>
" Toggle
nnoremap <leader>ts :setlocal spell!<CR>
nnoremap <leader>tl :set list!<CR>
nnoremap <leader>tw :call ToggleRemoveTrailingWhitespace()<CR>
" Buffers
nnoremap <leader>bd :bdelete<CR>
nnoremap <leader>bf :bfirst<CR>
nnoremap <leader>bl :blast<CR>
nnoremap <leader>bn :bnext<CR>
nnoremap <leader>bp :bprevious<CR>
" Windows
nnoremap <leader>wd <C-w>c
nnoremap <leader>wo <C-w>o
" ---------------------------------------------------------------------------- "
" Functions "
" ---------------------------------------------------------------------------- "
function! ToggleRemoveTrailingWhitespace()
if exists("g:dont_remove_trailing_whitespace")
unlet g:dont_remove_trailing_whitespace
echo "Enabled removing trailing whitespace"
else
let g:dont_remove_trailing_whitespace=1
echo "Disabled removing trailing whitespace"
endif
endfunction
function! RemoveTrailingWhitespace()
if !exists("g:dont_remove_trailing_whitespace")
%s/\s\+$//e
endif
endfunction
" ---------------------------------------------------------------------------- "
" Auto Commands "
" ---------------------------------------------------------------------------- "
" Extension specific commands
augroup extensions
autocmd!
autocmd BufNewFile,BufRead *.mm setlocal filetype=objcpp
augroup end
" Filetype specific commands
augroup filtypes
autocmd!
autocmd FileType c,cpp setlocal comments^=:///
autocmd FileType c,cpp setlocal commentstring=///\ %s
autocmd FileType crontab setlocal nobackup nowritebackup
autocmd FileType make setlocal noexpandtab
autocmd FileType python setlocal tabstop=4 softtabstop=4 shiftwidth=4
augroup end
" Remove trailing whitespace
augroup remove_trailing_whitespace
autocmd!
autocmd BufWritePre * :call RemoveTrailingWhitespace()
augroup end
" Watch my .vimrc
augroup reload_vimrc
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup end
" ---------------------------------------------------------------------------- "
" Plugin Configuration "
" ---------------------------------------------------------------------------- "
" vim-bbye
nnoremap <silent> <leader>bd :Bdelete!<CR>
" vim-signify
let g:signify_vcs_list=['git']
let g:signify_update_on_bufenter=0
" fzf.vim
let g:fzf_buffers_jump=1
nnoremap \ :Rg<SPACE>
nnoremap \| :Tags<SPACE>
vnoremap _ y :Rg <C-R>"<CR>
nnoremap _ yaw :Rg <C-R>"<CR>
nnoremap <silent> <C-f> :Files<CR>
nnoremap <silent> <C-b> :Buffers<CR>
" vim-lightline
let g:lightline = {
\ 'colorscheme': 'solarized',
\ }
" tagbar
let g:tagbar_autofocus=0
let g:tagbar_compact=1
let g:tagbar_right=1
let g:tagbar_width=35
nnoremap <leader>tt :TagbarToggle<CR>
" vim-autoformat
let g:formatters_python=['black', 'yapf', 'autopep8']
let g:formatter_yapf_style='pep8'
" doxygentoolkit.vim
let g:DoxygenToolkit_commentType="C++"
" LSP
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
nnoremap <leader>ld :LspDefinition<CR>
nnoremap <leader>lf :LspDocumentFormat<CR>
nnoremap <leader>lh :LspHover<CR>
nnoremap <leader>lr :LspReferences<CR>
endfunction
if has('nvim')
luafile ~/.vim/lsp.lua
luafile ~/.vim/treesitter.lua
luafile ~/.vim/dap.lua
luafile ~/.vim/git.lua
nnoremap <leader>db :lua require'dap'.toggle_breakpoint()<CR>
nnoremap <leader>dc :lua require'dap'.continue()<CR>
nnoremap <leader>dn :lua require'dap'.step_over()<CR>
nnoremap <leader>ds :lua require'dap'.step_into()<CR>
nnoremap <leader>dr :lua require'dap'.repl.open()<CR>
endif