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