-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
461 lines (389 loc) · 13.7 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
""""""""""""""""""""""
" Package management "
""""""""""""""""""""""
so /etc/xdg/nvim/sysinit.vim
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()
" General
Plugin 'VundleVim/Vundle.vim'
" Available in Arch repository
" Plugin 'vim-airline/vim-airline'
" Plugin 'ctrlpvim/ctrlp.vim'
" Plugin 'tpope/vim-surround'
" Plugin 'tpope/vim-fugitive'
" Plugin 'scrooloose/nerdcommenter'
" Plugin 'majutsushi/tagbar'
" Themes
Plugin 'morhetz/gruvbox'
" Navigation
Plugin 'rking/ag.vim'
Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'tpope/vim-unimpaired'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-abolish'
Plugin 'b4winckler/vim-angry'
Plugin 'dietsche/vim-lastplace'
" Code completion and linting
" Language-specific
Plugin 'posva/vim-vue'
" Plugin 'python-mode/python-mode'
Plugin 'nelstrom/vim-markdown-folding'
Plugin 'tpope/vim-markdown'
Plugin 'tpope/vim-rails'
Plugin 'tfnico/vim-gradle'
Plugin 'honza/dockerfile.vim'
Plugin 'mattn/emmet-vim'
Plugin 'vim-scripts/AnsiEsc.vim.git'
Plugin 'rust-lang/rust.vim'
if has('nvim')
" Neovim can use LSP to provide completion
Plugin 'neovim/nvim-lspconfig'
else
" LSP support is not available in vanilla Vim
Plugin 'ycm-core/YouCompleteMe'
endif
call vundle#end()
"""""""""""""""""""""""""
" Common editor options "
"""""""""""""""""""""""""
" Common options
set re=1
set ttyfast
set autoread " Auto reload modified files
set backspace=indent,eol,start " backspace erases in insert mode
set backup
set formatoptions=lq " Don't break comments at middle of words
set history=100 " reasonable history
set lbr
set nocompatible " Ensure VIM really is in IMproved mode
set nowrap " don't wrap lines
set number " show line numbers
set ruler " show line/character in statusbar
set showcmd " show number of lines selected in visual
set wildmenu " Expanded menu for command-line completion
set cursorline " Show the cursorline
set guicursor= " Disable GUI cursor (not supported in Guake)
" File encodings
set encoding=utf-8
set fileencoding=utf-8
" Highlight searches, searches begin immediately
set hlsearch
set incsearch
if has('nvim')
set inccommand=split
end
" Non-case-sensitive searches
set ignorecase
set smartcase
set infercase
" Tab settings
set expandtab " tabs as space
set shiftwidth=2 " set spaces for autoindent
set smartindent " smart autoindenting on a new line
set softtabstop=2
set tabstop=2 " tab character amount
" Folding (disabled by default)
set foldcolumn=1
set foldmethod=manual
set foldlevelstart=10
set nofoldenable
" Navigation
set nostartofline " navigate closest column
set showtabline=2 " tab bar always on
" Disable visual bells
set t_vb=''
" Mouse support (cursor position, tab selection - hold shift to select
" n = normal mode, i = insert, c = command, a = all
set mouse=ni
set scrolloff=4
" Setting menu tab completion
set wildignore+=*.o,*~,.lo
set wildignore+=.jpg,.png,.jpeg,.gif,~,.swp,.swo,.info,.o,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.pyc,.pyo
set suffixes+=.in,.a
" Leader key is ','
let mapleader=","
" Add easier foldlevel aliases
map z0 :set foldlevel=0<CR>
map z1 :set foldlevel=1<CR>
map z2 :set foldlevel=2<CR>
map z3 :set foldlevel=3<CR>
map z4 :set foldlevel=4<CR>
map z5 :set foldlevel=5<CR>
map z6 :set foldlevel=6<CR>
map z7 :set foldlevel=7<CR>
map z8 :set foldlevel=8<CR>
map z9 :set foldlevel=9<CR>
map ze :set foldenable foldmethod=indent foldlevelstart=0 foldlevel=0<CR>
map zd :set nofoldenable foldmethod=manual foldlevelstart=99<CR>
" Ctrl-A increments on a whole line
vmap <C-a> :s/\d\+/\=(submatch(0)+1)/g<CR>gv
" Auto-reload .vimrc when saved
au! bufWritePost .vimrc source %
""""""""""""""
" Appearance "
""""""""""""""
" Colorscheme
set background=dark
colorscheme gruvbox
" Show trailing whitespaces
au ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
au InsertLeave * match ExtraWhitespace /\s\+$/
" Better show weird characters
set list listchars=nbsp:¬,tab:>-,extends:»,precedes:«,trail:•
" Use 256 color palette if available
if &term=="xterm"
set t_Co=256
endif
""""""""""""""""""
" Syntax options "
""""""""""""""""""
" Enable syntax highlighting
syntax on
" Enable filetype plugins
filetype on
filetype plugin on
filetype plugin indent on
" LSP setup for Neovim
if has('nvim')
let g:ale_disable_lsp = 1
let g:ale_use_neovim_diagnostics_api = 1
lua <<EOF
local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_keymap(0, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<c-]>', '<cmd>lua vim.lsp.buf.definition()<CR>', {noremap = true})
vim.api.nvim_buf_set_option(0, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
vim.api.nvim_buf_set_option(0, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
end
require('lspconfig').ccls.setup({on_attach=on_attach})
require('lspconfig').rust_analyzer.setup{}
EOF
" Default completion function for vanilla Vim
else
set omnifunc="syntaxcomplete#Complete" " Set syntax-completion function
set complete-=i " Disable completion for included files
endif
"""""""""""
" Plugins "
"""""""""""
" Backup in ~/.vim/backup
if filewritable(expand("~/.vim/backup")) == 2
set backupdir=$HOME/.vim/backup
else
if has("unix") || has("win32unix")
call system("mkdir $HOME/.vim/backup -p")
set backupdir=$HOME/.vim/backup
endif
endif
" Vim 7 spell checker
if has("spell")
" Language : FR
map ,lf :setlocal spell spelllang=fr<cr>
" Language : EN
map ,le :setlocal spell spelllang=en<cr>
" Language : Aucun
map ,ln :setlocal nospell<cr>
endif
" Powerline
set laststatus=2
" Disable expensive Python mode scripts : most of the useful things are
" handled by YCM and ALE which are asynchronous.
let g:pymode_lint = 0
let g:pymode_rope = 0
let g:pymode_folding = 0
" YCM
let g:ycm_autoclose_preview_window_after_insertion = 1
" Indent Guides
let g:indent_guides_auto_colors = 1
autocmd VimEnter * silent exe ":IndentGuidesEnable"
" Netrw: Default configuration settings
let g:netrw_banner = 0 " No banner
let g:netrw_liststyle = 3 " Tree netrw style
let g:netrw_winsize = 20 " Smaller window size
let g:netrw_altv = 1 " Split on right by default
let g:netrw_browse_split = 0 " Reuse the same window when opening
" Netrw: Automatically open a left-explore window if launched with no arguments
"
" Interestingly, Lexplore will by default work much better than Vexplore for
" IDE-style file explorer, because the window won't resize the way standard
" Vim windows do (like Vexplore and Sexplore).
" augroup ProjectDrawer
" autocmd!
" autocmd VimEnter * if argc() == 0 | Lexplore | endif
" augroup END
" NERDCommenter: Use PEP8-compliant Python comments (space between # and text)
let g:NERDCustomDelimiters= {
\ 'python': {'left': '# '}
\ }
" CtrlP: Allow regular expressions, and use Git to take .gitignore into account
let g:ctrlp_regexp = 1
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
"""""""""""""""""""""
" Keyboard bindings "
"""""""""""""""""""""
" Copy/Paste using Ctrl-C and Ctrl-V
vmap <C-c> "+y
vmap <C-x> "+d
imap <C-v> <Esc>"+pi
" Wrapped line navigation
noremap <C-J> gj
noremap <C-K> gk
" Run "make" with Enter
" noremap <C-M> :!make<CR>
" Allow saving of files as sudo when I forgot to start vim using sudo
cmap w!! w !sudo tee > /dev/null %
" Space bar un-highligts search
noremap <silent> <Space> :silent noh<Bar>echo<CR>
" Tmux-like bindings
if has('nvim')
noremap <C-b>n :tabnext<CR>
noremap <C-b>c :tabnew<CR>
noremap <C-b>s :new<CR>
noremap <C-b>v :vnew<CR>
tnoremap <C-b>n <C-\><C-n>:tabnext<CR>
tnoremap <C-b>c <C-\><C-n>:tabnew<CR>:terminal<CR>
tnoremap <C-b>s <C-\><C-n>:new<CR>:terminal<CR>
tnoremap <C-b>v <C-\><C-n>:vnew<CR>:terminal<CR>
tnoremap <C-b><Esc> <Esc>
tnoremap <Esc> <C-\><C-n>
end
""""""""""""""""""""""""""
" Auto template commands "
""""""""""""""""""""""""""
"HTML Pages
augroup html
au bufNewFile *.html 0r ~/.vim/templates/html
au bufNewFile *.html silent exe "%s/%PLACE_CURSOR%//"
au bufNewFile *.htm 0r ~/.vim/templates/html
au bufNewFile *.htm silent exe "%s/%PLACE_CURSOR%//"
augroup END
"PHP Scripts
augroup php
au bufNewFile *.php 0r ~/.vim/templates/php
au bufNewFile *.php silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.php silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.php silent exe "%s/%PLACE_CURSOR%//"
augroup END
"CSS Stylesheets
augroup css
au bufNewFile *.css 0r ~/.vim/templates/css
au bufNewFile *.css silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.css silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.css silent exe "%s/%PLACE_CURSOR%//"
augroup END
"Bash scripts
augroup shellscripts
au bufNewFile *.sh 0r ~/.vim/templates/bash
au bufNewFile *.sh silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.sh silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.sh silent exe "%s/%PLACE_CURSOR%//"
augroup END
"Python Scripts
augroup pythonscripts
au bufNewFile *.py 0r ~/.vim/templates/python
au bufNewFile *.py silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.py silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.py silent exe "%s/%PLACE_CURSOR%//"
au bufNewFile *.py2 0r ~/.vim/templates/python2
au bufNewFile *.py2 silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.py2 silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.py2 silent exe "%s/%PLACE_CURSOR%//"
augroup END
"C++ Source files
augroup c_cpp
au bufNewFile *.cpp 0r ~/.vim/templates/cpp
au bufNewFile *.cpp silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.cpp silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.cpp silent exe "%s:%PLACE_FILENOEXT%:".substitute(expand("%"), ".cpp$", "", "g").":g"
au bufNewFile *.cpp silent exe "%s/%PLACE_CURSOR%//"
au bufNewFile *.hpp 0r ~/.vim/templates/hpp
au bufNewFile *.hpp silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.hpp silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.hpp silent exe "%s:%PLACE_FILENOEXT%:".substitute(expand("%"), ".hpp$", "", "g").":g"
au bufNewFile *.hpp silent exe "%s/%PLACE_CURSOR%//"
au bufNewFile *.c 0r ~/.vim/templates/c
au bufNewFile *.c silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.c silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.c silent exe "%s/%PLACE_CURSOR%//"
au bufNewFile *.h 0r ~/.vim/templates/h
au bufNewFile *.h silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.h silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.h silent exe "%s/%PLACE_CURSOR%//"
augroup END
"Haskell Source files
augroup haskell
au bufNewFile *.hs 0r ~:.vim:templates:hs
au bufNewFile *.hs silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.hs silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.hs silent exe "%s/%PLACE_FILENOEXT%/".substitute(expand("%"), ".hs$", "", "g")."/g"
augroup END
"C Headers
"Java source code
augroup java
au bufNewFile *.java 0r ~/.vim/templates/java
au bufNewFile *.java silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.java silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.java silent exe "%s:%PLACE_FILENOEXT%:".substitute(expand("%"), ".java$", "", "g").":g"
au bufNewFile *.java silent exe "%s/%PLACE_CURSOR%//"
augroup END
"C for CUDA source code
augroup cuda
au bufNewFile *.cu 0r ~/.vim/templates/cu
au bufNewFile *.cu silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.cu silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.cu silent exe "%s/%PLACE_CURSOR%//"
augroup END
"Ninja Build Script
augroup ninja
au bufNewFile *.ninja 0r ~/.vim/templates/ninja
au bufNewFile *.ninja silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.ninja silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.ninja silent exe "%s/%PLACE_CURSOR%//"
augroup END
"JavaScript
augroup js
au bufNewFile *.js 0r ~/.vim/templates/js
au bufNewFile *.js silent exe "%s:%PLACE_FILENAME%:".expand("%").":g"
au bufNewFile *.js silent exe "%s/%PLACE_CREATETIME%/".strftime("%c")."/g"
au bufNewFile *.js silent exe "%s/%PLACE_CURSOR%//"
augroup END
"Ruby
augroup rb
au bufNewFile *.rb 0r ~/.vim/templates/rb
augroup END
"QGIS XML files
augroup qgis
au bufRead,bufNewFile *.qml set syntax=xml
au bufRead,bufNewFile *.qpt set syntax=xml
au bufRead,bufNewFile *.qgs set syntax=xml
augroup END
"SQL scripts
augroup sql
au bufRead,bufNewFile *.sql set formatprg="sqlformat -kupper -r -"
augroup END
"Log files with color
augroup logfiles
au bufRead *.log AnsiEsc
augroup END
function! HighlightRepeats() range
let lineCounts = {}
let lineNum = a:firstline
while lineNum <= a:lastline
let lineText = getline(lineNum)
if lineText != ""
let lineCounts[lineText] = (has_key(lineCounts, lineText) ? lineCounts[lineText] : 0) + 1
endif
let lineNum = lineNum + 1
endwhile
exe 'syn clear Repeat'
for lineText in keys(lineCounts)
if lineCounts[lineText] >= 2
exe 'syn match Repeat "^' . escape(lineText, '".\^$*[]') . '$"'
endif
endfor
endfunction
command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
" Allow (secure) project-specific settings
set exrc
set secure