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