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