-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
438 lines (366 loc) · 13.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
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
set nocompatible
" If on Windows, link Vim directory to the standard location
if has('win32') && empty(glob('~/vimfiles'))
:silent !cmd /c mklink /J "\%UserProfile\%/vimfiles" "\%UserProfile\%/.vim"
endif
" Install Plug if needed
call ntpeters#util#ensurePlug()
" Determine if NCM should load
let g:ncmSupported = has('nvim') || ntpeters#util#hasPythonModule('neovim')
let g:ncmVimCompatAvailable = g:ncmSupported && !has('nvim')
" Setup Plug
call plug#begin('~/.vim/bundle')
" Setup Plugins
" Vim 8 compatibility for NCM (requires Python neovim module)
Plug 'roxma/vim-hug-neovim-rpc', ntpeters#util#plugEnableIf(g:ncmVimCompatAvailable)
" Required by ncm2
Plug 'roxma/nvim-yarp', ntpeters#util#plugEnableIf(g:ncmSupported)
" Enable NCM for NeoVim always, and Vim if requirements are met
Plug 'ncm2/ncm2', ntpeters#util#plugEnableIf(g:ncmSupported)
Plug 'Shougo/neco-vim'
Plug 'roxma/ncm-clang'
Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' }
Plug 'luochen1990/rainbow'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'scrooloose/nerdcommenter'
Plug 'myusuf3/numbers.vim'
Plug 'vim-scripts/a.vim'
Plug 'Raimondi/delimitMate'
Plug 'w0rp/ale'
Plug 'bling/vim-bufferline'
Plug 'airblade/vim-gitgutter'
Plug 'mbbill/undotree'
Plug 'tpope/vim-fugitive'
Plug 'godlygeek/tabular'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'guns/xterm-color-table.vim'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'ntpeters/vim-better-whitespace'
Plug 'gilsondev/searchtasks.vim'
Plug 'jeetsukumaran/vim-buffergator'
Plug 'ctrlpvim/ctrlp.vim', ntpeters#util#plugEnableIf(!executable('fzf'))
Plug 'tacahiroy/ctrlp-funky', ntpeters#util#plugEnableIf(!executable('fzf'))
Plug 'junegunn/fzf', ntpeters#util#plugEnableIf(executable('fzf'))
Plug 'junegunn/fzf.vim', ntpeters#util#plugEnableIf(executable('fzf'))
Plug 'tpope/vim-endwise'
Plug 'ervandew/supertab'
Plug 'terryma/vim-multiple-cursors'
Plug 'ludovicchabant/vim-gutentags', ntpeters#util#plugEnableIf(executable('ctags'))
Plug 'itchyny/lightline.vim'
Plug 'tpope/vim-obsession'
Plug 'dhruvasagar/vim-prosession'
Plug 'unblevable/quick-scope'
Plug 'zigford/vim-powershell'
Plug 'editorconfig/editorconfig-vim'
" Setup Theme Plugins
Plug 'nanotech/jellybeans.vim'
Plug 'alem0lars/vim-colorscheme-darcula'
" Always load devicons last
Plug 'ryanoasis/vim-devicons'
call plug#end()
" Remap leader from '\' to ','
let mapleader = ","
" Disable unused builtin plugins
let g:loaded_gzip = 1
let g:loaded_tar = 1
let g:loaded_tarPlugin = 1
let g:loaded_zip = 1
let g:loaded_zipPlugin = 1
let g:loaded_rrhelper = 1
let g:loaded_2html_plugin = 1
let g:loaded_vimball = 1
let g:loaded_vimballPlugin = 1
let g:loaded_getscript = 1
let g:loaded_getscriptPlugin = 1
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
let g:loaded_netrwSettings = 1
let g:loaded_netrwFileHandlers = 1
let g:loaded_logipat = 1
let g:gutentags_modules = ['ctags']
" Tell vim-whitespace to strip whitespace on save
let g:strip_whitespace_on_save = 1
let g:strip_only_modified_lines = 1
if (!executable('fzf'))
" Enable CtrlP extensions
let g:ctrlp_extensions = ['funky']
" Use fd for CtrlP if available
if (executable('fd'))
let g:ctrlp_user_command = 'fd --type file'
endif
endif
" Configure Rainbow Parenthese
let g:rainbow_conf = {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['red', 'blue', 'yellow', 'cyan', 'magenta', 'lightred', 'lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'lisp': {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
" Enable Rainbow Parenthesis
let g:rainbow_active = 1
" Prevent buffergator from resizing fullscreen gVim windows
let g:buffergator_autoexpand_on_split = 0
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" Put all vimrc auto commands in their own group
augroup vimrc
autocmd!
" Enable indent guides by default
autocmd VimEnter * if exists(":IndentGuidesToggle") | execute ":IndentGuidesToggle" | endif
" Open NERDTree if Vim was invoked with no args or a directory was opened
autocmd VimEnter * if ((!argc() || (expand('%:p') == expand('%:p:h'))) && exists(":NERDTree")) | execute ":NERDTreeToggle" | endif
" Close NERDTree if it's the last open buffer
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | :quit | endif
" Autosave on focus lost for gVim
autocmd FocusLost * :wall
" Normalize split sizes when terminal is resized
autocmd VimResized * :execute "normal \<C-w>="
" Save/load current vim state when exiting/opening a file
autocmd BufWinLeave ?* if ntpeters#util#shouldRestoreView() | mkview! | endif
autocmd BufWinEnter ?* if ntpeters#util#shouldRestoreView() | silent! loadview | endif
" Highlight anything beyond column 120 in red
autocmd BufWinEnter,BufWinLeave * let w:m2=matchadd('ErrorMsg', '\%>120v.\+', -1)
autocmd ColorScheme * highlight QuickScopePrimary ctermfg=119 ctermbg=22 cterm=underline guifg='#87ff5f' guibg='#005f00' gui=underline
autocmd ColorScheme * highlight QuickScopeSecondary ctermfg=117 ctermbg=55 cterm=underline guifg='#87dfff' guibg='#5f00af' gui=underline
" Disable tab expansion for certain filetypes that should use tabs instead of spaces
let preserveTabsFiletypes = ['gitconfig', 'makefile']
autocmd BufEnter * if index(preserveTabsFiletypes, &filetype) >= 0 | setlocal noexpandtab | endif
" Redraw the status line on mode change to trigger a redraw of the cursor line number.
" This allows the colors to stay in sync since the highlight groups are
" linked: CursorLineNr -> LightlineLeft_active_0
autocmd ModeChanged * redrawstatus
augroup END
set autoindent
set smartindent
" Tab width in spaces
set tabstop=4
" Size of indent in spaces
set shiftwidth=4
" Make spaces feel like real tabs
set softtabstop=4
" Convert tabs to spaces
set expandtab
" Intelligent backspace for space tabs. Makes a backspace delete one
" tabstop/shiftstop worth of spaces
set smarttab
" Set the encoding Vim uses for display
set encoding=utf-8
" Set the encoding Vim writes files with
set fileencoding=utf-8
set scrolloff=3
set noshowmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set wildignorecase
set cursorline
set cursorcolumn
set cursorlineopt=both
set ruler
set backspace=indent,eol,start
set laststatus=2
set number
set autowrite
" Shorten messages to avoid 'hit enter' prompts
set shortmess=at
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
" Set auto text wrapping at column 80
set wrap
set textwidth=79
set formatoptions=qrn1
" Show whitespace characters
set list
set listchars=tab:▸\ ,eol:¬
" More sane split defaults
set splitbelow
set splitright
set modeline
set modelines=3
" Tell gitgutter to always show sign column
set signcolumn=yes
" Set shortcut for paste mode
set pastetoggle=<F10>
" Enable mouse support for Visual and Normal modes
set mouse=vn
if !has('nvim')
set ttymouse=xterm2
endif
set ttyfast
" Must be set before GUI is loaded, don't move to gvimrc
" Disable menus, copy visual selection to clipboard, and preserve window sizing
set guioptions=Mak
" Enable persistent undo, and put undo files in their own directory to prevent
" pollution of project directories
if has('persistent_undo')
call ntpeters#util#ensureDirectory('~/.vim/undo')
" Remove current directory and home directory, then add .vim/undo as main
" dir and current dir as backup dir
set undodir-=.
set undodir-=~/
set undodir+=.
set undodir^=~/.vim/undo//
set undofile
endif
" Move swap files and backup files to their own directory to prevent pollution
call ntpeters#util#ensureDirectory('~/.vim/backup')
" Remove current directory and home directory, then add .vim/backup as main dir
" and current dir as backup dir
set backupdir-=.
set backupdir-=~/
set backupdir+=.
set backupdir^=~/.vim/backup//
" Enable standard backups if not built with 'writebackup'
if !has('writebackup')
set backup
endif
call ntpeters#util#ensureDirectory('~/.vim/swap')
" Remove current directory and home directory, then add .vim/swap as main dir
" and current dir as backup dir
set directory-=.
set directory-=~/
set directory+=.
set directory^=~/.vim/swap//
set swapfile
" Set the directory for storing saved views
call ntpeters#util#ensureDirectory('~/.vim/views')
set viewdir=~/.vim/views
" Set options for 'mkview'
set viewoptions= " Ensure no other options are set
set viewoptions+=cursor " Cursor position in file
set viewoptions+=folds " All local fold options (ie. opened/closed/manual folds)
set viewoptions+=slash " Backslashes in filenames are replaced with foward slashes
set viewoptions+=unix " Use Unix EOL
" Use FZF if available, otherwise fallback to CtrlP
if (executable('fzf'))
" Tell FZF to use the bottom 40% off the screen
let g:fzf_layout = { 'down': '~40%' }
" Remap CtrlP mappings to FZF
nnoremap <c-p> :Files<Cr>
nnoremap <Leader>fu :Tags<Cr>
" Search tags with the word under the cursor
nnoremap <Leader>fU :execute 'Tags ' . expand('<cword>')<Cr>
else
" Keys for CtrlP Funky
nnoremap <Leader>fu :CtrlPFunky<Cr>
" Narrow the list down with a word under cursor
nnoremap <Leader>fU :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
endif
" Enable 'very magic' search mode
nnoremap / /\v
vnoremap / /\v
" Search for the word under the curoser with leader+/
nnoremap <Leader>/ *
" Unhighlight search terms with leader+space
nnoremap <leader><space> :noh<cr>
nnoremap <tab> %
vnoremap <tab> %
"
" Map Ctrl+N to open the NERDTree sidebar
nmap <silent> <c-n> :NERDTreeToggle<cr>
" Set Ctrl+S to save the file in all modes
nnoremap <silent> <c-s> :update<cr>
vnoremap <silent> <c-s> <c-c>:update<cr>
inoremap <silent> <c-s> <c-o>:update<cr>
" Disable arrow keys
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
nnoremap j gj
nnoremap k gk
" Remap F1 to ESC in all modes for those times why you accidentally hit F1
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" Remap semicolon to colon, because shift is for nerds
nnoremap ; :
" Set 'jj' to escape. Homerow OP
imap jj <ESC>
" Remaps for easier buffer navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Remaps for easier split opening
nnoremap <leader>w <C-w>v<C-w>l
nnoremap <leader><S-w> <C-w>s<C-w>j
" Shift+dir to jump paragraphs
nnoremap <S-k> <S-{>
nnoremap <S-j> <S-}>
" Shift+dir to jump to begin/end of line
nnoremap <S-h> ^
nnoremap <S-l> $
" More laziness remaps
nnoremap :q :q!
nnoremap :X :x
" Hit F9 to toggle spaces and tabs
nmap <silent> <F9> :call ntpeters#util#toggleTabs()<CR>
" Search help for the word under the cursor
nnoremap <Leader>h :execute 'help ' . expand('<cword>')<Cr>
" Enable 256 color support explicitly if we're running on Windows in a terminal
" that supports it. This only applies to Vim, Neovim correctly handles this.
if &term == 'win32' && ($TERM == 'xterm-256color' || $COLORTERM == 'truecolor')
" Do not set `term` to anything other than 'win32', as that is the only
" officially supported term by Vim on Windows and other values could have
" unexpected behavior. For more info see :help win32-term.
let &t_Co = 256
endif
" Set colorscheme options based on detected 256 color support
if &t_Co == 256
" Use 24-bit color if available
if has('termguicolors')
" Required to set Vim-specific sequences for RGB colors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Enable 256 colors in supported base16 themes
let base16colorspace=256
endif
" Only allow Base16 themes to attempt running thier shell script in
" non-Windows, console Vim
if !has('win32')
let g:base16_shell_path='~/.scripts/base16'
endif
" Base16 themes don't work well in Windows console
if !has('win32')
call ntpeters#util#tryColorscheme('base16-material-darker')
else
" Jellybeans works reasonably well everywhere, so it's a good fallback
call ntpeters#util#tryColorscheme('jellybeans')
endif
set background=dark
" Set columns as 80 and 120
let &colorcolumn="80,120,121"
highlight ColorColumn ctermbg=19
" Set color for cursor line and column
highlight CursorLine ctermbg=232
highlight CursorColumn ctermbg=232
" Link the cursor line highlight to the active mode highlight from Lightline
highlight! link CursorLineNr LightlineLeft_active_0
" Load local vim config if it exists
let s:localRcPath = glob('~/.vimrc.local')
if filereadable(s:localRcPath)
execute 'source ' . s:localRcPath
endif