3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
7 set rtp+=~/.vim/bundle/vundle/
10 Bundle 'gmarik/vundle'
11 Bundle 'wincent/Command-T'
12 Bundle 'bling/vim-airline'
16 Bundle 'The-NERD-tree'
21 Bundle 'Valloric/YouCompleteMe'
22 Bundle 'elzr/vim-json'
24 filetype plugin indent on
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
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
42 inoremap <Right> <NOP>
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:, ...
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
57 set lazyredraw " don't redraw while executing macros
59 set list " show chars defined in 'listchars'
60 set listchars=tab:»·,trail:· " list of strings used for list mode
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>
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']
76 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
77 \ exe "normal! g`\"" |
82 " syntax, highlighting and spelling {{{1
83 set background=dark " Dark background, d'uh!
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>
93 \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
96 " multiple windows {{{1
97 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
99 set previewheight=20 " default height for the preview window
101 set splitright " a new window is put right of the current one
108 map <F1> :ls<CR>:b<space>
110 " using the mouse {{{1
111 set mouse=rnv " list of flags for using the mouse
112 set ttymouse=xterm " type of mouse
114 "xterm mouse with middleclick paste
115 nnoremap <MiddleMouse> i<MiddleMouse>
116 vnoremap <MiddleMouse> s<MiddleMouse>
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
124 set backspace=indent,eol,start " allow backspacing over everything in insert mode
126 set showmatch " Show matching brackets.
128 set nojoinspaces " don't use two spaces after '.' when joining a line
129 set formatoptions+=j " remove comment leader when joining lines
131 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
133 " whether to use a popup menu for Insert mode completion
134 set completeopt=longest,menuone,preview
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'
145 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
146 inoremap <S-Tab> <C-P>
148 " fix legacy vi inconsistency
151 " allow repeat operator on visual
152 vnoremap . :normal .<CR>
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>
158 " Don't use Ex mode, use Q for formatting
161 " allow undoing in insert-mode
162 inoremap <C-U> <C-G>u<C-U>
163 inoremap <C-W> <C-G>u<C-W>
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
172 set cindent " use smart C indenting (see :h C-indenting)
173 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
175 set pastetoggle=<F11> " key sequence to toggle paste mode
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>
183 set foldmethod=marker " folding type
184 set foldlevelstart=99 " value for 'foldlevel' when starting to edit a file
186 " space will toggle current fold in normal mode
187 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
188 " create folds around visual selection
191 " save and restore folds
192 autocmd BufWinLeave *.* mkview
193 autocmd BufWinEnter *.* silent loadview
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
200 set undofile " persistent undo history
201 set undodir=$HOME/.vim/backupdir
203 set autowrite " automatically write a file when leaving a modified buffer
206 cmap w!! w !sudo tee % > /dev/null
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
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
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
227 nnoremap <F7> :GundoToggle<CR>
229 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
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
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>
252 let g:syntastic_check_on_open=1
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 = ['+', '-']
264 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
267 let g:vim_json_syntax_conceal = 0
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