]> git.immae.eu Git - perso/Immae/Config/dotdrop.git/blob - dotfiles/tools/vimrc
Add autoformat for vim
[perso/Immae/Config/dotdrop.git] / dotfiles / tools / vimrc
1 " ---------- Init, config, backup ---------------
2 " Respect XDG directories (more below for cache)
3 set viminfo+='1000,n$XDG_STATE_HOME/vim/viminfo
4 set runtimepath=$XDG_DATA_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_DATA_HOME/vim/after
5
6 " Run :PlugInstall after adding plugins there
7 call plug#begin(expand($XDG_DATA_HOME) . '/vim/plugged')
8
9 Plug 'vim-scripts/cecutil'
10 Plug 'vim-scripts/LargeFile'
11 Plug 'vim-scripts/Align'
12 Plug 'vim-scripts/AutoAlign'
13 Plug 'jamessan/vim-gnupg'
14 Plug 'vim-scripts/taglist.vim'
15 Plug 'chrisbra/csv.vim'
16 Plug 'mustache/vim-mustache-handlebars'
17 Plug 'cakebaker/scss-syntax.vim'
18 Plug 'tpope/vim-bundler'
19 Plug 'tpope/vim-rails'
20 Plug 'ledger/vim-ledger'
21 Plug 'beyondwords/vim-twig'
22 Plug 'scrooloose/nerdtree'
23 Plug 'kien/ctrlp.vim'
24 Plug 'rodjek/vim-puppet'
25 Plug 'szw/vim-tags'
26 Plug 'neomutt/neomutt.vim'
27 Plug 'kchmck/vim-coffee-script'
28 Plug 'digitaltoad/vim-pug'
29 Plug 'vim-scripts/slapd.vim'
30 Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
31 Plug 'vim-vdebug/vdebug'
32 Plug 'tpope/vim-fugitive'
33 Plug 'tomlion/vim-solidity'
34 Plug 'chrisbra/SudoEdit.vim'
35 Plug 'Chiel92/vim-autoformat'
36
37 call plug#end()
38
39 " Charge automatiquement les ftplugins/*.vim selon le type de fichier
40 filetype plugin on
41 " Charge automatiquement les indent/*.vim selon le type de fichier
42 filetype indent on
43
44 " Pour que vim garde une copie de sauvegarde des fichiers modifiés.
45 set backup
46 """ Copied from /usr/share/vim/vimfiles/archlinux.vim
47 " Move temporary files to a secure location to protect against CVE-2017-1000382
48 if exists('$XDG_CACHE_HOME')
49 let &g:directory=$XDG_CACHE_HOME
50 else
51 let &g:directory=$HOME . '/.cache'
52 endif
53 let g:ctrlp_cache_dir=&g:directory . '/vim/ctrlp//'
54 let &g:undodir=&g:directory . '/vim/undo//'
55 let &g:backupdir=&g:directory . '/vim/backup//'
56 let g:vim_tags_cache_dir = &g:directory . '/vim/ctags//'
57 let &g:directory.='/vim/swap//'
58 " Create directories if they doesn't exist
59 if ! isdirectory($XDG_STATE_HOME . '/vim')
60 silent! call mkdir($XDG_STATE_HOME . '/vim')
61 endif
62 if ! isdirectory(expand(&g:directory))
63 silent! call mkdir(expand(&g:directory), 'p', 0700)
64 endif
65 if ! isdirectory(expand(&g:backupdir))
66 silent! call mkdir(expand(&g:backupdir), 'p', 0700)
67 endif
68 if ! isdirectory(expand(&g:undodir))
69 silent! call mkdir(expand(&g:undodir), 'p', 0700)
70 endif
71 if ! isdirectory(expand(g:vim_tags_cache_dir))
72 silent! call mkdir(expand(g:vim_tags_cache_dir), 'p', 0700)
73 endif
74 """ /Copied from /usr/share/vim/vimfiles/archlinux.vim
75
76
77 " Ne pas sauver un backup spécial pour les fichiers réseau
78 let g:netrw_dirhistmax = 0
79
80 " ---------- Mappings ---------------------------
81 " map : Normal, Visual, Select, Operator-pending
82 " map! : Insert and Command-line
83
84 " Le BackSpace fonctionne aussi en mode normal.
85 map <BS> X
86
87 " Les Control-flèches
88 map <ESC>[1;5A <C-Up>
89 map! <ESC>[1;5A <C-Up>
90 map <ESC>[1;5B <C-Down>
91 map! <ESC>[1;5B <C-Down>
92 map <ESC>[1;5C <C-Right>
93 map! <ESC>[1;5C <C-Right>
94 map <ESC>[1;5D <C-Left>
95 map! <ESC>[1;5D <C-Left>
96
97 map <S-Up> {
98 map! <S-Up> <C-O>{
99 map <S-Down> }
100 map! <S-Down> <C-O>}
101
102
103 " ---------- Comportement à la frappe -----------
104 " <BS> passe à travers l'indentation, les fins de ligne et le début du "insert"
105 set backspace=indent,eol,start
106
107 " '<BS>e écrit un é (sinon : ctrl+K ' e)
108 " set digraph
109
110 " La taille d'une ligne, pour la frappe au kilomètre.
111 " Permet 4 niveaux de 'citation' pour les mails/forum
112 set textwidth=72
113 " set textwidth=80
114
115 " Les touches qui font passer à la ligne suivante/précédente. backspace (b),
116 " espace (s), flèches (<,>,[,]).
117 set whichwrap=b,s,<,>,[,]
118
119 " Ne pas mettre deux espaces après la ponctuation quand on "join" deux lignes
120 set nojoinspaces
121
122 " Quand on tape un ), vim montre furtivement le ( correspondant.
123 set showmatch
124
125 " Les options de formatage.
126 set formatoptions=tcq2
127
128
129 " ---------- Recherche --------------------------
130 " Pour voir tous les matchs d'une recherche
131 set hlsearch
132
133 " Pour que les matchs soient affichés pendant que vous tapez le mot recherché
134 set incsearch
135
136 " On ignore la casse des caractères dans les recherches de chaînes en
137 " minuscules; par contre, dès qu'une lettre est en majuscule, on tient compte
138 " de la casse de toute la chaîne.
139 " Pendant la recherche : \c pour ignorer quand même, \C pour case-sensitive
140 set ignorecase
141 set smartcase
142
143
144 " ---------- Fichiers ---------------------------
145 " Pour une complétion automatique des noms de fichiers
146 set wildmenu
147
148 " La façon dont la complétion présente les choix.
149 set wildmode=longest,list:longest,full
150
151 " La complétion automatique ignore les fichiers suivants.
152 set suffixes=.bak.o.aux.dvi.log.toc.tof
153
154
155 " ---------- Buffers ----------------------------
156 " On veut pouvoir rendre invisible un buffer
157 set hidden
158
159 " Pour éviter de trop ralentir en faisant défiler le texte pendant l'exécution
160 " des macros.
161 set lazyredraw
162
163
164 " ----------- Interactions ----------------------
165 " On affiche en permanence les numéros de ligne et de colonne.
166 set ruler
167
168 " Pour ne pas se faire bipper tout le temps.
169 set noerrorbells
170 set visualbell t_vb=
171
172 " Pour avoir des messages de vim qui tiennent sur une seule ligne, ce
173 " qui évite d'avoir à presser «Enter» pour voir les messages suivants.
174 set shortmess=filnrxoOt
175
176 " Quand on tape une commande complexe en mode normal, vim affiche ce que l'on
177 " a déjà tapé
178 set showcmd
179
180
181 " ------------ Indentations ---------------------
182 " Conserve l'indentation
183 set autoindent
184
185 " Remplace les <Tab> par des espaces
186 set expandtab
187
188 " Nombre d'espaces
189 set shiftwidth=2
190 set softtabstop=2
191
192 " Pour que l'indentation ajuste sur un multiple de 'shiftwidth'.
193 set shiftround
194
195 " ------------ Folding --------------------------
196 set foldmethod=indent
197 set foldnestmax=10
198 set nofoldenable
199 set foldlevel=0
200 set foldlevelstart=0
201
202
203 " ------------ Auto-commandes -------------------
204 " On commence par enlever toutes les autocommandes avant de les définir
205 " (pour le cas où ce fichier serait lu plusieurs fois.)
206 autocmd!
207
208 autocmd BufRead,BufNewFile mutt*[0-9] set nobackup nowritebackup
209 autocmd BufRead,BufNewFile .article.* set filetype=mail nobackup
210
211 " ledger
212 " Don't load ftplugin for ledger
213 " autocmd BufReadPre,BufNewFile *ledger* let b:did_ftplugin = 1
214 autocmd FileType ledger set textwidth=0
215 let g:ledger_main = '~/.ledger/perso'
216
217 autocmd FileType puppet set textwidth=0
218
219 " ----------- Coloration syntaxique -------------
220 syntax enable
221
222 highlight Comment term=none ctermfg=darkCyan cterm=none
223 highlight Constant term=underline ctermfg=Blue cterm=none
224 highlight Error term=reverse ctermfg=White ctermbg=Red cterm=none
225 highlight Identifier term=none ctermfg=Green cterm=none
226 highlight IncSearch term=reverse ctermfg=Blue ctermbg=White
227 highlight Operator term=none ctermfg=darkGray cterm=bold
228 highlight PreProc term=underline ctermfg=Magenta cterm=none
229 highlight Search term=reverse cterm=reverse
230 highlight Special term=bold ctermfg=Blue cterm=bold
231 highlight Statement term=bold ctermfg=Red cterm=none
232 highlight Todo term=standout ctermfg=White ctermbg=Green cterm=bold
233 highlight Type term=bold ctermfg=Brown cterm=none
234
235 highlight link Delimiter Operator
236 highlight link SpecialChar Special
237
238 " lignes "foldées"
239 highlight Folded term=standout ctermfg=White ctermbg=Blue cterm=bold
240
241 " Pour les diffs (commande vimdiff).
242 highlight DiffAdd term=bold ctermfg=Green ctermbg=none cterm=bold
243 highlight DiffChange term=bold ctermfg=Cyan ctermbg=none
244 highlight DiffDelete term=bold ctermfg=Red ctermbg=none cterm=bold
245 highlight DiffText term=standout ctermfg=White ctermbg=Cyan cterm=bold
246
247 " ------------- Fonctions, commandes, macros ----
248 " Identer les fichiers (json, xml)
249 function PRangeFunc(command_line, syntax) range
250 if a:firstline==1 && a:lastline==line('$')
251 execute 'set filetype=' . a:syntax
252 execute 'syntax on'
253 endif
254 execute a:firstline . "," . a:lastline . '!' . a:command_line
255 endfunction
256
257 command -range=% Pjson normal <Esc>`>a<CR><Esc>mb`<i<CR><Esc>ma:'a,'b-1 call PRangeFunc('python -m json.tool', 'json')<CR>
258 command -range=% Pxml normal <Esc>`>a<CR><Esc>mb`<i<CR><Esc>ma:'a,'b-1 call PRangeFunc('xmllint --format --encode UTF8 -', 'xml')<CR>
259 command -range=% Pdeflate normal <Esc>`>a<CR><Esc>mb`<i<CR><Esc>ma:'a,'b-1 call PRangeFunc('python -c "import zlib; import sys; sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))"', '')<CR>
260 command -range=% Pinflate normal <Esc>`>a<CR><Esc>mb`<i<CR><Esc>ma:'a,'b-1 call PRangeFunc('python -c "import zlib; import sys; sys.stdout.buffer.write(zlib.compress(sys.stdin.buffer.read()))"', '')<CR>
261 command! -range=% Pastebin execute <line1> . "," . <line2> . "w !curl -F 'c=@-' https://ptpb.pw"
262
263 noremap <F3> :Autoformat<CR>
264 vmap <F8> :Pxml<CR>
265 vmap <F9> :Pjson<CR>
266
267 " gpg-encryptes files
268 let g:GPGPreferArmor=1
269 let g:GPGDefaultRecipients=["ismael.bouya@normalesup.org"]
270 let g:GPGUsesPipes=1
271
272 command Decrypt 1,$!gpg -d -q
273 command Encrypt 1,$!gpg -e -q --armor -r ismael.bouya@normalesup.org
274 command -range=% Runhash s/:\([_a-zA-Z0-9]\+\)\( \+\)=> \( *\)/\1:\2\3/
275
276 function! s:DiffWithSaved()
277 let filetype=&ft
278 diffthis
279 vnew | r # | normal! 1Gdd
280 diffthis
281 exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
282 endfunction
283 command! DiffSaved call s:DiffWithSaved()
284
285 " Load NERDTree on startup if no file were specified
286 " autocmd StdinReadPre * let s:std_in=1
287 " autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
288 " Load NERDTree on startup
289 "autocmd VimEnter * NERDTree | wincmd p
290 let g:vim_tags_auto_generate = 1
291 let g:vim_tags_project_tags_command = "ctags -R {OPTIONS} {DIRECTORY} 2>/dev/null"
292 map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
293 map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
294
295 let g:ctrlp_extensions = ['tag', 'buffertag', 'dir', 'undo', 'line']
296 set modeline
297
298 set grepprg=grep\ -rn\ $*\ /dev/null
299 let c_comment_strings=1
300 if !exists(":DiffOrig")
301 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
302 \ | wincmd p | diffthis
303 endif
304
305 set list
306 set listchars=tab:>-,trail:-
307