]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: don't allow arrows anywhere
[dotfiles.git] / vim / vimrc
1 " My vimrc file.
2 "
3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
4 "
5
6 " bundles {{{1
7 filetype off
8 set runtimepath& " reset rtp
9
10 set runtimepath+=$XDG_DATA_HOME/vim/vundle
11 call vundle#rc('$XDG_DATA_HOME/vim')
12
13 Bundle 'gmarik/vundle'
14
15 Bundle 'bling/vim-airline'
16 Bundle 'elzr/vim-json'
17 Bundle 'ervandew/ag.git'
18 Bundle 'http://git.code.sf.net/p/vim-latex/vim-latex'
19 Bundle 'kien/ctrlp.vim'
20 Bundle 'majutsushi/tagbar'
21 Bundle 'scrooloose/nerdtree'
22 Bundle 'scrooloose/syntastic'
23 Bundle 'sjl/gundo.vim'
24 Bundle 'tomtom/tcomment_vim'
25 Bundle 'tpope/vim-fugitive'
26 Bundle 'tpope/vim-surround'
27 Bundle 'tpope/vim-unimpaired'
28 Bundle 'valloric/youcompleteme'
29 "Bundle 'zhaocai/goldenview.vim'
30
31 Bundle 'ompugao/ros.vim'
32 Bundle 'ompugao/ctrlp-ros'
33
34 Bundle 'firef0x/pkgbuild.vim'
35 Bundle 'derekwyatt/vim-fswitch'
36 " seems to have problems right now... may be add later?
37 "Bundle 'jalcine/cmake.vim'
38 Bundle 'powerman/vim-plugin-viewdoc'
39
40 " rtp + xdg {{{1
41 " remove entries first
42 set runtimepath -=$HOME/.vim
43 set runtimepath -=$HOME/.vim/after
44 set runtimepath -=$XDG_CONFIG_HOME/vim
45 set runtimepath -=$XDG_CONFIG_HOME/vim/after
46 " then prepend and append them
47 set runtimepath ^=$XDG_CONFIG_HOME/vim
48 set runtimepath +=$XDG_CONFIG_HOME/vim/after
49
50 filetype plugin indent on
51
52 " bindings {{{1
53 " allow both <space> and / to be <leader>
54 map <space> <leader>
55
56 " moving around, searching and patterns {{{1
57 set incsearch " show match for partly typed search command
58 set ignorecase " ignore case when using a search pattern
59 set smartcase " override 'ignorecase' when pattern has upper case characters
60 set hlsearch " highlight all matches for the last used search pattern
61
62 " use leader-n to unhighlight search
63 nmap <silent> <Leader>n :silent nohl<CR>
64 " use leader-# to display the number of matches for the last search
65 nmap <Leader># :%s:<C-R>/::gn<CR>
66 " center cursor after search
67 nnoremap n nzz
68
69 " disable arrows
70 noremap <Up> <NOP>
71 noremap <Down> <NOP>
72 noremap <Left> <NOP>
73 noremap <Right> <NOP>
74 inoremap <Up> <NOP>
75 inoremap <Down> <NOP>
76 inoremap <Left> <NOP>
77 inoremap <Right> <NOP>
78 cnoremap <Up> <NOP>
79 cnoremap <Down> <NOP>
80 cnoremap <Left> <NOP>
81 cnoremap <Right> <NOP>
82 cnoremap <C-K> <Up>
83 cnoremap <C-J> <Down>
84 cnoremap <C-H> <Left>
85 cnoremap <C-L> <Right>
86
87 set nostartofline " don't move the cursor to the first non-blank char of a line
88 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
89
90 " displaying text {{{1
91 set scrolloff=5 " number of screen lines to show around the cursor
92 set nowrap " long lines wrap
93 set linebreak " wrap long lines at a character in 'breakat'
94 set showbreak=▒▒ " show these chars for wrapped lines
95
96 set lazyredraw " don't redraw while executing macros
97
98 set list " show chars defined in 'listchars'
99 set listchars=tab:»·,trail:· " list of strings used for list mode
100
101 set number " show the line number for each line
102 set relativenumber " show the relative line number for each line
103 " toggle relativenumber
104 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
105
106 if has("autocmd")
107 " When editing a file, always jump to the last known cursor position.
108 " Don't do it when the position is invalid or when inside an event handler
109 " (happens when dropping a file on gvim).
110 " Also don't do it when the mark is in the first line, that is the default
111 " position when opening a file.
112 " blacklist certain filetype, you can get a file type with :echo &ft
113 let blacklist = ['gitcommit']
114 autocmd BufReadPost *
115 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
116 \ exe "normal! g`\"" |
117 \ endif
118 endif
119
120
121 " syntax, highlighting and spelling {{{1
122 colorscheme badwolf
123 syntax on
124
125 set dictionary=spell " list of dictionary files for keyword completion
126 " Spell Check http://tex.stackexchange.com/a/52932
127 let b:myLang=0
128 let g:myLangList=["en_gb","en_us","de","fr"]
129
130 function! ToggleSpell()
131 execute "setlocal spell!"
132 if (&spell)
133 echo "setlocal spelllang=" g:myLangList[b:myLang]
134 endif
135 endfunction
136 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
137
138 function! SwitchSpell()
139 if (&spell)
140 let b:myLang=b:myLang+1
141 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
142 endif
143 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
144 echo "setlocal spelllang=" g:myLangList[b:myLang]
145 endfunction
146 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
147
148 " fix spelling with first choice
149 nnoremap <Leader>f 1z=
150
151 if has("autocmd")
152 au Filetype *
153 \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
154 endif
155
156 " multiple windows {{{1
157 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
158
159 set previewheight=20 " default height for the preview window
160
161 set splitright " a new window is put right of the current one
162
163 map <F1> :ls<CR>:b<space>
164
165 nmap <C-L> <C-W>w
166 nmap <C-H> <C-W>W
167
168 " using the mouse {{{1
169 set mouse=rnv " list of flags for using the mouse
170 set ttymouse=xterm " type of mouse
171
172 "xterm mouse with middleclick paste
173 nnoremap <MiddleMouse> i<MiddleMouse>
174 vnoremap <MiddleMouse> s<MiddleMouse>
175
176 " messages and info {{{1
177 set showcmd " Show (partial) command in status line.
178 set ruler " show the cursor position all the time
179 set confirm " Ask what to do when closing unsaved documents
180 set shortmess=filnxtoOI " don't show intro message
181
182 " editing text {{{1
183 set backspace=indent,eol,start " allow backspacing over everything in insert mode
184
185 set showmatch " Show matching brackets.
186
187 set nojoinspaces " don't use two spaces after '.' when joining a line
188 set formatoptions+=j " remove comment leader when joining lines
189
190 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
191
192 " whether to use a popup menu for Insert mode completion
193 set completeopt=longest,menuone,preview
194
195 " Indent if we're at the beginning of a line. Else, do completion.
196 function! InsertTabWrapper()
197 let col = col('.') - 1
198 if !col || getline('.')[col - 1] !~ '\k'
199 return "\<Tab>"
200 else
201 return "\<C-N>"
202 endif
203 endfunction
204 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
205 inoremap <S-Tab> <C-P>
206
207 " fix legacy vi inconsistency
208 map Y y$
209
210 " allow repeat operator on visual
211 vnoremap . :normal .<CR>
212
213 " add line without changing position or leaving mode
214 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
215 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
216
217 " Don't use Ex mode, use Q for formatting
218 map Q gq
219
220 " allow undoing in insert-mode
221 inoremap <C-U> <C-G>u<C-U>
222 inoremap <C-W> <C-G>u<C-W>
223
224 " tabs and indent {{{1
225 set shiftwidth=4 " number of spaces used for each step of (auto)indent
226 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
227 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
228 set shiftround " round to 'shiftwidth' for "<<" and ">>"
229 set expandtab " expand <Tab> to spaces in Insert mode
230
231 set cindent " use smart C indenting (see :h C-indenting)
232 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
233
234 set pastetoggle=<F11> " key sequence to toggle paste mode
235
236 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
237 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
238 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
239 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
240
241 " folding {{{1
242 set foldmethod=marker " folding type
243 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
244
245 " space will toggle current fold in normal mode
246 nnoremap <leader><Space> za
247 " create folds around visual selection
248 vnoremap <leader><Space> zf
249
250 " save and restore folds
251 set viewoptions=folds,cursor " don't save local options
252 autocmd BufWinLeave *.* mkview
253 autocmd BufWinEnter *.* silent loadview
254
255 " reading and writing files {{{1
256 set writebackup " write a backup file before overwriting a file
257 set backup " keep a backup after owerwriting a file
258 set backupdir=$XDG_CACHE_HOME/vim
259
260 set undofile " persistent undo history
261 set undodir=$XDG_CACHE_HOME/vim
262
263 set autowrite " automatically write a file when leaving a modified buffer
264
265 " save with sudo
266 cmap w!! w !sudo tee % > /dev/null
267
268 " the swap file {{{1
269 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
270
271 " command line editing {{{1
272 set history=500 " how many command lines are remembered
273 set wildmode=longest:full " specifies how command line completion works
274 set wildmenu " command-line completion shows a list of matches
275
276 " various {{{1
277 set virtualedit=block " let cursor move past last char in <C-V> mode
278 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
279
280 set viewdir=$XDG_CACHE_HOME/vim
281
282 " plugins {{{1
283 " airline {{{2
284 let g:airline_detect_whitespace=2
285 let g:airline#extensions#tabline#enabled = 1
286 let g:airline_powerline_fonts = 1
287
288 " GoldenView {{{2
289 "let g:goldenview__enable_default_mapping = 0
290 "nmap <silent> <C-N> <Plug>GoldenViewSplit
291 "nmap <silent> <C-L> <Plug>GoldenViewNext
292 "nmap <silent> <C-H> <Plug>GoldenViewPrevious
293 "nmap <silent> <C-M> <Plug>GoldenViewSwitchMain
294 "nmap <silent> <C-S-M> <Plug>GoldenViewPrevious
295
296 " Gundo {{{2
297 nnoremap <F7> :GundoToggle<CR>
298 " fugitive {{{2
299 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
300 " delete fugitive buffers when closed
301 autocmd BufReadPost fugitive://* set bufhidden=delete
302
303 " NERDTree {{{2
304 " open/close NERDTree with \e
305 nmap <Leader>e :NERDTreeToggle<CR>
306 nmap <F6> :NERDTreeToggle<CR>
307 " <space> to open files/dirs
308 let NERDTreeMapActivateNode='<space>'
309 " close vim if only NERDTree is open
310 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
311
312 " synastic {{{2
313 let g:syntastic_enable_highlighting = 0
314 let g:syntastic_error_symbol='E'
315 let g:syntastic_style_error_symbol='S'
316 let g:syntastic_warning_symbol='W'
317 let g:syntastic_style_warning_symbol='S'
318 let g:syntastic_always_populate_loc_list=1
319 nmap <silent> <leader>y :SyntasticCheck<cr>
320
321 if ! &diff
322 let g:syntastic_check_on_open=1
323 endif
324
325 " tagbar {{{2
326 map <F5> :TagbarToggle<cr>
327 let g:tagbar_sort = 0
328 let g:tagbar_compact = 1
329 let g:tagbar_autoshowtag = 1
330 let g:tagbar_width = 25
331 let g:tagbar_iconchars = ['+', '-']
332
333 " YouCompleteMe {{{2
334 let g:ycm_extra_conf_globlist = ['~/src/*']
335
336 " vim-json {{{2
337 let g:vim_json_syntax_conceal = 0
338
339 " vim-latex {{{2
340 let g:tex_flavor='latex'
341 let g:Tex_DefaultTargetFormat='pdf'
342
343 " vim-viewdoc {{{2
344 let g:no_viewdoc_maps = 1
345 nnoremap K :call ViewDoc('doc', '<cword>')<cr>
346
347 " functions {{{1
348 " auto source vimrc when saved
349 autocmd bufwritepost vimrc source $MYVIMRC
350 nmap <leader>v :tabedit $MYVIMRC<CR>
351
352 " Convenient command to see the difference between the current buffer and the
353 " file it was loaded from, thus the changes you made.
354 " Only define it when not defined already.
355 if !exists(":DiffOrig")
356 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
357 \ | wincmd p | diffthis
358 endif