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