3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
7 set runtimepath=$XDG_CONFIG_HOME/vim,$VIMRUNTIME,$XDG_CONFIG_HOME/vim/after
11 set rtp+=$XDG_DATA_HOME/vim/vundle
12 call vundle#rc('$XDG_DATA_HOME/vim')
14 Bundle 'gmarik/vundle'
15 Bundle 'bling/vim-airline'
19 Bundle 'The-NERD-tree'
24 Bundle 'Valloric/YouCompleteMe'
25 Bundle 'elzr/vim-json'
26 Bundle 'http://git.code.sf.net/p/vim-latex/vim-latex'
27 Bundle 'ervandew/ag.git'
28 Bundle 'zhaocai/GoldenView.Vim'
30 filetype plugin indent on
32 " moving around, searching and patterns {{{1
33 set incsearch " show match for partly typed search command
34 set ignorecase " ignore case when using a search pattern
35 set smartcase " override 'ignorecase' when pattern has upper case characters
36 set hlsearch " highlight all matches for the last used search pattern
38 " use leader-n to unhighlight search
39 nmap <silent> <Leader>n :silent nohl<CR>
40 " use leader-# to display the number of matches for the last search
41 nmap <Leader># :%s:<C-R>/::gn<CR>
42 " center cursor after search
48 inoremap <Right> <NOP>
54 set nostartofline " don't move the cursor to the first non-blank char of a line
55 set path=.,** " current + subdirectory search for :find, :grep:, ...
57 " displaying text {{{1
58 set scrolloff=5 " number of screen lines to show around the cursor
59 set wrap " long lines wrap
60 set linebreak " wrap long lines at a character in 'breakat'
61 set showbreak=▒▒ " show these chars for wrapped lines
63 set lazyredraw " don't redraw while executing macros
65 set list " show chars defined in 'listchars'
66 set listchars=tab:»·,trail:· " list of strings used for list mode
68 set number " show the line number for each line
69 set relativenumber " show the relative line number for each line
70 " toggle relativenumber
71 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
74 " When editing a file, always jump to the last known cursor position.
75 " Don't do it when the position is invalid or when inside an event handler
76 " (happens when dropping a file on gvim).
77 " Also don't do it when the mark is in the first line, that is the default
78 " position when opening a file.
79 " blacklist certain filetype, you can get a file type with :echo &ft
80 let blacklist = ['gitcommit']
82 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
83 \ exe "normal! g`\"" |
88 " syntax, highlighting and spelling {{{1
89 set background=dark " Dark background, d'uh!
92 set spelllang=en_gb " list of accepted languages
93 set dictionary=spell " list of dictionary files for keyword completion
94 " Spell Check http://tex.stackexchange.com/a/52932
96 let g:myLangList=["en_gb","en_us","de","fr"]
98 function! ToggleSpell()
99 execute "setlocal spell!"
101 echo "setlocal spelllang=" g:myLangList[b:myLang]
104 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
106 function! SwitchSpell()
108 let b:myLang=b:myLang+1
109 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
111 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
112 echo "setlocal spelllang=" g:myLangList[b:myLang]
114 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
116 " fix spelling with first choice
117 nnoremap <Leader>f 1z=
121 \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
124 " multiple windows {{{1
125 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
127 set previewheight=20 " default height for the preview window
129 set splitright " a new window is put right of the current one
131 map <F1> :ls<CR>:b<space>
133 " using the mouse {{{1
134 set mouse=rnv " list of flags for using the mouse
135 set ttymouse=xterm " type of mouse
137 "xterm mouse with middleclick paste
138 nnoremap <MiddleMouse> i<MiddleMouse>
139 vnoremap <MiddleMouse> s<MiddleMouse>
141 " messages and info {{{1
142 set showcmd " Show (partial) command in status line.
143 set ruler " show the cursor position all the time
144 set confirm " Ask what to do when closing unsaved documents
147 set backspace=indent,eol,start " allow backspacing over everything in insert mode
149 set showmatch " Show matching brackets.
151 set nojoinspaces " don't use two spaces after '.' when joining a line
152 set formatoptions+=j " remove comment leader when joining lines
154 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
156 " whether to use a popup menu for Insert mode completion
157 set completeopt=longest,menuone,preview
159 " Indent if we're at the beginning of a line. Else, do completion.
160 function! InsertTabWrapper()
161 let col = col('.') - 1
162 if !col || getline('.')[col - 1] !~ '\k'
168 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
169 inoremap <S-Tab> <C-P>
171 " fix legacy vi inconsistency
174 " allow repeat operator on visual
175 vnoremap . :normal .<CR>
177 " add line without changing position or leaving mode
178 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
179 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
181 " Don't use Ex mode, use Q for formatting
184 " allow undoing in insert-mode
185 inoremap <C-U> <C-G>u<C-U>
186 inoremap <C-W> <C-G>u<C-W>
188 " tabs and indent {{{1
189 set shiftwidth=4 " number of spaces used for each step of (auto)indent
190 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
191 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
192 set shiftround " round to 'shiftwidth' for "<<" and ">>"
193 set expandtab " expand <Tab> to spaces in Insert mode
195 set cindent " use smart C indenting (see :h C-indenting)
196 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
198 set pastetoggle=<F11> " key sequence to toggle paste mode
200 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
201 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
202 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
203 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
206 set foldmethod=marker " folding type
207 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
209 " space will toggle current fold in normal mode
210 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
211 " create folds around visual selection
214 " save and restore folds
215 set viewoptions=folds,cursor " don't save local options
216 autocmd BufWinLeave *.* mkview
217 autocmd BufWinEnter *.* silent loadview
219 " reading and writing files {{{1
220 set writebackup " write a backup file before overwriting a file
221 set backup " keep a backup after owerwriting a file
222 set backupdir=$XDG_CACHE_HOME/vim
224 set undofile " persistent undo history
225 set undodir=$XDG_CACHE_HOME/vim
227 set autowrite " automatically write a file when leaving a modified buffer
230 cmap w!! w !sudo tee % > /dev/null
233 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
235 " command line editing {{{1
236 set history=500 " how many command lines are remembered
237 set wildmode=longest:full " specifies how command line completion works
238 set wildmenu " command-line completion shows a list of matches
241 set virtualedit=block " let cursor move past last char in <C-V> mode
242 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .vim
244 set viewdir=$XDG_CACHE_HOME/vim
248 let g:airline_detect_whitespace=2
249 let g:airline_whitespace_symbol = 'Ξ'
250 let g:airline_linecolumn_prefix = '␊ '
251 let g:airline_left_sep = '▶'
252 let g:airline_right_sep = '◀'
253 let g:airline#extensions#tabline#enabled = 1
256 let g:goldenview__enable_default_mapping = 0
257 nmap <silent> <C-N> <Plug>GoldenViewSplit
258 nmap <silent> <C-L> <Plug>GoldenViewNext
259 nmap <silent> <C-H> <Plug>GoldenViewPrevious
260 nmap <silent> <C-M> <Plug>GoldenViewSwitchMain
261 nmap <silent> <C-S-M> <Plug>GoldenViewPrevious
264 nnoremap <F7> :GundoToggle<CR>
266 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
269 " open/close NERDTree with \e
270 nmap <Leader>e :NERDTreeToggle<CR>
271 nmap <F6> :NERDTreeToggle<CR>
272 " <space> to open files/dirs
273 let NERDTreeMapActivateNode='<space>'
274 " close vim if only NERDTree is open
275 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
278 let g:syntastic_enable_highlighting = 0
279 let g:syntastic_error_symbol='E'
280 let g:syntastic_style_error_symbol='S'
281 let g:syntastic_warning_symbol='W'
282 let g:syntastic_style_warning_symbol='S'
283 let g:syntastic_always_populate_loc_list=1
284 nmap <silent> <leader>y :SyntasticCheck<cr>
287 let g:syntastic_check_on_open=1
291 map <F5> :TagbarToggle<cr>
292 let g:tagbar_sort = 0
293 let g:tagbar_compact = 1
294 let g:tagbar_autoshowtag = 1
295 let g:tagbar_width = 25
296 let g:tagbar_iconchars = ['+', '-']
299 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
302 let g:vim_json_syntax_conceal = 0
305 let g:tex_flavor='latex'
306 let g:Tex_DefaultTargetFormat='pdf'
309 " Convenient command to see the difference between the current buffer and the
310 " file it was loaded from, thus the changes you made.
311 " Only define it when not defined already.
312 if !exists(":DiffOrig")
313 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
314 \ | wincmd p | diffthis