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