summaryrefslogtreecommitdiff
path: root/dotfiles/tools/vimrc
blob: 68a52f7609626011bd5cd13df9d2c726e206615b (plain) (blame)
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
" ---------- Init, config, backup ---------------
" Respect XDG directories (more below for cache)
set viminfo+='1000,n$XDG_STATE_HOME/vim/viminfo
set runtimepath=$XDG_DATA_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_DATA_HOME/vim/after

" Run :PlugInstall after adding plugins there
call plug#begin(expand($XDG_DATA_HOME) . '/vim/plugged')

Plug 'vim-scripts/cecutil'
Plug 'vim-scripts/LargeFile'
Plug 'vim-scripts/Align'
Plug 'vim-scripts/AutoAlign'
Plug 'jamessan/vim-gnupg'
Plug 'vim-scripts/taglist.vim'
Plug 'chrisbra/csv.vim'
Plug 'mustache/vim-mustache-handlebars'
Plug 'cakebaker/scss-syntax.vim'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-rails'
Plug 'ledger/vim-ledger'
Plug 'beyondwords/vim-twig'
Plug 'scrooloose/nerdtree'
Plug 'kien/ctrlp.vim'
Plug 'rodjek/vim-puppet'
Plug 'szw/vim-tags'
Plug 'neomutt/neomutt.vim'
Plug 'kchmck/vim-coffee-script'
Plug 'digitaltoad/vim-pug'
Plug 'vim-scripts/slapd.vim'
Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
Plug 'vim-vdebug/vdebug'
Plug 'tpope/vim-fugitive'
Plug 'tomlion/vim-solidity'
Plug 'chrisbra/SudoEdit.vim'

call plug#end()

" Charge automatiquement les ftplugins/*.vim selon le type de fichier
filetype plugin on
" Charge automatiquement les indent/*.vim selon le type de fichier
filetype indent on

" Pour que vim garde une copie de sauvegarde des fichiers modifiés.
set backup
""" Copied from /usr/share/vim/vimfiles/archlinux.vim
" Move temporary files to a secure location to protect against CVE-2017-1000382
if exists('$XDG_CACHE_HOME')
  let &g:directory=$XDG_CACHE_HOME
else
  let &g:directory=$HOME . '/.cache'
endif
let g:ctrlp_cache_dir=&g:directory . '/vim/ctrlp//'
let &g:undodir=&g:directory . '/vim/undo//'
let &g:backupdir=&g:directory . '/vim/backup//'
let g:vim_tags_cache_dir = &g:directory . '/vim/ctags//'
let &g:directory.='/vim/swap//'
" Create directories if they doesn't exist
if ! isdirectory($XDG_STATE_HOME . '/vim')
  silent! call mkdir($XDG_STATE_HOME . '/vim')
endif
if ! isdirectory(expand(&g:directory))
  silent! call mkdir(expand(&g:directory), 'p', 0700)
endif
if ! isdirectory(expand(&g:backupdir))
  silent! call mkdir(expand(&g:backupdir), 'p', 0700)
endif
if ! isdirectory(expand(&g:undodir))
  silent! call mkdir(expand(&g:undodir), 'p', 0700)
endif
if ! isdirectory(expand(g:vim_tags_cache_dir))
  silent! call mkdir(expand(g:vim_tags_cache_dir), 'p', 0700)
endif
""" /Copied from /usr/share/vim/vimfiles/archlinux.vim


" Ne pas sauver un backup spécial pour les fichiers réseau
let g:netrw_dirhistmax = 0

" ---------- Mappings ---------------------------
" map  : Normal, Visual, Select, Operator-pending
" map! : Insert and Command-line

" Le BackSpace fonctionne aussi en mode normal.
map <BS> X

" Les Control-flèches
map  <ESC>[1;5A <C-Up>
map! <ESC>[1;5A <C-Up>
map  <ESC>[1;5B <C-Down>
map! <ESC>[1;5B <C-Down>
map  <ESC>[1;5C <C-Right>
map! <ESC>[1;5C <C-Right>
map  <ESC>[1;5D <C-Left>
map! <ESC>[1;5D <C-Left>

map  <S-Up> {
map! <S-Up> <C-O>{
map  <S-Down> }
map! <S-Down> <C-O>}


" ---------- Comportement à la frappe -----------
" <BS> passe à travers l'indentation, les fins de ligne et le début du "insert"
set backspace=indent,eol,start

" '<BS>e écrit un é (sinon : ctrl+K ' e)
" set digraph

" La taille d'une ligne, pour la frappe au kilomètre.
" Permet 4 niveaux de 'citation' pour les mails/forum
set textwidth=72
" set textwidth=80

" Les touches qui font passer à la ligne suivante/précédente. backspace (b),
" espace (s), flèches (<,>,[,]).
set whichwrap=b,s,<,>,[,]

" Ne pas mettre deux espaces après la ponctuation quand on "join" deux lignes
set nojoinspaces

" Quand on tape un ), vim montre furtivement le ( correspondant.
set showmatch

" Les options de formatage.
set formatoptions=tcq2


" ---------- Recherche --------------------------
" Pour voir tous les matchs d'une recherche
set hlsearch

" Pour que les matchs soient affichés pendant que vous tapez le mot recherché
set incsearch

" On ignore la casse des caractères dans les recherches de chaînes en
" minuscules; par contre, dès qu'une lettre est en majuscule, on tient compte
" de la casse de toute la chaîne.
" Pendant la recherche : \c pour ignorer quand même, \C pour case-sensitive
set ignorecase
set smartcase


" ---------- Fichiers ---------------------------
" Pour une complétion automatique des noms de fichiers
set wildmenu

" La façon dont la complétion présente les choix.
set wildmode=longest,list:longest,full

" La complétion automatique ignore les fichiers suivants.
set suffixes=.bak.o.aux.dvi.log.toc.tof


" ---------- Buffers ----------------------------
" On veut pouvoir rendre invisible un buffer
set hidden

" Pour éviter de trop ralentir en faisant défiler le texte pendant l'exécution
" des macros.
set lazyredraw


" ----------- Interactions ----------------------
" On affiche en permanence les numéros de ligne et de colonne.
set ruler

" Pour ne pas se faire bipper tout le temps.
set noerrorbells
set visualbell t_vb=

" Pour avoir des messages de vim qui tiennent sur une seule ligne, ce
" qui évite d'avoir à presser «Enter» pour voir les messages suivants.
set shortmess=filnrxoOt

" Quand on tape une commande complexe en mode normal, vim affiche ce que l'on
" a déjà tapé
set showcmd


" ------------ Indentations ---------------------
" Conserve l'indentation
set autoindent

" Remplace les <Tab> par des espaces
set expandtab

" Nombre d'espaces
set shiftwidth=2
set softtabstop=2

" Pour que l'indentation ajuste sur un multiple de 'shiftwidth'.
set shiftround

" ------------ Folding --------------------------
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=0
set foldlevelstart=0


" ------------ Auto-commandes -------------------
" On commence par enlever toutes les autocommandes avant de les définir
" (pour le cas où ce fichier serait lu plusieurs fois.) 
autocmd!

autocmd BufRead,BufNewFile mutt*[0-9] set nobackup nowritebackup
autocmd BufRead,BufNewFile .article.* set filetype=mail nobackup

" ledger
" Don't load ftplugin for ledger
" autocmd BufReadPre,BufNewFile *ledger* let b:did_ftplugin = 1
autocmd FileType ledger set textwidth=0
let g:ledger_main = '~/.ledger/perso'

autocmd FileType puppet set textwidth=0

" ----------- Coloration syntaxique -------------
syntax enable
 
highlight Comment     term=none      ctermfg=darkCyan cterm=none
highlight Constant    term=underline ctermfg=Blue     cterm=none
highlight Error       term=reverse   ctermfg=White    ctermbg=Red   cterm=none
highlight Identifier  term=none      ctermfg=Green    cterm=none
highlight IncSearch   term=reverse   ctermfg=Blue     ctermbg=White
highlight Operator    term=none      ctermfg=darkGray cterm=bold
highlight PreProc     term=underline ctermfg=Magenta  cterm=none
highlight Search      term=reverse   cterm=reverse
highlight Special     term=bold      ctermfg=Blue     cterm=bold
highlight Statement   term=bold      ctermfg=Red      cterm=none
highlight Todo        term=standout  ctermfg=White    ctermbg=Green cterm=bold 
highlight Type        term=bold      ctermfg=Brown    cterm=none

highlight link Delimiter   Operator  
highlight link SpecialChar Special

" lignes "foldées"
highlight Folded      term=standout  ctermfg=White   ctermbg=Blue cterm=bold

" Pour les diffs (commande vimdiff).
highlight DiffAdd     term=bold      ctermfg=Green   ctermbg=none cterm=bold
highlight DiffChange  term=bold      ctermfg=Cyan    ctermbg=none
highlight DiffDelete  term=bold      ctermfg=Red     ctermbg=none cterm=bold
highlight DiffText    term=standout  ctermfg=White   ctermbg=Cyan cterm=bold

" ------------- Fonctions, commandes, macros ----
" Identer les fichiers (json, xml)
function PRangeFunc(command_line, syntax) range
  if a:firstline==1 && a:lastline==line('$')
    execute 'set filetype=' . a:syntax
    execute 'syntax on'
  endif
  execute a:firstline . "," . a:lastline . '!' . a:command_line
endfunction

command -range=% Pjson normal <Esc>`>a<CR><Esc>mb`<i<CR><Esc>ma:'a,'b-1 call PRangeFunc('python -m json.tool', 'json')<CR>
command -range=% Pxml  normal <Esc>`>a<CR><Esc>mb`<i<CR><Esc>ma:'a,'b-1 call PRangeFunc('xmllint --format --encode UTF8 -', 'xml')<CR>
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>
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>
command! -range=% Pastebin execute <line1> . "," . <line2> . "w !curl -F 'c=@-' https://ptpb.pw"

vmap <F8> :Pxml<CR>
vmap <F9> :Pjson<CR>

" gpg-encryptes files
let g:GPGPreferArmor=1
let g:GPGDefaultRecipients=["ismael.bouya@normalesup.org"]
let g:GPGUsesPipes=1

command Decrypt 1,$!gpg -d -q
command Encrypt 1,$!gpg -e -q --armor -r ismael.bouya@normalesup.org
command -range=% Runhash s/:\([_a-zA-Z0-9]\+\)\( \+\)=> \( *\)/\1:\2\3/

function! s:DiffWithSaved()
  let filetype=&ft
  diffthis
  vnew | r # | normal! 1Gdd
  diffthis
  exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
command! DiffSaved call s:DiffWithSaved()

" Load NERDTree on startup if no file were specified
" autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" Load NERDTree on startup
"autocmd VimEnter * NERDTree | wincmd p
let g:vim_tags_auto_generate = 1
let g:vim_tags_project_tags_command = "ctags -R {OPTIONS} {DIRECTORY} 2>/dev/null"
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>

let g:ctrlp_extensions = ['tag', 'buffertag', 'dir', 'undo', 'line']
set modeline

set grepprg=grep\ -rn\ $*\ /dev/null
let c_comment_strings=1
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif

set list
set listchars=tab:>-,trail:-