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