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