config/.vimrc

601 lines
20 KiB
VimL
Raw Normal View History

"""""""""""""
" 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
" F9 view changes
" 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
2010-05-04 15:32:13 +02:00
" Use snippets with tab e.g : for <tab> (see .vim/snippets for available
" snippets)
"""""""""""
" GENERAL "
"""""""""""
" disable vi-compatible mode
set nocompatible
2010-03-29 17:08:19 +02:00
" to enable spellchecking :set speell"
" set spell spelllang=fr "
""""""""
" 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
"""""""""
" 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 "
"""""""""""
" color palette
set t_Co=256
" syntax highlighting when the terminal has colors
if &t_Co > 2 || has("gui_running")
syntax on
" my colors
set background=dark
highlight clear
if exists("syntax_on")
syntax reset
endif
if &t_Co == 256
highlight! Normal ctermfg=77 ctermbg=Black
highlight! Statement ctermfg=254 ctermbg=Black
highlight! Comment ctermfg=191 ctermbg=Black
highlight! PreProc ctermfg=200 ctermbg=Black
else
highlight! Normal ctermfg=Green ctermbg=Black
highlight! Statement ctermfg=White ctermbg=Black
highlight! Comment ctermfg=Yellow ctermbg=Black
highlight! PreProc ctermfg=Magenta ctermbg=Black
endif
highlight! Constant ctermfg=Red ctermbg=Black
highlight! def link Structure Statement
highlight! def link StorageClass Statement
highlight! Type ctermfg=Grey ctermbg=Black
highlight! def link Identifier Type
highlight! Todo ctermfg=Black ctermbg=DarkRed
highlight! Search ctermfg=Black ctermbg=Yellow
highlight! def link IncSearch Visual
if &t_Co == 256
highlight! DiffAdd ctermbg=54 cterm=none
highlight! DiffDelete ctermfg=Black ctermbg=54 cterm=none
else
highlight! DiffAdd ctermbg=DarkMagenta cterm=none
highlight! DiffDelete ctermfg=Black ctermbg=DarkMagenta cterm=none
endif
highlight! def link DiffChange DiffAdd
highlight! DiffText ctermfg=White ctermbg=DarkBlue cterm=none
highlight! def link Folded TabLineSel
highlight! def link FoldColumn Folded
highlight! MatchParen ctermbg=Blue
if &t_Co == 256
highlight! BadWhitespace ctermbg=235
elseif &t_Co > 8
highlight! BadWhitespace ctermbg=DarkGrey
else
highlight! BadWhitespace ctermbg=DarkCyan
endif
highlight! Pmenu ctermfg=Grey ctermbg=DarkBlue
if &t_Co > 8
highlight! PmenuSel ctermfg=Yellow ctermbg=Blue
else
highlight! PmenuSel ctermfg=Yellow ctermbg=Cyan
endif
highlight! def link PmenuSbar Pmenu
highlight! PmenuThumb ctermbg=DarkMagenta cterm=none
if &t_Co == 256
highlight! LineNr ctermfg=DarkCyan ctermbg=235
highlight! CursorLine ctermbg=236 cterm=none
else
highlight! LineNr ctermfg=DarkCyan ctermbg=Black
highlight! CursorLine ctermbg=DarkGrey cterm=none
endif
highlight! def link CursorColumn CursorLine
highlight! Visual ctermfg=White ctermbg=Blue cterm=none
highlight! VertSplit ctermfg=Grey ctermbg=Grey cterm=none
highlight! StatusLine ctermfg=Black ctermbg=Grey cterm=none
if &t_Co > 8
highlight! StatusLineNC ctermfg=DarkGrey ctermbg=Grey cterm=none
else
highlight! StatusLineNC ctermfg=Cyan ctermbg=Grey cterm=none
endif
highlight! def link TabLine StatusLineNC
highlight! def link TabLineFill TabLine
if &t_Co == 256
highlight! TabLineSel ctermfg=White ctermbg=235 cterm=none
elseif &t_Co > 8
highlight! TabLineSel ctermfg=White ctermbg=Black cterm=none
else
highlight! TabLineSel ctermfg=White ctermbg=Black
endif
highlight! ModeMsg ctermfg=DarkCyan ctermbg=Black
highlight! WarningMsg ctermfg=Yellow ctermbg=Black
highlight! ErrorMsg ctermfg=Red ctermbg=Black
endif
" 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
"""""""""""""""
" INDENTATION "
"""""""""""""""
if has("autocmd")
" enable file type detection and do language-dependent indenting
filetype plugin indent on
else
" auto-indent
set autoindent
" smart-indent
set smartindent
" C-indent
"set cindent
" indent-expr
"set indentexpr ""
endif
" tab=4
set tabstop=4
set softtabstop=4
set shiftwidth=4
" real tabs
set noexpandtab
" use tabs at the start of a line, spaces elsewhere
set smarttab
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
endif
" define whitespaces at end of line as bad whitespaces
match BadWhitespace /\s\+$/
" define extra spaces at the front of the line as bad whitespaces
match BadWhitespace /^\ \+/
" define redundant whitespaces as bad whitespaces
match BadWhitespace /\s\+$\| \+\ze\t/
""""""""""
" 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
" 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>
" shown current tag in status bar
" set statusline=%<%f\ %h%m%r%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P
" include Git status(plugin vim-fugitiv) and tag name in status
set laststatus=2
"set statusline=%<%f\ %h%w%m%r%3.(\ %)%{fugitive#statusline()}%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P
" if compiled with --enable-cscope
if has("cscope")
" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
set cscopetag
" use ctags before cscope
2009-11-27 14:30:36 +01:00
set csto=0
" add any cscope database in current directory
if filereadable("cscope.out")
cscope add cscope.out
2010-03-04 10:10:31 +01:00
endif
2009-11-27 14:30:36 +01:00
" add the database pointed by environment variable
2010-03-04 10:10:31 +01:00
if $CSCOPE_DB != ""
2009-11-27 14:30:36 +01:00
if filereadable($CSCOPE_DB)
cscope add $CSCOPE_DB
endif
endif
" show message when any other cscope db added
set cscopeverbose
" open include file with F4 and split with shift+F4
nmap <F4> :cscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <S-F4> :scscope find f <C-R>=expand("<cfile>")<CR><CR>
" find this C symbol with F5 and split with shift+F5
2010-09-16 18:18:19 +02:00
nmap <F5> :cscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <S-F5> :scscope find s <C-R>=expand("<cword>")<CR><CR>
" go to definition with F6 and split with shift+F6 and use ctags with alt+shift+F6
nmap <F6> :cscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <S-F6> :scscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <M-S-F6> :tag <C-R>=expand("<cword>")<CR><CR>
" go to calls with F7 and split with shift+F7
nmap <F7> :cscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <S-F7> :scscope find c <C-R>=expand("<cword>")<CR><CR>
" go to ... with 'ctrl+s letter' and go back with ctrl+t
nmap <C-s>s :cscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>g :cscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>c :cscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>t :cscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>e :cscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>f :cscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-s>i :cscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-s>d :cscope find d <C-R>=expand("<cword>")<CR><CR>
" split to ... with 'ctrl+space letter'
nmap <C-@>s :scscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :scscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :scscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :scscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :scscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :scscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@>i :scscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@>d :scscope find d <C-R>=expand("<cword>")<CR><CR>
" vertical split to ... with 'ctrl+space ctrl+space letter'
nmap <C-@><C-@>s :vertical scscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>g :vertical scscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>c :vertical scscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>t :vertical scscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>e :vertical scscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>f :vertical scscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@><C-@>i :vertical scscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@><C-@>d :vertical scscope find d <C-R>=expand("<cword>")<CR><CR>
" s symbol find all references to the token under cursor
" //find this C symbol
" g global find global definition of the token under cursori
" //find this definition
" c calls find all calls to the function name under cursor
" //find function calling this function
" d called find functions that function under cursor calls
" //find function called by this function
" t text find all instances of the text under cursor
" //find this text string
" e egrep egrep search for the word under cursor
" //find this egrep pattern
" f file open the filename under cursor
" //find this file
" i includes find files that include the filename under cursor
" //find files #including this file
endif
2010-05-04 15:32:13 +02:00
" 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
command! CtagsBuild
\ :!echo 'building ctags database...' ;
\ ctags --fields=+iaS --extra=+q --totals -R &&
\ echo 'adding system headers...' ;
2010-05-04 15:32:13 +02:00
\ 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
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>
map <M-F8> :CtagsKernelBuild<CR><CR>:CscopeKernelBuild<CR><CR>:cscope reset<CR><CR>
else
map <S-F8> :CtagsBuild<CR><CR>
map <M-F8> :CtagsKernelBuild<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
"""""""""
" 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
2010-09-21 10:59:10 +02:00
"nmap <silent> <S-F1> :sview ~/.vimrc<CR>gg
"imap <F1> <Esc><S-F1>
" show contextual help with F1
function Help()
try
execute "Man " . expand("<cword>")
catch /:E149:/
execute "help " . expand("<cword>")
endtry
endfunction
nmap <silent> <F1> :call Help()<CR>
2010-09-21 10:59:10 +02:00
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 <F9> :DiffOrig<CR>
imap <F9> <ESC><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
" :set tags+=~/.vim/wxwidgetstags
set tags=tags
"for when programming in build dir
set tags+=../tags
set tags+=~/.vim/qttags
2010-09-21 10:59:10 +02:00
set tags+=~/.vim/qtembedded
" Affichage du prototype d'une fonction sur le
" plugin echofunc
" Eclim
command -range -nargs=* Google call eclim#web#SearchEngine(
\ 'http://www.google.com/search?q=<query>', <q-args>, <line1>, <line2>)
2010-05-04 15:32:13 +02:00
" QT manual with C-b
function! QtClassDoc()
let qt_dir = "/usr/share/qt4/doc/html/"
let class = tolower(expand("<cword>"))
silent execute "!x-www-browser " . qt_dir . class . ".html &>/dev/null" . " &" | redraw!
endfunction
nmap <silent> <C-b> :call QtClassDoc()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""
"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>
function! GetProtoLine()
let ret = ""
let line_save = line(".")
let col_save = col(".")
let top = line_save - winline() + 1
let so_save = &so
let &so = 0
let istypedef = 0
" find closing brace
let closing_lnum = search('^}','cW')
if closing_lnum > 0
if getline(line(".")) =~ '\w\s*;\s*$'
let istypedef = 1
let closingline = getline(".")
endif
" go to the opening brace
normal! %
" if the start position is between the two braces
if line(".") <= line_save
if istypedef
let ret = matchstr(closingline, '\w\+\s*;')
else
" find a line contains function name
let lnum = search('^\w','bcnW')
if lnum > 0
let ret = getline(lnum)
endif
endif
endif
endif
" restore position and screen line
exe "normal! " . top . "Gz\<CR>"
call cursor(line_save, col_save)
let &so = so_save
return ret
endfunction
function! WhatFunction()
if &ft != "c" && &ft != "cpp"
return ""
endif
let proto = GetProtoLine()
if proto == ""
return "?"
endif
if stridx(proto, '(') > 0
let ret = matchstr(proto, '\w\+(\@=')
elseif proto =~# '\<struct\>'
let ret = matchstr(proto, 'struct\s\+\w\+')
elseif proto =~# '\<class\>'
let ret = matchstr(proto, 'class\s\+\w\+')
else
let ret = strpart(proto, 0, 15) . "..."
endif
return ret
endfunction
2010-05-04 15:32:13 +02:00
set statusline=%<%f\ %h%w%m%r%3.(\ %)%{fugitive#statusline()}%=%([%{Tlist_Get_Tagname_By_Line()}%{WhatFunction()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P