Mots-clé : config

vim : configuration

Je partage mon fichier de configuration de vim, si vous avez des suggestions, n’hésitez pas :

set nocompatible
set nocompatible
filetype plugin on
syntax enable

set ignorecase
set paste
set ruler
set modeline

set showcmd

set nowrap
set textwidth=0
set wrapmargin=0
let g:leave_my_textwidth_alone=1

set expandtab
set autoindent
set smartindent
set softtabstop=4
set tabstop=4

" Dans un fichier php, lorsqu'on tape {<CR> alors
" il fait l'indentation automatique
set shiftwidth=4

set number
colorscheme desert
colorscheme torte
colorscheme zellner

set vb t_vb=

set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp
set fileencodings=utf-8,ucs-bom,default,latin1
set scrolloff=5
set scrolloff=15
set undolevels=1000
nmap ;bw :. w! ~/.vimxfer<CR>
nmap ;br :r ~/.vimxfer<CR>
nmap ;ba :. w! >>~/.vimxfer<CR>

" Pour la macro gset, après j'utilise F3 :
" ça sert à transformer les trucs du genre :
" - @return string le nom ajouté ...
" par :
" - @return string Nom ajouté ...
map <F3> ^3w/ [a-zA-Z]<CR><RIGHT>v/\( \\|'\)<CR>xvU
" Macro qui réindente le bloc courant d'une seule tab à droite :
map <F4> Vi{9<lt>Vi{>

" Tell vim to remember certain things when we exit
"  '10 : marks will be remembered for up to 10 previously edited files
"  "100 : will save up to 100 lines for each register
"  :20 : up to 20 lines of command-line history will be remembered
"  % : saves and restores the buffer list
"  n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo

" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
 au!
 autocmd BufReadPost *
 \ if expand("<afile>:p:h") !=? $TEMP |
 \ if line("'\"") > 1 && line("'\"") <= line("$") |
 \ let JumpCursorOnEdit_foo = line("'\"") |
 \ let b:doopenfold = 1 |
 \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
 \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
 \ let b:doopenfold = 2 |
 \ endif |
 \ exe JumpCursorOnEdit_foo |
 \ endif |
 \ endif
 " Need to postpone using "zv" until after reading the modelines.
 autocmd BufWinEnter *
 \ if exists("b:doopenfold") |
 \ exe "normal zv" |
 \ if(b:doopenfold > 1) |
 \ exe "+".1 |
 \ endif |
 \ unlet b:doopenfold |
 \ endif
augroup END

set backspace=2

inoremap <silent> <Bar>   <Bar><Esc>:call <SID>align()<CR>a

function! s:align()
  let p = '^\s*|\s.*\s|\s*$'
  if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
    let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
    let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
    Tabularize/|/l1
    normal! 0
    call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  endif
endfunction

autocmd BufNewFile  * silent! 0r ~/.vim/templates/%:e.tpl
autocmd BufNewFile  *.php call search('w', '', line("w$"))
autocmd BufNewFile,BufRead *.vhost.conf set filetype=apache
autocmd BufNewFile,BufRead *.json set filetype=yaml

let g:snips_author='Olivier Pons'
let g:snips_author_email='olivier.pons@gmail.com'

" ----------------------------------------
" Smarty syntax highlighter / Rappel il est dans ~/.vim/syntax
" Pris ici http://www.vim.org/scripts/script.php?script_id=1798 :
autocmd BufRead,BufNewFile *.tpl set filetype=smarty

" ----------------------------------------
" Truc de Stackoverflow : si ouverture d'un fichier htm(l) alors
" verifier s'il y a {* *} ou {(alphanum) $xx (alphanum)}
" et si c'est le cas appliquer la syntaxe Smarty (au dessus)
autocmd BufNewFile,BufRead *.htm call s:CheckForSmarty()
autocmd BufNewFile,BufRead *.html call s:CheckForSmarty()

function! s:CheckForSmarty()
  for n in range(1, line('$'))
    "if n > 100
    "  return
    "endif

    let line = getline(n)
    if line =~ '{.*$\k\+}' || line =~ '{\*.*\*}'
      set filetype=smarty
      return
    endif
  endfor
endfunction

" (!) Ultra important sinon *tous* les mappings sont désactivés :
set nopaste

" Code will highlight trailing whitespace in red:
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/

"highlight OverLength ctermbg=red ctermfg=white guibg=#592929
"match OverLength /\%>80v.\+/
set textwidth=80
set colorcolumn=+1
highlight ColorColumn ctermbg=8
highlight Folded term=standout ctermfg=216 guifg=1 guibg=2 ctermbg=8

" Raccourci : F7 = ouvrir le fichier sous le curseur, F8 = ouvrir en vsplit :
:nnoremap <F8> :vertical wincmd f<CR>
:nnoremap <F7> :wincmd f<CR>