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