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