]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: disable viewdoc plugin
[dotfiles.git] / vim / vimrc
1 " My vimrc file.
2 "
3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
4 "
5
6 " bundles {{{1
7 filetype off
8 set runtimepath& " reset rtp
9 autocmd!
10
11 set runtimepath+=$XDG_DATA_HOME/vim/vundle
12 call vundle#rc('$XDG_DATA_HOME/vim')
13
14 Bundle 'gmarik/vundle'
15
16 Bundle 'bling/vim-airline'
17 Bundle 'elzr/vim-json'
18 Bundle 'rking/ag.vim'
19 Bundle 'http://git.code.sf.net/p/vim-latex/vim-latex'
20 Bundle 'kien/ctrlp.vim'
21 Bundle 'kshenoy/vim-signature'
22 Bundle 'majutsushi/tagbar'
23 Bundle 'scrooloose/nerdtree'
24 Bundle 'scrooloose/syntastic'
25 Bundle 'sjl/gundo.vim'
26 Bundle 'tomtom/tcomment_vim'
27 Bundle 'tpope/vim-endwise'
28 Bundle 'tpope/vim-fugitive'
29 Bundle 'tpope/vim-repeat'
30 Bundle 'tpope/vim-surround'
31 Bundle 'tpope/vim-unimpaired'
32 Bundle 'valloric/youcompleteme'
33
34 Bundle 'ompugao/ros.vim'
35 Bundle 'ompugao/ctrlp-ros'
36
37 Bundle 'firef0x/pkgbuild.vim'
38 Bundle 'derekwyatt/vim-fswitch'
39 " seems to have problems right now... may be add later?
40 " Bundle 'jalcine/cmake.vim'
41 " Bundle 'powerman/vim-plugin-viewdoc'
42
43 " remove entries first
44 set runtimepath -=$HOME/.vim
45 set runtimepath -=$HOME/.vim/after
46 set runtimepath -=$XDG_CONFIG_HOME/vim
47 set runtimepath -=$XDG_CONFIG_HOME/vim/after
48 " then prepend and append them
49 set runtimepath ^=$XDG_CONFIG_HOME/vim
50 set runtimepath +=$XDG_CONFIG_HOME/vim/after
51
52 filetype plugin indent on
53
54 " bindings {{{1
55 " allow both <space> and / to be <leader>
56 map <space> <leader>
57 nnoremap <leader><cr> :make<cr>
58
59 " moving around, searching and patterns {{{1
60 set incsearch " show match for partly typed search command
61 set ignorecase " ignore case when using a search pattern
62 set smartcase " override 'ignorecase' when pattern has upper case characters
63 set hlsearch " highlight all matches for the last used search pattern
64
65 " use leader-n to unhighlight search
66 nmap <silent> <Leader>n :silent nohl<CR>
67 " use leader-# to display the number of matches for the last search
68 nmap <Leader># :%s:<C-R>/::gn<CR>
69 " center cursor after search
70 nnoremap n nzz
71
72 " disable arrows
73 noremap <Up> <NOP>
74 noremap <Down> <NOP>
75 noremap <Left> <NOP>
76 noremap <Right> <NOP>
77 inoremap <Up> <NOP>
78 inoremap <Down> <NOP>
79 inoremap <Left> <NOP>
80 inoremap <Right> <NOP>
81 cnoremap <Up> <NOP>
82 cnoremap <Down> <NOP>
83 cnoremap <Left> <NOP>
84 cnoremap <Right> <NOP>
85 cnoremap <C-K> <Up>
86 cnoremap <C-J> <Down>
87 cnoremap <C-H> <Left>
88 cnoremap <C-L> <Right>
89
90 set nostartofline " don't move the cursor to the first non-blank char of a line
91 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
92
93 " displaying text {{{1
94 set scrolloff=5 " number of screen lines to show around the cursor
95 set nowrap " long lines wrap
96 set linebreak " wrap long lines at a character in 'breakat'
97 set showbreak=▒▒ " show these chars for wrapped lines
98
99 set lazyredraw " don't redraw while executing macros
100
101 set list " show chars defined in 'listchars'
102 set listchars=tab:»·,trail:· " list of strings used for list mode
103 set listchars+=extends:⋯,precedes:⋯
104 set sidescrolloff=1 " don't scroll over the listchars
105
106 set number " show the line number for each line
107 set relativenumber " show the relative line number for each line
108 " toggle relativenumber
109 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
110
111 if has("autocmd")
112 " When editing a file, always jump to the last known cursor position.
113 " Don't do it when the position is invalid or when inside an event handler
114 " (happens when dropping a file on gvim).
115 " Also don't do it when the mark is in the first line, that is the default
116 " position when opening a file.
117 " blacklist certain filetype, you can get a file type with :echo &ft
118 let blacklist = ['gitcommit']
119 autocmd BufReadPost *
120 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
121 \ exe "normal! g`\"" |
122 \ endif
123 endif
124
125
126 " syntax, highlighting and spelling {{{1
127 colorscheme badwolf
128 syntax on
129
130 set dictionary=spell " list of dictionary files for keyword completion
131 " Spell Check http://tex.stackexchange.com/a/52932
132 let b:myLang=0
133 let g:myLangList=["en_gb","en_us","de","fr"]
134
135 function! ToggleSpell()
136 execute "setlocal spell!"
137 if (&spell)
138 echo "setlocal spelllang=" g:myLangList[b:myLang]
139 endif
140 endfunction
141 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
142
143 function! SwitchSpell()
144 if (&spell)
145 let b:myLang=b:myLang+1
146 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
147 endif
148 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
149 echo "setlocal spelllang=" g:myLangList[b:myLang]
150 endfunction
151 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
152
153 " fix spelling with first choice
154 nnoremap <Leader>f 1z=
155
156 if has("autocmd")
157 au Filetype *
158 \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
159 endif
160
161 " multiple windows {{{1
162 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
163
164 set previewheight=20 " default height for the preview window
165
166 set splitright " a new window is put right of the current one
167
168 map <F1> :ls<CR>:b<space>
169
170 nmap <C-L> <C-W>w
171 nmap <C-H> <C-W>W
172
173 " using the mouse {{{1
174 set mouse=rnv " list of flags for using the mouse
175 set ttymouse=xterm " type of mouse
176
177 "xterm mouse with middleclick paste
178 nnoremap <MiddleMouse> i<MiddleMouse>
179 vnoremap <MiddleMouse> s<MiddleMouse>
180
181 " messages and info {{{1
182 set showcmd " Show (partial) command in status line.
183 set ruler " show the cursor position all the time
184 set confirm " Ask what to do when closing unsaved documents
185 set shortmess=filnxtoOI " don't show intro message
186
187 " editing text {{{1
188 set backspace=indent,eol,start " allow backspacing over everything in insert mode
189
190 set showmatch " Show matching brackets.
191
192 set nojoinspaces " don't use two spaces after '.' when joining a line
193 set formatoptions+=j " remove comment leader when joining lines
194
195 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
196
197 " whether to use a popup menu for Insert mode completion
198 set completeopt=longest,menuone,preview
199
200 " Indent if we're at the beginning of a line. Else, do completion.
201 function! InsertTabWrapper()
202 let col = col('.') - 1
203 if !col || getline('.')[col - 1] !~ '\k'
204 return "\<Tab>"
205 else
206 return "\<C-N>"
207 endif
208 endfunction
209 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
210 inoremap <S-Tab> <C-P>
211
212 " fix legacy vi inconsistency
213 map Y y$
214
215 " allow repeat operator on visual
216 vnoremap . :normal .<CR>
217
218 " add line without changing position or leaving mode
219 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
220 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
221
222 " Don't use Ex mode, use Q for formatting
223 map Q gq
224
225 " allow undoing in insert-mode
226 inoremap <C-U> <C-G>u<C-U>
227 inoremap <C-W> <C-G>u<C-W>
228
229 " tabs and indent {{{1
230 set shiftwidth=4 " number of spaces used for each step of (auto)indent
231 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
232 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
233 set shiftround " round to 'shiftwidth' for "<<" and ">>"
234 set expandtab " expand <Tab> to spaces in Insert mode
235
236 set cindent " use smart C indenting (see :h C-indenting)
237 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
238
239 set pastetoggle=<F11> " key sequence to toggle paste mode
240
241 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
242 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
243 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
244 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
245
246 " folding {{{1
247 set foldmethod=marker " folding type
248 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
249
250 " space will toggle current fold in normal mode
251 nnoremap <leader><Space> za
252 " create folds around visual selection
253 vnoremap <leader><Space> zf
254
255 " save and restore folds
256 set viewoptions=folds,cursor " don't save local options
257 autocmd BufWinLeave *.* mkview
258 autocmd BufWinEnter *.* silent loadview
259
260 " reading and writing files {{{1
261 set writebackup " write a backup file before overwriting a file
262 set backup " keep a backup after owerwriting a file
263 set backupdir=$XDG_CACHE_HOME/vim
264
265 set undofile " persistent undo history
266 set undodir=$XDG_CACHE_HOME/vim
267
268 set autowrite " automatically write a file when leaving a modified buffer
269
270 " save with sudo
271 cmap w!! w !sudo tee % > /dev/null
272
273 " the swap file {{{1
274 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
275
276 " command line editing {{{1
277 set history=500 " how many command lines are remembered
278 set wildmode=longest:full,full " specifies how command line completion works
279 set wildmenu " command-line completion shows a list of matches
280
281 " various {{{1
282 set virtualedit=block " let cursor move past last char in <C-V> mode
283 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
284
285 set viewdir=$XDG_CACHE_HOME/vim
286
287 " plugins {{{1
288 " ag {{{2
289 let g:AgSmartCase = 1
290 nnoremap <leader>ag yiw:Ag \12"<cr>
291 vnoremap <leader>ag y:Ag \12"<cr>
292
293 " airline {{{2
294 let g:airline_detect_whitespace=2
295 let g:airline#extensions#tabline#enabled = 1
296 let g:airline_powerline_fonts = 1
297
298 " GoldenView {{{2
299 "let g:goldenview__enable_default_mapping = 0
300 "nmap <silent> <C-N> <Plug>GoldenViewSplit
301 "nmap <silent> <C-L> <Plug>GoldenViewNext
302 "nmap <silent> <C-H> <Plug>GoldenViewPrevious
303 "nmap <silent> <C-M> <Plug>GoldenViewSwitchMain
304 "nmap <silent> <C-S-M> <Plug>GoldenViewPrevious
305
306 " Gundo {{{2
307 nnoremap <F7> :GundoToggle<CR>
308 " fugitive {{{2
309 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
310 " delete fugitive buffers when closed
311 autocmd BufReadPost fugitive://* set bufhidden=delete
312
313 nnoremap <silent> <leader>gs :Gstatus<CR>
314 nnoremap <silent> <leader>gd :Gdiff<CR>
315 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
316
317 " NERDTree {{{2
318 " open/close NERDTree with \e
319 nmap <Leader>e :NERDTreeToggle<CR>
320 nmap <F6> :NERDTreeToggle<CR>
321 " <space> to open files/dirs
322 let NERDTreeMapActivateNode='<space>'
323 " close vim if only NERDTree is open
324 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
325
326 " synastic {{{2
327 let g:syntastic_enable_highlighting = 0
328 let g:syntastic_error_symbol='E'
329 let g:syntastic_style_error_symbol='S'
330 let g:syntastic_warning_symbol='W'
331 let g:syntastic_style_warning_symbol='S'
332 let g:syntastic_always_populate_loc_list=1
333 nmap <silent> <leader>y :SyntasticCheck<cr>
334
335 if ! &diff
336 let g:syntastic_check_on_open=1
337 endif
338
339 " tagbar {{{2
340 map <F5> :TagbarToggle<cr>
341 let g:tagbar_sort = 0
342 let g:tagbar_compact = 1
343 let g:tagbar_autoshowtag = 1
344 let g:tagbar_width = 25
345 let g:tagbar_iconchars = ['+', '-']
346
347 " YouCompleteMe {{{2
348 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
349 let g:ycm_add_preview_to_completeopt = 1
350 let g:ycm_autoclose_preview_window_after_insertion = 1
351 "let g:ycm_extra_conf_vim_data = ['%:p']
352 nnoremap <leader>jd :YcmCompleter GoTo<CR>
353
354 " vim-json {{{2
355 let g:vim_json_syntax_conceal = 0
356
357 " vim-latex {{{2
358 let g:tex_flavor='latex'
359 let g:Tex_DefaultTargetFormat='pdf'
360 let g:Tex_MultipleCompileFormats='pdf'
361
362 " " vim-viewdoc {{{2
363 " let g:no_viewdoc_maps = 1
364 " nnoremap K :call ViewDoc('doc', '<cword>')<cr>
365
366 " functions {{{1
367 " auto source vimrc when saved
368 autocmd bufwritepost vimrc source $MYVIMRC
369 nmap <leader>v :tabedit $MYVIMRC<CR>
370
371 " Convenient command to see the difference between the current buffer and the
372 " file it was loaded from, thus the changes you made.
373 " Only define it when not defined already.
374 if !exists(":DiffOrig")
375 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
376 \ | wincmd p | diffthis
377 endif