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