3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
7 set runtimepath=$XDG_CONFIG_HOME/vim,$VIMRUNTIME,$XDG_CONFIG_HOME/vim/after
10 set rtp+=$XDG_DATA_HOME/vim/vundle
11 call vundle#rc('$XDG_DATA_HOME/vim')
13 Bundle 'gmarik/vundle'
14 Bundle 'wincent/Command-T'
15 Bundle 'bling/vim-airline'
19 Bundle 'The-NERD-tree'
24 Bundle 'Valloric/YouCompleteMe'
25 Bundle 'elzr/vim-json'
27 filetype plugin indent on
29 " moving around, searching and patterns {{{1
30 set incsearch " show match for partly typed search command
31 set ignorecase " ignore case when using a search pattern
32 set smartcase " override 'ignorecase' when pattern has upper case characters
33 set hlsearch " highlight all matches for the last used search pattern
35 " use leader-n to unhighlight search
36 nmap <silent> <Leader>n :silent nohl<CR>
37 " use leader-# to display the number of matches for the last search
38 nmap <Leader># :%s:<C-R>/::gn<CR>
39 " center cursor after search
45 inoremap <Right> <NOP>
51 set nostartofline " don't move the cursor to the first non-blank char of a line
52 set path=.,** " current + subdirectory search for :find, :grep:, ...
54 " displaying text {{{1
55 set scrolloff=5 " number of screen lines to show around the cursor
56 set wrap " long lines wrap
57 set linebreak " wrap long lines at a character in 'breakat'
58 set showbreak=▒▒ " show these chars for wrapped lines
60 set lazyredraw " don't redraw while executing macros
62 set list " show chars defined in 'listchars'
63 set listchars=tab:»·,trail:· " list of strings used for list mode
65 set number " show the line number for each line
66 set relativenumber " show the relative line number for each line
67 " toggle relativenumber
68 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
71 " When editing a file, always jump to the last known cursor position.
72 " Don't do it when the position is invalid or when inside an event handler
73 " (happens when dropping a file on gvim).
74 " Also don't do it when the mark is in the first line, that is the default
75 " position when opening a file.
76 " blacklist certain filetype, you can get a file type with :echo &ft
77 let blacklist = ['gitcommit']
79 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
80 \ exe "normal! g`\"" |
85 " syntax, highlighting and spelling {{{1
86 set background=dark " Dark background, d'uh!
89 set spelllang=en,de,fr " list of accepted languages
90 set dictionary=spell " list of dictionary files for keyword completion
91 " toggle spell-checking
92 map <silent><F10> :set nospell!<CR>:set nospell?<CR>
96 \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
99 " multiple windows {{{1
100 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
102 set previewheight=20 " default height for the preview window
104 set splitright " a new window is put right of the current one
111 map <F1> :ls<CR>:b<space>
113 " using the mouse {{{1
114 set mouse=rnv " list of flags for using the mouse
115 set ttymouse=xterm " type of mouse
117 "xterm mouse with middleclick paste
118 nnoremap <MiddleMouse> i<MiddleMouse>
119 vnoremap <MiddleMouse> s<MiddleMouse>
121 " messages and info {{{1
122 set showcmd " Show (partial) command in status line.
123 set ruler " show the cursor position all the time
124 set confirm " Ask what to do when closing unsaved documents
127 set backspace=indent,eol,start " allow backspacing over everything in insert mode
129 set showmatch " Show matching brackets.
131 set nojoinspaces " don't use two spaces after '.' when joining a line
132 set formatoptions+=j " remove comment leader when joining lines
134 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
136 " whether to use a popup menu for Insert mode completion
137 set completeopt=longest,menuone,preview
139 " Indent if we're at the beginning of a line. Else, do completion.
140 function! InsertTabWrapper()
141 let col = col('.') - 1
142 if !col || getline('.')[col - 1] !~ '\k'
148 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
149 inoremap <S-Tab> <C-P>
151 " fix legacy vi inconsistency
154 " allow repeat operator on visual
155 vnoremap . :normal .<CR>
157 " add line without changing position or leaving mode
158 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
159 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
161 " Don't use Ex mode, use Q for formatting
164 " allow undoing in insert-mode
165 inoremap <C-U> <C-G>u<C-U>
166 inoremap <C-W> <C-G>u<C-W>
168 " tabs and indent {{{1
169 set shiftwidth=4 " number of spaces used for each step of (auto)indent
170 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
171 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
172 set shiftround " round to 'shiftwidth' for "<<" and ">>"
173 set expandtab " expand <Tab> to spaces in Insert mode
175 set cindent " use smart C indenting (see :h C-indenting)
176 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
178 set pastetoggle=<F11> " key sequence to toggle paste mode
180 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
181 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
182 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
183 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
186 set foldmethod=marker " folding type
187 set foldlevelstart=99 " value for 'foldlevel' when starting to edit a file
189 " space will toggle current fold in normal mode
190 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
191 " create folds around visual selection
194 " save and restore folds
195 autocmd BufWinLeave *.* mkview
196 autocmd BufWinEnter *.* silent loadview
198 " reading and writing files {{{1
199 set writebackup " write a backup file before overwriting a file
200 set backup " keep a backup after owerwriting a file
201 set backupdir=$XDG_CACHE_HOME/vim
203 set undofile " persistent undo history
204 set undodir=$XDG_CACHE_HOME/vim
206 set autowrite " automatically write a file when leaving a modified buffer
209 cmap w!! w !sudo tee % > /dev/null
212 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
214 " command line editing {{{1
215 set history=500 " how many command lines are remembered
216 set wildmode=longest:full " specifies how command line completion works
217 set wildmenu " command-line completion shows a list of matches
220 set virtualedit=block " let cursor move past last char in <C-V> mode
221 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .vim
223 set viewdir=$XDG_CACHE_HOME/vim
227 let g:airline_detect_whitespace=2
228 let g:airline_whitespace_symbol = 'Ξ'
229 let g:airline_linecolumn_prefix = '␊ '
230 let g:airline_left_sep = '▶'
231 let g:airline_right_sep = '◀'
232 let g:airline#extensions#tabline#enabled = 1
235 nnoremap <F7> :GundoToggle<CR>
237 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
240 " open/close NERDTree with \e
241 nmap <Leader>e :NERDTreeToggle<CR>
242 nmap <F6> :NERDTreeToggle<CR>
243 " <space> to open files/dirs
244 let NERDTreeMapActivateNode='<space>'
245 " open NERDTree if no files were selected
246 autocmd vimenter * if !argc() | NERDTree | endif
247 " close vim if only NERDTree is open
248 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
251 let g:syntastic_enable_highlighting = 0
252 let g:syntastic_error_symbol='E'
253 let g:syntastic_style_error_symbol='S'
254 let g:syntastic_warning_symbol='W'
255 let g:syntastic_style_warning_symbol='S'
256 let g:syntastic_always_populate_loc_list=1
257 nmap <silent> <leader>y :SyntasticCheck<cr>
260 let g:syntastic_check_on_open=1
264 map <F5> :TagbarToggle<cr>
265 let g:tagbar_sort = 0
266 let g:tagbar_compact = 1
267 let g:tagbar_autoshowtag = 1
268 let g:tagbar_width = 25
269 let g:tagbar_iconchars = ['+', '-']
272 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
275 let g:vim_json_syntax_conceal = 0
278 " Convenient command to see the difference between the current buffer and the
279 " file it was loaded from, thus the changes you made.
280 " Only define it when not defined already.
281 if !exists(":DiffOrig")
282 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
283 \ | wincmd p | diffthis