]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vimrc: don't show info message on startup
[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=.,** " current + subdirectory search for :find, :grep:, ...
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 " using the mouse {{{1
142 set mouse=rnv " list of flags for using the mouse
143 set ttymouse=xterm " type of mouse
144
145 "xterm mouse with middleclick paste
146 nnoremap <MiddleMouse> i<MiddleMouse>
147 vnoremap <MiddleMouse> s<MiddleMouse>
148
149 " messages and info {{{1
150 set showcmd " Show (partial) command in status line.
151 set ruler " show the cursor position all the time
152 set confirm " Ask what to do when closing unsaved documents
153 set shortmess=filnxtoOI " don't show intro message
154
155 " editing text {{{1
156 set backspace=indent,eol,start " allow backspacing over everything in insert mode
157
158 set showmatch " Show matching brackets.
159
160 set nojoinspaces " don't use two spaces after '.' when joining a line
161 set formatoptions+=j " remove comment leader when joining lines
162
163 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
164
165 " whether to use a popup menu for Insert mode completion
166 set completeopt=longest,menuone,preview
167
168 " Indent if we're at the beginning of a line. Else, do completion.
169 function! InsertTabWrapper()
170 let col = col('.') - 1
171 if !col || getline('.')[col - 1] !~ '\k'
172 return "\<Tab>"
173 else
174 return "\<C-N>"
175 endif
176 endfunction
177 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
178 inoremap <S-Tab> <C-P>
179
180 " fix legacy vi inconsistency
181 map Y y$
182
183 " allow repeat operator on visual
184 vnoremap . :normal .<CR>
185
186 " add line without changing position or leaving mode
187 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
188 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
189
190 " Don't use Ex mode, use Q for formatting
191 map Q gq
192
193 " allow undoing in insert-mode
194 inoremap <C-U> <C-G>u<C-U>
195 inoremap <C-W> <C-G>u<C-W>
196
197 " tabs and indent {{{1
198 set shiftwidth=4 " number of spaces used for each step of (auto)indent
199 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
200 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
201 set shiftround " round to 'shiftwidth' for "<<" and ">>"
202 set expandtab " expand <Tab> to spaces in Insert mode
203
204 set cindent " use smart C indenting (see :h C-indenting)
205 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
206
207 set pastetoggle=<F11> " key sequence to toggle paste mode
208
209 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
210 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
211 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
212 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
213
214 " folding {{{1
215 set foldmethod=marker " folding type
216 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
217
218 " space will toggle current fold in normal mode
219 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
220 " create folds around visual selection
221 vnoremap <Space> zf
222
223 " save and restore folds
224 set viewoptions=folds,cursor " don't save local options
225 autocmd BufWinLeave *.* mkview
226 autocmd BufWinEnter *.* silent loadview
227
228 " reading and writing files {{{1
229 set writebackup " write a backup file before overwriting a file
230 set backup " keep a backup after owerwriting a file
231 set backupdir=$XDG_CACHE_HOME/vim
232
233 set undofile " persistent undo history
234 set undodir=$XDG_CACHE_HOME/vim
235
236 set autowrite " automatically write a file when leaving a modified buffer
237
238 " save with sudo
239 cmap w!! w !sudo tee % > /dev/null
240
241 " the swap file {{{1
242 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
243
244 " command line editing {{{1
245 set history=500 " how many command lines are remembered
246 set wildmode=longest:full " specifies how command line completion works
247 set wildmenu " command-line completion shows a list of matches
248
249 " various {{{1
250 set virtualedit=block " let cursor move past last char in <C-V> mode
251 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .vim
252
253 set viewdir=$XDG_CACHE_HOME/vim
254
255 " plugins {{{1
256 " airline {{{2
257 let g:airline_detect_whitespace=2
258 let g:airline_whitespace_symbol = 'Ξ'
259 let g:airline_linecolumn_prefix = '␊ '
260 let g:airline_left_sep = '▶'
261 let g:airline_right_sep = '◀'
262 let g:airline#extensions#tabline#enabled = 1
263
264 " GoldenView {{{2
265 let g:goldenview__enable_default_mapping = 0
266 nmap <silent> <C-N> <Plug>GoldenViewSplit
267 nmap <silent> <C-L> <Plug>GoldenViewNext
268 nmap <silent> <C-H> <Plug>GoldenViewPrevious
269 nmap <silent> <C-M> <Plug>GoldenViewSwitchMain
270 nmap <silent> <C-S-M> <Plug>GoldenViewPrevious
271
272 " Gundo {{{2
273 nnoremap <F7> :GundoToggle<CR>
274 " fugitive {{{2
275 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
276
277 " NERDTree {{{2
278 " open/close NERDTree with \e
279 nmap <Leader>e :NERDTreeToggle<CR>
280 nmap <F6> :NERDTreeToggle<CR>
281 " <space> to open files/dirs
282 let NERDTreeMapActivateNode='<space>'
283 " close vim if only NERDTree is open
284 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
285
286 " synastic {{{2
287 let g:syntastic_enable_highlighting = 0
288 let g:syntastic_error_symbol='E'
289 let g:syntastic_style_error_symbol='S'
290 let g:syntastic_warning_symbol='W'
291 let g:syntastic_style_warning_symbol='S'
292 let g:syntastic_always_populate_loc_list=1
293 nmap <silent> <leader>y :SyntasticCheck<cr>
294
295 if ! &diff
296 let g:syntastic_check_on_open=1
297 endif
298
299 " tagbar {{{2
300 map <F5> :TagbarToggle<cr>
301 let g:tagbar_sort = 0
302 let g:tagbar_compact = 1
303 let g:tagbar_autoshowtag = 1
304 let g:tagbar_width = 25
305 let g:tagbar_iconchars = ['+', '-']
306
307 " YouCompleteMe {{{2
308 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
309
310 " vim-json {{{2
311 let g:vim_json_syntax_conceal = 0
312
313 " vim-latex {{{2
314 let g:tex_flavor='latex'
315 let g:Tex_DefaultTargetFormat='pdf'
316
317 " functions {{{1
318 " Convenient command to see the difference between the current buffer and the
319 " file it was loaded from, thus the changes you made.
320 " Only define it when not defined already.
321 if !exists(":DiffOrig")
322 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
323 \ | wincmd p | diffthis
324 endif