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