config/.vimrc
2015-06-30 15:46:20 +02:00

441 lines
12 KiB
VimL

"""""""""""""
" SHORTCUTS "
"""""""""""""
" F1 help
" F2 open file
" F3 search
" F4 open include file
" F5 find C symbol
" F6 go to definition
" F7 go to calls
" F8 view tag list
" S-F8 build ctags/cscope databases
" M-F8 build kernel ctags/cscope databases
" S-F9 build cscope in .vim/cscope
" F9 Search cscopeDB in .vim/cscope
" M-F9 diff tool
" F10 folding
" F11 unhighlight search
" F12 paste mode
" C-left/right switch tab
" C-up/down switch window
" M-left/right horizontal size
" M-up/down vertical size
" Use snippets with tab e.g : for <tab> (see .vim/snippets for available
" snippets)
"""""""""""
" GENERAL "
"""""""""""
" disable vi-compatible mode
set nocompatible
""""""""
" SAVE "
""""""""
" disable backup
set nobackup
" save before compilation
set autowrite
" jump to last known position when reopening a file
if has("autocmd")
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute "normal! g`\"" |
\ endif
endif
" command line history
set history=50
" Check that file have not been changed
" CursorHold : after cursor move
" WinEnter or BufWinEnter
au WinEnter * checktime
au BufWinEnter * checktime
"""""""""
" INPUT "
"""""""""
" allow backspacing in insert mode
set backspace=indent,eol,start
" don't use Ex mode, use Q for formatting
map Q gq
" disable mouse
set mouse=a
" key combination timeout
set notimeout
"set timeoutlen=4000
" set timeout for multicharacter keys codes (like <F1>)
set ttimeout
" set timeout to tenth of a second (could be increased for slow terminals)
set ttimeoutlen=100
" key event timeout
set updatetime=1000
"""""""""""
" DISPLAY "
"""""""""""
" highlight the cursor line
set cursorline
" show the status line
set laststatus=2
" show the cursor position
set ruler
" show mode
set showmode
" display incomplete commands
set showcmd
" display line number"
set number
" set status line
set statusline=%<%f\ %h%w%m%r%3.(\ %)%{fugitive#statusline()}%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P
" always display status line
set laststatus=2
" show bad white spaces
let c_space_errors = 1
let python_space_error_highlight = 1
highlight link cSpaceError SpaceError
highlight link pythonSpaceError SpaceError
highlight SpaceError ctermfg=235 cterm=reverse
"""""""""""""""
" INDENTATION "
"""""""""""""""
" use tabs at the start of a line, spaces elsewhere
set smarttab
set smartindent
set autoindent
" tab=4
set tabstop=4
set softtabstop=4
set shiftwidth=4
" real tabs
" set noexpandtab
if has("autocmd")
" python
" autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab
autocmd BufRead,BufNewFile *.py syntax on
autocmd BufRead,BufNewFile *.py set ai
autocmd BufRead,BufNewFile *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd BufRead,BufNewFile *.py set tabstop=4
autocmd BufRead,BufNewFile *.py set expandtab
autocmd BufRead,BufNewFile *.py set shiftwidth=4
autocmd BufRead,BufNewFile *.py set softtabstop=4
autocmd BufRead,BufNewFile *.py set modeline
autocmd BufRead,BufNewFile *.py set ft=python
endif
if has("autocmd")
autocmd BufRead,BufNewFile *.iris set ft=python
endif
" vim -b : edit binary using xxd-format!
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END
if has("autocmd")
" enable file type detection and do language-dependent indenting
" filetype plugin indent on
" detect indentation see http://www.freehackers.org/Indent_Finder
autocmd BufReadPost * execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output "' . expand('%') . '"' )
else
" auto-indent
set autoindent
" smart-indent
set smartindent
" C-indent
"set cindent
" indent-expr
"set indentexpr ""
endif
""""""""""
" SEARCH "
""""""""""
" highlight search
set hlsearch
" unhighlight current search
map <silent> <F11> :nohlsearch<CR>
imap <F11> <ESC><F11>a
" highlight search while typing
set incsearch
" show matching brackets -> key %
set showmatch
" tenths of a second before blink matching brackets
set mat=5
" % match if/then/else/...
runtime macros/matchit.vim
" search word and list lines to jump with F3
map <F3> [I:let nr = input("Which one: ") <Bar>execute "normal " . nr ."[\t"<CR>
" go to declaration with F5
" map <silent> <F5> gd:nohlsearch<CR>
" imap <F5> <ESC><F5>i
" try to go to definition or declaration with , and go back with ;
function GoToDefinition()
try
execute "cscope find g " . expand("<cword>")
catch /:E259:/
try
execute "tag " . expand("<cword>")
catch /:E257:/
execute "normal! gd"
execute "nohlsearch"
endtry
endtry
endfunction
nmap <silent> , :call GoToDefinition()<CR>
nmap <silent> ; <C-t>
" plugin taglist
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Process_File_Always = 1
let Tlist_Exit_OnlyWindow = 1
"let Tlist_Close_On_Select = 1
let Tlist_Auto_Highlight_Tag = 1
let Tlist_Display_Prototype = 0
let Tlist_Display_Tag_Scope = 0
let Tlist_Show_One_File = 1
let Tlist_Compact_Format = 1
let Tlist_Enable_Fold_Column = 0
"let Tlist_File_Fold_Auto_Close = 1
let Tlist_Inc_Winwidth = 0
"let Tlist_Use_Horiz_Window = 1
let Tlist_Use_Right_Window = 1
" open/close tag list window with F8
map <silent> <F8> :TlistToggle<CR>
" cat Makefile | grep '\-I\/' | tr '[:space:]' '\n' | grep '\-I/' | sort -u | tr '\n' ' '
" build tags database with shift+F8 or alt+F8 to ignore /usr/include
" --c++-kinds=+p : Adds prototypes in the database for C/C++ files.
" --fields=+iaS : Adds inheritance (i), access (a) and function
" signatures (S) information.
" --extra=+q : Adds context to the tag name. Note: Without this
" option, the script cannot get class members.
command! CtagsBuild
\ :!echo 'building ctags database...' ;
\ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p &&
\ echo 'adding system headers...' ;
\ find -exec gcc -M '{}' \; 2>&- | tr '[:space:]' '\n' | grep '^/.*' | sort -u |
\ ctags --c-kinds=+px --c++-kinds=+px --fields=+iaS --extra=+q -aL-
command! CtagsKernelBuild
\ :!echo 'building ctags database in kernel mode...' ;
\ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p
command! CscopeBuild
\ :!echo 'building cscope database...' ;
\ cscope -bR
command! CscopeKernelBuild
\ :!echo 'building cscope database in kernel mode...' ;
\ cscope -bkR
if has("cscope")
map <S-F8> :CtagsBuild<CR><CR>:CscopeBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>
map <M-F8> :CtagsKernelBuild<CR><CR>:CscopeKernelBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>
else
map <S-F8> :CtagsBuild<CR><CR>
map <M-F8> :CtagsKernelBuild<CR><CR>
endif
if has("cscope")
map <F9> :call GetCscopeDb(expand("%:p:h")) <CR><CR>
map <S-F9> :call GenerateCscopeDb() <CR><CR>
endif
" close preview window after a completion
if has("autocmd")
autocmd CursorMovedI *.{[hc],cpp} if pumvisible() == 0|pclose|endif
autocmd InsertLeave *.{[hc],cpp} if pumvisible() == 0|pclose|endif
endif
function! TagInNewTab()
let word = expand("<cword>")
redir => tagsfiles
silent execute 'set tags'
redir END
tabe
execute 'setlocal' . strpart(tagsfiles, 2)
execute 'tag ' . word
endfunction
nmap <S-Enter> :call TagInNewTab()<CR>
"""""""""
" PASTE "
"""""""""
" set/unset paste mode with F12/shift+F12
map <F12> :set paste<CR>
map <S-F12> :set nopaste<CR>
imap <F12> <C-O>:set paste<CR>
imap <S-F12> <nop>
set pastetoggle=<S-F12>
" paste with reindent with Esc prefix
nnoremap <Esc>P P'[v']=
nnoremap <Esc>p p'[v']=
""""""""""
" WINDOW "
""""""""""
" create window below or at right of the current one
set splitbelow
set splitright
" if multiple windows
if bufwinnr(1)
" vertically increase/decrease window size with alt+up/alt+down
map <M-Up> <C-W>+
map <M-Down> <C-W>-
imap <M-Up> <ESC><M-Up>a
imap <M-Down> <ESC><M-Down>a
" horizontally increase/decrease window size with alt+right/alt+left
map <M-Right> <C-W>>
map <M-Left> <C-W><
imap <M-Right> <ESC><M-Right>a
imap <M-Left> <ESC><M-Left>a
" switch to next/previous tab with ctrl+right/ctrl+left
map <C-Right> gt
map <C-Left> gT
imap <C-Right> <ESC><C-Right>a
imap <C-Left> <ESC><C-Left>a
" switch to next/previous window with ctrl+down/ctrl+up
map <C-Down> <C-W>w
map <C-Up> <C-W>W
imap <C-Down> <ESC><C-Down>a
imap <C-Up> <ESC><C-Up>a
endif
" open automatically quickfix window
if has("autocmd")
autocmd QuickFixCmdPost * cw
endif
" open a file in the same directory as the current file with F2 and split with shift+F2
map <F2> :tabe <C-R>=expand("%:h") . "/"<CR>
nmap <S-F2> :split <C-R>=expand("%:h") . "/"<CR>
""""""""
" HELP "
""""""""
" allow embedded man page
runtime! ftplugin/man.vim
" show vimrc with shift+F1
nmap <silent> <S-F1> :tabe ~/.vimrc<CR>gg
"imap <F1> <Esc><S-F1>
" show contextual help with F1
function Help()
try
if b:current_syntax == "python"
:call ShowPyDoc(expand("<cword>"), 1)
else
execute "Man " . expand("<cword>")
endif
catch /:E149:/
execute "help " . expand("<cword>")
endtry
endfunction
nmap <silent> <F1> :call Help()<CR>
imap <F1> <Esc><F1>
" show VIM help with alt+shift+F1
nmap <silent> <M-S-F1> :help <C-R>=expand("<cword>")<CR><CR>
imap <M-S-F1> <Esc><M-S-F1>
"""""""""
" TOOLS "
"""""""""
" show current changes with F9
command! DiffOrig
\ vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis
map <M-F9> :DiffOrig<CR>
imap <M-F9> <ESC><M-F9>a
" show git diff when committing
let g:git_diff_spawn_mode = 1
if has("autocmd")
autocmd BufRead,BufNewFile COMMIT_EDITMSG setf git
endif
" zf#j creates a fold from the cursor down # lines.
"zf/string creates a fold from the cursor to string .
"zj moves the cursor to the next fold.
"zk moves the cursor to the previous fold.
"zo opens a fold at the cursor.
"zO opens all folds at the cursor.
"zm increases the foldlevel by one.
"zM closes all open folds.
"zr decreases the foldlevel by one.
"zR decreases the foldlevel to zero -- all folds will be open.
"zd deletes the fold at the cursor.
"zE deletes all folds.
"[z move to start of open fold.
"]z move to end of open fold.
" fold form this bracket
nmap <F10> zfa{<CR><CR>
" unfold or use End
nmap <S-F10> zo<CR><CR>
" Autosave folding
"au BufWinLeave * mkview
" Autoload folding
"au BufWinEnter * silent loadview
""""""""""""""""""""""""""""""""""""""""""""""""""
"Omni-completion par CTRL-X_CTRL-O
"""""""""""""""""""""""""""""""""""""""""""""""""""
au FileType html set omnifunc=htmlcomplete#CompleteTags
au FileType css set omnifunc=csscomplete#CompleteCSS
au FileType javascript set omnifunc=javascriptcomplete#CompleteJS
au FileType c set omnifunc=ccomplete#Complete
au FileType php set omnifunc=phpcomplete#CompletePHP
au FileType ruby set omnifunc=rubycomplete#Complete
au FileType sql set omnifunc=sqlcomplete#Complete
au FileType python set omnifunc=pythoncomplete#Complete
au FileType xml set omnifunc=xmlcomplete#CompleteTags
" Enable omnicppcompletion
set nocp
filetype plugin on
let OmniCpp_ShowAccess = 0
let OmniCpp_LocalSearchDecl=1
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
set path=.,..,/usr/local/include,/usr/include
" Will search from current dir to home
set tags+=./tags;$HOME
set tags+=./tags " in file directory
set tags+=tags " in current directory
"for when programming in build dir
set tags+=../tags
"set tags+=~/vim/tags/systags
""""""""""""""""""""""""""""""""""""""""""""""""""
"Poser une marque visible avec F7
"""""""""""""""""""""""""""""""""""""""""""""""""""
"hi Mark guibg=indianred guifg=white gui=bold cterm=bold ctermfg=7 ctermbg=1
"sign define mark text=!> texthl=Mark
"map <F7> :exe 'sign place 001 name=mark line='.line(".").' buffer='.winbufnr(0)<CR>
"map <C-F7> :sign unplace<CR>
"""""""""""""
" Latex "
"""""""""""""
" package vim-latexsuite
" Insert the following line in your ~/.vim/ftplugin/tex.vim file:
" imap <buffer> <leader>it <Plug>Tex_InsertItemOnThisLine
" compile with \ll
set grepprg=grep\ -nH\ $*
let g:tex_flavor = "pdflatex"
imap <buffer> <leader>it <Plug>Tex_InsertItemOnThisLine
let g:Tex_DefaultTargetFormat="pdf"
colorscheme mycolor