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