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