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