summaryrefslogblamecommitdiff
path: root/dotfiles/tools/vimrc
blob: fcd9f17fb7e3f461d905ca705399c3b283402a74 (plain) (tree)

































                                                                                                         
                             


































































































































































































































                                                                                                                                                                                                            
                            











































                                                                                  
" ---------- 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'
Plug 'Chiel92/vim-autoformat'

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"

noremap <F3> :Autoformat<CR>
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:-