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