From 25e6cc36c7701a782f458bcfbf635be88ac7ab60 Mon Sep 17 00:00:00 2001 From: mathieu Date: Mon, 7 Sep 2009 11:20:15 +0200 Subject: [PATCH] Add vimrc config file --- vimrc | 419 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 419 insertions(+) create mode 100644 vimrc diff --git a/vimrc b/vimrc new file mode 100644 index 0000000..4e03a72 --- /dev/null +++ b/vimrc @@ -0,0 +1,419 @@ +""""""""""""" +" SHORTCUTS " +""""""""""""" +" F1 help +" F2 open file +" F3 search +" F4 open include file +" F5 go to declaration +" F6 go to definition +" F7 go to calls +" F8 view tag list +" S-F8 build 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 + +""""""""""" +" 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 + +""""""""" +" 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= +" key combination timeout +set notimeout +"set timeoutlen=4000 +" set timeout for multicharacter keys codes (like ) +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 + +""""""""""""""" +" 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 +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 :nohlsearch +imap a +" highlight search while typing +set incsearch +" show matching brackets +set showmatch +" tenths of a second before blink matching brackets +set mat=5 +" search word and list lines to jump with F3 +map [I:let nr = input("Which one: ") execute "normal " . nr ."[\t" +" go to declaration with F5 +map gd:nohlsearch +imap i +" try to go to definition or declaration with , and go back with ; +function GoToDefinition() + try + execute "cscope find g " . expand("") + catch /:E259:/ + try + execute "tag " . expand("") + catch /:E257:/ + execute "normal! gd" + execute "nohlsearch" + endtry + endtry +endfunction +nmap , :call GoToDefinition() +nmap ; +" 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 :TlistToggle +" shown current tag in status bar +set statusline=%<%f\ %h%m%r%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P +" plugin omnicppcomplete +let OmniCpp_ShowAccess = 0 +let OmniCpp_LocalSearchDecl=1 +" 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 + set csto=1 + " add any cscope database in current directory + if filereadable("cscope.out") + cscope add cscope.out + " else add the database pointed by environment variable + elseif $CSCOPE_DB != "" + cscope add $CSCOPE_DB + endif + " show message when any other cscope db added + set cscopeverbose + " open include file with F4 and split with shift+F4 + nmap :cscope find f =expand("") + nmap :scscope find f =expand("") + " go to definition with F6 and split with shift+F6 and use ctags with alt+shift+F6 + nmap :cscope find g =expand("") + nmap :scscope find g =expand("") + nmap :tag =expand("") + " go to calls with F7 and split with shift+F7 + nmap :cscope find c =expand("") + nmap :scscope find c =expand("") + " go to ... with 'ctrl+s letter' and go back with ctrl+t + nmap s :cscope find s =expand("") + nmap g :cscope find g =expand("") + nmap c :cscope find c =expand("") + nmap t :cscope find t =expand("") + nmap e :cscope find e =expand("") + nmap f :cscope find f =expand("") + nmap i :cscope find i ^=expand("")$ + nmap d :cscope find d =expand("") + " split to ... with 'ctrl+space letter' + nmap s :scscope find s =expand("") + nmap g :scscope find g =expand("") + nmap c :scscope find c =expand("") + nmap t :scscope find t =expand("") + nmap e :scscope find e =expand("") + nmap f :scscope find f =expand("") + nmap i :scscope find i ^=expand("")$ + nmap d :scscope find d =expand("") + " vertical split to ... with 'ctrl+space ctrl+space letter' + nmap s :vertical scscope find s =expand("") + nmap g :vertical scscope find g =expand("") + nmap c :vertical scscope find c =expand("") + nmap t :vertical scscope find t =expand("") + nmap e :vertical scscope find e =expand("") + nmap f :vertical scscope find f =expand("") + nmap i :vertical scscope find i ^=expand("")$ + nmap d :vertical scscope find d =expand("") + " s symbol find all references to the token under cursor + " g global find global definition of the token under cursor + " c calls find all calls to the function name under cursor + " t text find all instances of the text under cursor + " e egrep egrep search for the word under cursor + " f file open the filename under cursor + " i includes find files that include the filename under cursor + " d called find functions that function under cursor calls +endif +" build tags database with shift+F8 +if has("cscope") + command! TagsBuild + \ :!echo "building ctags and cscope databases..." && + \ ctags --c++-kinds=+p --fields=+iaS --extra=+q -R && + \ cscope -bR + map :TagsBuild:cscope reset +else + command! TagsBuild + \ :!echo "building ctags database..." && + \ ctags --c++-kinds=+p --fields=+iaS --extra=+q -R + map :TagsBuild +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 :set paste +map :set nopaste +imap :set paste +imap +set pastetoggle= +" paste with reindent with Esc prefix +nnoremap P P'[v']= +nnoremap 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 + + map - + imap a + imap a + " horizontally increase/decrease window size with alt+right/alt+left + map > + map < + imap a + imap a + " switch to next/previous tab with ctrl+right/ctrl+left + map gt + map gT + imap a + imap a + " switch to next/previous window with ctrl+down/ctrl+up + map w + map W + imap a + imap 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 :tabe =expand("%:h") . "/" +nmap :split =expand("%:h") . "/" + +"""""""" +" HELP " +"""""""" +" allow embedded man page +runtime! ftplugin/man.vim +" show vimrc with shift+F1 +nmap :sview ~/.vimrcgg +imap +" show contextual help with F1 +function Help() + try + execute "Man " . expand("") + catch /:E149:/ + execute "help " . expand("") + endtry +endfunction +nmap :call Help() +imap +" show VIM help with alt+shift+F1 +nmap :help =expand("") +imap + +""""""""" +" TOOLS " +""""""""" +" show current changes with F9 +command! DiffOrig + \ vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis +map :DiffOrig +imap a +" show git diff when committing +let g:git_diff_spawn_mode = 1 +if has("autocmd") + autocmd BufRead,BufNewFile COMMIT_EDITMSG setf git +endif