.vimrc 7.43 KB
Newer Older
Mathieu Maret's avatar
Mathieu Maret committed
1 2 3
"""""""""""""
" SHORTCUTS "
"""""""""""""
Mathieu Maret's avatar
Mathieu Maret committed
4 5 6
"   F1          help
"   F2          open file in a new tab
" S-F2          Split and open file
Mathieu Maret's avatar
Mathieu Maret committed
7 8
"   F3          autotags Update
" S-F3          autotags Add
Mathieu Maret's avatar
Mathieu Maret committed
9 10 11 12
"   F4          open include file
"   F5          find C symbol
"   F6          go to definition
"   F7          go to calls
Mathieu Maret's avatar
Mathieu Maret committed
13
"   F8          view tag list
Mathieu Maret's avatar
Mathieu Maret committed
14 15
" S-F8          build ctags/cscope databases
" M-F8          build kernel ctags/cscope databases
Mathieu Maret's avatar
Mathieu Maret committed
16 17 18
"   F9          Open NerdTree
" M-F9          Show diff line
" S-F9          Highlight diff line
Mathieu Maret's avatar
Mathieu Maret committed
19 20 21 22
" C-left/right  switch tab
" C-up/down     switch window
" M-left/right  horizontal size
" M-up/down     vertical size
Mathieu Maret's avatar
Mathieu Maret committed
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
"""""""""""
" GENERAL "
"""""""""""
" disable vi-compatible mode
set nocompatible
filetype plugin on
syntax on

""""""""
" 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

Mathieu Maret's avatar
Mathieu Maret committed
55 56 57 58 59 60 61
"""""""""
" INPUT "
"""""""""

" Enable mouse for 'a'll mode
set mouse=a

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
"""""""""""
" 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
77 78
" set status line
set statusline=%<%f\ %h%w%m%r%3.(\ %)%{fugitive#statusline()}%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P
79 80 81 82 83 84 85 86 87 88
" 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

Mathieu Maret's avatar
Mathieu Maret committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
"""""""""""""""
" 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
" tab=8
set tabstop=8
set softtabstop=8
set shiftwidth=8
" real tabs
" set noexpandtab

Mathieu Maret's avatar
Mathieu Maret committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
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
        if has('python')
                autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output "' . expand('%') . '"' )
        endif
else
        " auto-indent
        set autoindent
        " smart-indent
        set smartindent
        " C-indent
        "set cindent
        " indent-expr
        "set indentexpr ""
endif
124

Mathieu Maret's avatar
Mathieu Maret committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
""""""""""
" 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


Mathieu Maret's avatar
Mathieu Maret committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
""""""""""
" 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>

Mathieu Maret's avatar
Mathieu Maret committed
180 181 182
colorscheme desert
set nocursorline

Mathieu Maret's avatar
Mathieu Maret committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
""""""""
" HELP "
""""""""
" allow embedded man page
runtime! ftplugin/man.vim
" show vimrc with shift+F1
nmap <silent> <S-F1> :tabe ~/.vimrc<CR>gg
imap <S-F1> <Esc><S-F1>
" show contextual help with F1
function Help()
        try
        if exists('b:current_syntax') && 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>

Mathieu Maret's avatar
Mathieu Maret committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
""""""""""""""""""""""""""""""""""""""""""""""""""
"Omni-completion par CTRL-X_CTRL-O
"""""""""""""""""""""""""""""""""""""""""""""""""""
filetype plugin on
set omnifunc=syntaxcomplete#Complete

" 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

"""""""""""
" NerdTree
"""""""""""
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
map <F9>   :NERDTreeToggle<CR>

"""""""""""
" GitGutter
"""""""""""
map <M-F9> :GitGutterSignsToggle <CR>
map <S-F9> :GitGutterLineHighlightsToggle <CR>

237 238 239
"""""""""
" Plugin"
"""""""""
Mathieu Maret's avatar
Mathieu Maret committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266

" 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
" sort by name or order ?
let Tlist_Sort_Type = "name"
"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>

" 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

267 268 269 270 271 272 273 274 275
"Using vundle
"cf. https://github.com/gmarik/Vundle.vim
":PluginInstall to install them
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

276 277 278 279 280 281
" Show current modified line
Plugin 'airblade/vim-gitgutter'

" Communication with git
Plugin 'tpope/vim-fugitive'

Mathieu Maret's avatar
Mathieu Maret committed
282 283 284 285 286 287
" Omni completion for cpp
Plugin 'vim-scripts/OmniCppComplete'

" Filesystem exploration
Plugin 'scrooloose/nerdtree'

Mathieu Maret's avatar
Mathieu Maret committed
288
" List current file function
289 290
" This version is buggy. Use a local one
"Plugin 'vim-scripts/taglist.vim'
Mathieu Maret's avatar
Mathieu Maret committed
291 292 293 294 295 296 297 298 299

" echofunc -> what is the current function signature
Plugin 'mbbill/echofunc'

" % match if/then/else/html ...
Plugin 'tmhedberg/matchit'

"Syntax checking
Plugin 'scrooloose/syntastic.git'
300
call vundle#end()