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'
28 filetype plugin indent on
30 " moving around, searching and patterns {{{1
31 set incsearch " show match for partly typed search command
32 set ignorecase " ignore case when using a search pattern
33 set smartcase " override 'ignorecase' when pattern has upper case characters
34 set hlsearch " highlight all matches for the last used search pattern
36 " use leader-n to unhighlight search
37 nmap <silent> <Leader>n :silent nohl<CR>
38 " use leader-# to display the number of matches for the last search
39 nmap <Leader># :%s:<C-R>/::gn<CR>
40 " center cursor after search
46 inoremap <Right> <NOP>
52 set nostartofline " don't move the cursor to the first non-blank char of a line
53 set path=.,** " current + subdirectory search for :find, :grep:, ...
55 " displaying text {{{1
56 set scrolloff=5 " number of screen lines to show around the cursor
57 set wrap " long lines wrap
58 set linebreak " wrap long lines at a character in 'breakat'
59 set showbreak=▒▒ " show these chars for wrapped lines
61 set lazyredraw " don't redraw while executing macros
63 set list " show chars defined in 'listchars'
64 set listchars=tab:»·,trail:· " list of strings used for list mode
66 set number " show the line number for each line
67 set relativenumber " show the relative line number for each line
68 " toggle relativenumber
69 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
72 " When editing a file, always jump to the last known cursor position.
73 " Don't do it when the position is invalid or when inside an event handler
74 " (happens when dropping a file on gvim).
75 " Also don't do it when the mark is in the first line, that is the default
76 " position when opening a file.
77 " blacklist certain filetype, you can get a file type with :echo &ft
78 let blacklist = ['gitcommit']
80 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
81 \ exe "normal! g`\"" |
86 " syntax, highlighting and spelling {{{1
87 set background=dark " Dark background, d'uh!
90 set spelllang=en_gb " list of accepted languages
91 set dictionary=spell " list of dictionary files for keyword completion
92 " Spell Check http://tex.stackexchange.com/a/52932
94 let g:myLangList=["nospell","en_gb","en_us","de","fr"]
95 function! ToggleSpell()
96 let b:myLang=b:myLang+1
97 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
101 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
103 echo "spell checking language:" g:myLangList[b:myLang]
105 map <F10> :call ToggleSpell()<CR>
106 imap <F10> <C-O>:call ToggleSpell()<CR>
110 \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
113 " multiple windows {{{1
114 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
116 set previewheight=20 " default height for the preview window
118 set splitright " a new window is put right of the current one
125 map <F1> :ls<CR>:b<space>
127 " using the mouse {{{1
128 set mouse=rnv " list of flags for using the mouse
129 set ttymouse=xterm " type of mouse
131 "xterm mouse with middleclick paste
132 nnoremap <MiddleMouse> i<MiddleMouse>
133 vnoremap <MiddleMouse> s<MiddleMouse>
135 " messages and info {{{1
136 set showcmd " Show (partial) command in status line.
137 set ruler " show the cursor position all the time
138 set confirm " Ask what to do when closing unsaved documents
141 set backspace=indent,eol,start " allow backspacing over everything in insert mode
143 set showmatch " Show matching brackets.
145 set nojoinspaces " don't use two spaces after '.' when joining a line
146 set formatoptions+=j " remove comment leader when joining lines
148 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
150 " whether to use a popup menu for Insert mode completion
151 set completeopt=longest,menuone,preview
153 " Indent if we're at the beginning of a line. Else, do completion.
154 function! InsertTabWrapper()
155 let col = col('.') - 1
156 if !col || getline('.')[col - 1] !~ '\k'
162 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
163 inoremap <S-Tab> <C-P>
165 " fix legacy vi inconsistency
168 " allow repeat operator on visual
169 vnoremap . :normal .<CR>
171 " add line without changing position or leaving mode
172 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
173 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
175 " Don't use Ex mode, use Q for formatting
178 " allow undoing in insert-mode
179 inoremap <C-U> <C-G>u<C-U>
180 inoremap <C-W> <C-G>u<C-W>
182 " tabs and indent {{{1
183 set shiftwidth=4 " number of spaces used for each step of (auto)indent
184 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
185 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
186 set shiftround " round to 'shiftwidth' for "<<" and ">>"
187 set expandtab " expand <Tab> to spaces in Insert mode
189 set cindent " use smart C indenting (see :h C-indenting)
190 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
192 set pastetoggle=<F11> " key sequence to toggle paste mode
194 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
195 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
196 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
197 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
200 set foldmethod=marker " folding type
201 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
203 " space will toggle current fold in normal mode
204 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
205 " create folds around visual selection
208 " save and restore folds
209 set viewoptions=folds,cursor " don't save local options
210 autocmd BufWinLeave *.* mkview
211 autocmd BufWinEnter *.* silent loadview
213 " reading and writing files {{{1
214 set writebackup " write a backup file before overwriting a file
215 set backup " keep a backup after owerwriting a file
216 set backupdir=$XDG_CACHE_HOME/vim
218 set undofile " persistent undo history
219 set undodir=$XDG_CACHE_HOME/vim
221 set autowrite " automatically write a file when leaving a modified buffer
224 cmap w!! w !sudo tee % > /dev/null
227 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
229 " command line editing {{{1
230 set history=500 " how many command lines are remembered
231 set wildmode=longest:full " specifies how command line completion works
232 set wildmenu " command-line completion shows a list of matches
235 set virtualedit=block " let cursor move past last char in <C-V> mode
236 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .vim
238 set viewdir=$XDG_CACHE_HOME/vim
242 let g:airline_detect_whitespace=2
243 let g:airline_whitespace_symbol = 'Ξ'
244 let g:airline_linecolumn_prefix = '␊ '
245 let g:airline_left_sep = '▶'
246 let g:airline_right_sep = '◀'
247 let g:airline#extensions#tabline#enabled = 1
250 nnoremap <F7> :GundoToggle<CR>
252 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
255 " open/close NERDTree with \e
256 nmap <Leader>e :NERDTreeToggle<CR>
257 nmap <F6> :NERDTreeToggle<CR>
258 " <space> to open files/dirs
259 let NERDTreeMapActivateNode='<space>'
260 " close vim if only NERDTree is open
261 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
264 let g:syntastic_enable_highlighting = 0
265 let g:syntastic_error_symbol='E'
266 let g:syntastic_style_error_symbol='S'
267 let g:syntastic_warning_symbol='W'
268 let g:syntastic_style_warning_symbol='S'
269 let g:syntastic_always_populate_loc_list=1
270 nmap <silent> <leader>y :SyntasticCheck<cr>
273 let g:syntastic_check_on_open=1
277 map <F5> :TagbarToggle<cr>
278 let g:tagbar_sort = 0
279 let g:tagbar_compact = 1
280 let g:tagbar_autoshowtag = 1
281 let g:tagbar_width = 25
282 let g:tagbar_iconchars = ['+', '-']
285 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
288 let g:vim_json_syntax_conceal = 0
291 let g:tex_flavor='latex'
292 let g:Tex_DefaultTargetFormat='pdf'
295 " Convenient command to see the difference between the current buffer and the
296 " file it was loaded from, thus the changes you made.
297 " Only define it when not defined already.
298 if !exists(":DiffOrig")
299 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
300 \ | wincmd p | diffthis