]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: do not Plug youcompleteme in nvim
[dotfiles.git] / vim / vimrc
1 " force python3
2 if has('python3') | endif
3
4 " space is leader
5 let g:mapleader = " "
6
7 " runtimepath {{{1
8 set runtimepath ^=$XDG_CONFIG_HOME/vim
9 set runtimepath +=$XDG_CONFIG_HOME/vim/after
10
11 " plugins {{{1
12 call plug#begin('$XDG_DATA_HOME/vim')
13 " This does not update vim-plug, use PlugUpgrade instead
14 Plug 'junegunn/vim-plug'
15
16 Plug 'airblade/vim-gitgutter' " {{{
17 " prefer other signs such as ycm diags
18 let g:gitgutter_sign_priority = 1
19 " don't clobber other signs
20 let g:gitgutter_sign_allow_clobber = 0
21 "}}}
22 Plug 'alepez/vim-gtest'
23 Plug 'alx741/vinfo'
24 Plug 'andrewradev/sideways.vim' " {{{2
25 nnoremap <silent> ,h :SidewaysLeft<CR>:delmarks z<CR>
26 nnoremap <silent> ,l :SidewaysRight<CR>:delmarks z<CR>
27 "}}}
28 Plug 'andrewradev/switch.vim'
29 if !has('nvim')
30 Plug 'bling/vim-airline' "{{{2
31 let g:airline#extensions#whitespace#enabled = 1
32 let g:airline#extensions#tabline#enabled = 1
33 let g:airline#extensions#searchcount#enabled = 0
34 let g:airline_powerline_fonts = 1
35
36 let g:asyncrun_status = "stopped"
37 " let g:airline_section_error = airline#section#create_right(['%{g:asyncrun_status}'])
38 "}}}
39 endif
40
41 Plug 'chrisbra/checkattach'
42 Plug 'derekwyatt/vim-fswitch'
43 Plug 'elzr/vim-json'
44 Plug 'firef0x/pkgbuild.vim'
45 Plug 'junegunn/vim-easy-align'
46 Plug 'justinmk/vim-sneak'
47 Plug 'klen/python-mode'
48 Plug 'kshenoy/vim-signature'
49 Plug 'majutsushi/tagbar'
50 Plug 'octol/vim-cpp-enhanced-highlight'
51 Plug 'raimondi/delimitmate'
52 Plug 'sgeb/vim-diff-fold'
53 Plug 'skywind3000/asyncrun.vim' " {{{2
54 command! -bang -nargs=* -complete=file Make AsyncRun -save=2 -program=make @ <args>
55 let g:asyncrun_open = 10
56 "}}}
57 Plug 'shougo/unite.vim'
58 Plug 'shougo/vimproc.vim', {'do': 'make'}
59 Plug 'sjl/gundo.vim'
60 Plug 'thinca/vim-qfreplace'
61 Plug 'tomtom/tcomment_vim'
62 Plug 'tpope/vim-abolish'
63 Plug 'tpope/vim-characterize'
64 Plug 'tpope/vim-endwise'
65 Plug 'tpope/vim-eunuch'
66 Plug 'tpope/vim-fugitive'
67 Plug 'tpope/vim-repeat'
68 Plug 'tpope/vim-scriptease'
69 Plug 'tpope/vim-speeddating'
70 Plug 'tpope/vim-surround' "investigate vim-sandwich
71 Plug 'tpope/vim-unimpaired'
72 Plug 'tweekmonster/spellrotate.vim'
73 if !has("nvim")
74 " Plug 'valloric/youcompleteme' {{{2
75 Plug 'valloric/youcompleteme',
76 \{ 'do': './install.py --clangd-completer --clang-completer' }
77 let g:ycm_clangd_binary_path = 'clangd' " use clangd in path
78 let g:ycm_clangd_args = ['--clang-tidy']
79 let g:ycm_extra_conf_vim_data = ['getcwd()']
80 let g:ycm_add_preview_to_completeopt = 1
81 let g:ycm_complete_in_comments = 1
82 let g:ycm_complete_in_strings = 1
83 let g:ycm_autoclose_preview_window_after_insertion = 0
84
85 let g:ycm_language_server =
86 \ [
87 \ {
88 \ 'name': 'haskell',
89 \ 'cmdline': [ 'haskell-language-server-wrapper', '--lsp' ],
90 \ 'filetypes': [ 'haskell', 'lhaskell' ]
91 \ },
92 \ ]
93 " }}}
94 endif
95 Plug 'vim-scripts/mediawiki.vim'
96 Plug 'vim-scripts/replacewithregister'
97 Plug 'vim-scripts/yankring.vim'
98 Plug 'wincent/loupe'
99
100 " colorschemes
101 Plug 'morhetz/gruvbox' " {{{2
102 let g:gruvbox_contrast_dark = 'hard'
103 let g:gruvbox_contrast_light = 'soft'
104
105 if !has('nvim')
106 Plug 'arcticicestudio/nord-vim' " {{{2
107 let g:nord_bold = 1
108 let g:nord_italic = 1
109 let g:nord_italic_comments = 1
110 let g:nord_underline = 1
111 let g:nord_uniform_status_lines = 0
112 let g:nord_uniform_diff_background = 0
113 let g:nord_cursor_line_number_background = 0
114 let g:nord_bold_vertical_split_line = 0
115 endif
116
117 "}}}
118
119 " snippets
120 Plug 'sirver/ultisnips'
121 Plug 'honza/vim-snippets'
122
123 " text objects
124 Plug 'kana/vim-textobj-user'
125 Plug 'julian/vim-textobj-variable-segment'
126 Plug 'sgur/vim-textobj-parameter'
127 Plug 'kana/vim-operator-user'
128
129 " staging
130 " Check LucHermites plugins: https://github.com/LucHermitte/lh-cpp
131 Plug 'imsnif/kdl.vim'
132
133 Plug 'puremourning/vimspector'
134 Plug 'ilyachur/cmake4vim'
135 Plug 'ilyachur/gtest-vim'
136
137 Plug 'git@github.com:/ram-z/vim-orgmode', { 'branch': 'dev' } " {{{2
138 Plug 'vim-scripts/syntaxrange'
139
140 let g:org_agenda_files = ['~/org/*.org']
141
142 Plug 'neovimhaskell/haskell-vim' " {{{2
143 let g:haskell_enable_quantification = 1 " to enable highlighting of `forall`
144 let g:haskell_enable_recursivedo = 1 " to enable highlighting of `mdo` and `rec`
145 let g:haskell_enable_arrowsyntax = 1 " to enable highlighting of `proc`
146 let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern`
147 let g:haskell_enable_typeroles = 1 " to enable highlighting of type roles
148 let g:haskell_enable_static_pointers = 1 " to enable highlighting of `static`
149 let g:haskell_backpack = 1 " to enable highlighting of backpack keywords
150
151 let g:haskell_indent_before_where = 2
152 " }}}
153
154 Plug 'aklt/plantuml-syntax'
155
156 Plug 'mtth/scratch.vim' " {{{2
157 let g:scratch_no_mappings = 1
158 let g:scratch_autohide = 0
159 "}}}
160
161 let g:man_hardwrap = 80
162 if !has('nvim')
163 Plug 'vim-utils/vim-man' " {{{2
164 let g:man_width = 80
165 "}}}
166 endif
167
168 Plug 'jenterkin/vim-autosource' " {{{2
169 let g:autosource_hashdir = $XDG_CACHE_HOME . '/vim/vim-autosource'
170 let g:autosource_conf_names = ['.vimrc', '.vimrc.lua']
171 "}}}
172 call plug#end()
173
174 filetype plugin indent on
175 syntax on
176
177 " colorscheme {{{1
178 set background=dark
179 let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
180 let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
181 set termguicolors
182 if !has('nvim')
183 colorscheme $THEME
184 endif
185 "TODO see how I can integrate this into a theme that customises upstream Nord
186 hi debugPC term=reverse ctermbg=8
187
188 " options {{{1
189 " moving around, searching and patterns {{{2
190 set incsearch " show match for partly typed search command
191 set ignorecase " ignore case when using a search pattern
192 set smartcase " override 'ignorecase' when pattern has upper case characters
193 set hlsearch " highlight all matches for the last used search pattern
194
195 set nostartofline " don't move the cursor to the first non-blank char of a line
196 set path+=.
197 set path+=include/
198 set path+=../include/
199 set path+=/usr/include/c++/*
200
201 " displaying text {{{2
202 set nowrap " long lines wrap
203 set linebreak " wrap long lines at a character in 'breakat'
204 set showbreak=↪ " show these chars for wrapped lines
205 set breakindent " preserve indentation in wrapped text
206
207 set lazyredraw " don't redraw while executing macros
208
209 set list " show chars defined in 'listchars'
210 set listchars=tab:❭\ " list of strings used for list mode
211 set listchars+=extends:❯,precedes:❮
212 set listchars+=nbsp:␣
213 " Only shown when not in insert mode
214 set listchars+=trail:·
215 augroup trailing
216 au!
217 au FileType qf setlocal listchars-=trail:·
218 au InsertEnter * set listchars-=trail:·
219 au InsertLeave * set listchars+=trail:·
220 augroup END
221
222 set scrolloff=5 " number of screen lines to show around the cursor
223 set sidescroll=1 " number of collumns to scroll
224 set sidescrolloff=1 " don't scroll over the listchars
225 set display+=lastline " display as much as possible of last line
226
227 set fillchars=diff:⣿,vert:│
228
229 set nonumber " show the line number for each line
230 set norelativenumber " show the relative line number for each line
231
232 " syntax, highlighting and spelling {{{2
233 set synmaxcol=800 " don't highlight long lines
234
235 set dictionary=spell " list of dictionary files for keyword completion
236
237 set colorcolumn=+1
238
239 " multiple windows {{{2
240 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
241
242 set previewheight=20 " default height for the preview window
243
244 set hidden
245
246 " set splitbelow " a new window is put below of the current one
247 set splitright " a new window is put right of the current one
248
249 " terminal {{{2
250 set ttyfast
251
252 " using the mouse {{{2
253 set mouse=rnv " list of flags for using the mouse
254 if !has('nvim')
255 set ttymouse=xterm " type of mouse
256 endif
257
258 " messages and info {{{2
259 set showcmd " Show (partial) command in status line.
260 set ruler " show the cursor position all the time
261 set confirm " Ask what to do when closing unsaved documents
262 set shortmess= " reset option
263 set shortmess+=a " all abbreviations
264 set shortmess+=o " overwrite file-written message
265 set shortmess+=O " file-read message overrides previous
266 set shortmess+=t " truncate file message at start
267 set shortmess+=T " truncate other messages in the middle
268 set shortmess+=W " don't give 'written' or '[w]' when writing a file
269 set shortmess+=A " ignore swapfile warning
270 set shortmess+=I " no splash screen
271 set shortmess+=c " don't give |ins-completion-menu| messages
272
273 " editing text {{{2
274 set backspace=indent,eol,start " allow backspacing over everything in insert mode
275
276 set showmatch " Show matching brackets.
277
278 set nojoinspaces " don't use two spaces after '.' when joining a line
279 set formatoptions+=j " Delete comment leader when joining lines
280 set formatoptions+=c " Autowrap comments using textwidth
281 set formatoptions+=r " Insert comment leader after hitting <Enter>
282 set formatoptions+=n " Recognize numbered lists
283 set formatoptions+=q " Allow formatting of comments with "gq".
284 set formatoptions+=l " do not wrap lines that have been longer when starting insert mode already
285 set formatoptions+=t " Auto-wrap text using textwidth
286 set formatoptions-=o " Do not insert comment leader after hitting o or O in normal mode
287
288 set nrformats-=octal " don't inc/dec octal numbers with ^[AX]
289 set nrformats+=unsigned " treat all numbers as unsigned
290
291 set complete=. " scan the current buffer ( 'wrapscan' is ignored)
292 set complete+=w " scan buffers from other windows
293 set complete+=b " scan other loaded buffers that are in the buffer list
294 set complete+=u " scan the unloaded buffers that are in the buffer list
295 set complete+=t " scan tags
296 set complete+=i " scan current and included files
297 set complete+=kspell " use the currently active spell checking |spell|
298
299 " whether to use a popup menu for Insert mode completion
300 set completeopt=longest,menuone,preview
301
302 " tabs and indent {{{2
303 set shiftwidth=4 " number of spaces used for each step of (auto)indent
304 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
305 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
306 set shiftround " round to 'shiftwidth' for "<<" and ">>"
307 set expandtab " expand <Tab> to spaces in Insert mode
308 set autoindent
309
310 set pastetoggle=<F11> " key sequence to toggle paste mode
311
312 " folding {{{2
313 set foldmethod=marker " folding type
314 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
315
316 " open folds when jumping to line
317 set foldopen+=jump
318
319 set viewoptions=cursor " save cursor position
320 set viewoptions+=folds " save folds
321
322 " diff mode {{{2
323 set diffopt+=filler " show filler lines
324 set diffopt+=vertical " always vertical split
325 set diffopt+=context:10 " 10 lines context between changes
326 set diffopt+=internal
327 set diffopt+=algorithm:patience
328
329 " reading and writing files {{{2
330 set modeline " read modelines
331 set modelines=2 " only check first/last 2 lines
332
333 set writebackup " write a backup file before overwriting a file
334 set backup " keep a backup after owerwriting a file
335 set backupdir=$XDG_CACHE_HOME/vim/backup//
336
337 set backupskip+=.netrc " skip netrc
338 set backupskip+=/dev/shm/pass* " skip passwordstore files
339
340 set undofile " persistent undo history
341 set undolevels=10000 " moar undos
342 if !has('nvim')
343 set undodir=$XDG_CACHE_HOME/vim/undo//
344 endif
345
346 augroup undoskip
347 au!
348 au BufWritePre .netrc setlocal noundofile
349 au BufWritePre /dev/shm/pass* setlocal noundofile
350 au BufWritePre /tmp/* setlocal noundofile
351 augroup END
352
353 set autowrite " automatically write a file when leaving a modified buffer
354 set autoread " automatically read a file that has been modified
355
356 " the swap file {{{2
357 set noswapfile
358 set directory=$XDG_CACHE_HOME/vim/swap//
359
360 " command line editing {{{2
361 set history=5000 " how many command lines are remembered
362 set wildmenu " command-line completion shows a list of matches
363 set wildmode=longest:full,full " specifies how command line completion works
364 set wildignorecase " ignore case when completing file names
365
366 set wildignore+=.hg,.git,.svn " Version control
367 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
368 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
369 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
370 set wildignore+=*.spl " compiled spelling word lists
371 set wildignore+=*.sw? " Vim swap files
372 set wildignore+=*.luac " Lua byte code
373 set wildignore+=*.pyc " Python byte code
374 set wildignore+=*.orig " Merge resolution files
375
376 " running make and jumping to errors {{{2
377 set makeprg=make\ -w " print changing directories
378
379 set grepformat=%f:%l:%c:%m
380 set grepprg=ag\ --vimgrep\ $*
381
382 " language specific {{{2
383 set isfname-== " don't treat `=` as being part of filenames
384
385 " various {{{2
386 set virtualedit+=block " let cursor move past last char in <C-V> mode
387 set virtualedit+=onemore " allow the cursor to move just past the end of the line
388 if !has('nvim')
389 " viminfo defaults but save file in .cache
390 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo
391 else
392 " shada is the replacement format for viminfo
393 " this setting is probably not needed as it's most likely the default
394 " the default path is in XDG_DATA_HOME, which is fine
395 set shada='100,<50,s10,h
396 endif
397
398 set viewdir=$XDG_CACHE_HOME/vim/view//
399
400 set sessionoptions+=unix,slash " damn windows and it's silly ways
401
402 " autocmds {{{1
403 " Resize splits when the window is resized {{{2
404 augroup resize_splits
405 au!
406 autocmd VimResized * :tabdo wincmd =
407 augroup END
408
409 " Only show cursorline in the current window and in normal mode {{{2
410 augroup cline
411 au!
412 au WinLeave,InsertEnter * set nocursorline
413 au WinEnter,InsertLeave * set cursorline
414 augroup END
415
416 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
417 augroup ft_stdin
418 au!
419 au StdinReadPost * :set buftype=nofile
420 augroup END
421
422 " Jump to last known cursor position {{{2
423 augroup last_loc
424 au!
425 " blacklist certain filetype
426 let blacklist = ['gitcommit']
427 autocmd BufReadPost *
428 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
429 \ exe "normal! g`\"" |
430 \ endif
431 augroup END
432
433 " Check for file modifications automatically {{{2
434 " (current buffer only)
435 " Use :NoAutoChecktime to disable it (uses b:autochecktime)
436 fun! MyAutoCheckTime()
437 " only check timestamp for normal files
438 if &buftype != '' | return | endif
439 if ! exists('b:autochecktime') || b:autochecktime
440 checktime %
441 let b:autochecktime = 1
442 endif
443 endfun
444 augroup MyAutoChecktime
445 au!
446 au FocusGained,BufEnter,CursorHold,InsertEnter * call MyAutoCheckTime()
447 augroup END
448 command! NoAutoChecktime let b:autochecktime=0
449 command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime
450
451 " bindings {{{1
452
453 " make
454 function! MakeWithOpt()
455 " TODO only do this if makeprg matches make
456 " if &makeprg =~ "make"
457 let l:make_dir = ""
458 if exists("b:make_dir")
459 let l:make_dir = "-C ".b:make_dir
460 elseif exists("t:make_dir")
461 let l:make_dir = "-C ".t:make_dir
462 elseif exists("g:make_dir")
463 let l:make_dir = "-C ".g:make_dir
464 endif
465
466 let l:make_targets = ""
467 if exists("g:make_targets")
468 let l:make_targets = g:make_targets
469 endif
470 execute "Make ".l:make_dir." ".l:make_targets
471 endf
472 nnoremap <silent> <leader>r :call MakeWithOpt()<cr>
473
474 " unhighlight search
475 nnoremap <silent> <Leader>/ :silent nohl<CR>
476
477 " Tabs
478 nnoremap <leader>[ :tabprev<cr>
479 nnoremap <leader>] :tabnext<cr>
480
481 " paste from selection
482 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
483 " paste from clipboard
484 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
485
486 " strip trailing whitespace
487 function! StripWhitespace(line1, line2, ...) " {{{2
488 let s_report = &report
489 let &report=0
490 let pattern = a:0 ? a:1 : '\s\+$'
491 let oldview = winsaveview()
492 exe 'keepjumps keeppatterns '.a:line1.','.a:line2.'substitute/'.pattern.'//e'
493 if oldview != winsaveview()
494 redraw
495 endif
496 call winrestview(oldview)
497 let &report = s_report
498 endfunction " }}}2
499 command! -range=% -nargs=0 -bar Untrail keepjumps call StripWhitespace(<line1>,<line2>)
500 nnoremap <silent> <leader>ww :Untrail<CR>
501
502 " Source
503 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
504 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
505
506 " jump to last cursor position
507 noremap ' `
508
509 " Select (charwise) the contents of the current line, excluding indentation.
510 nnoremap vv ^vg_
511
512 " Unfuck my screen
513 nnoremap U
514 \ :syntax sync fromstart<cr>
515 \ :AirlineRefresh<cr>
516 \ :call popup_clear(1)<cr>
517 \ :redraw!<cr>
518
519 " Ranger
520 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
521 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
522
523 " Use sane regexes.
524 nnoremap / /\v
525 vnoremap / /\v
526 cnoremap s/ s/\v
527
528 " display the number of matches for the last search
529 nmap <Leader># :%s:<C-R>/::gn<CR>
530
531 " center cursor after search and open folds
532 nnoremap n nzzzv
533 nnoremap N Nzzzv
534
535 " same when jumping around
536 nnoremap g; g;zzzv
537 nnoremap g, g,zzzv
538 nnoremap <c-o> <c-o>zzzv
539 nnoremap <c-i> <c-i>zzzv
540
541 " Not using the default mappings of 'To line from top/bottom'
542 noremap H ^
543 noremap L $
544 vnoremap H ^
545 vnoremap L g_
546
547 " Heresy, emacs insert bindings
548 inoremap <C-A> <Esc>I
549 inoremap <C-E> <Esc>A
550 cnoremap <C-A> <Home>
551 cnoremap <C-E> <End>
552
553 " proper movement when lines are wrapped
554 noremap <silent><expr> j (v:count == 0 ? 'gj' : 'j')
555 noremap <silent><expr> k (v:count == 0 ? 'gk' : 'k')
556
557 " disable arrows
558 noremap <Up> <NOP>
559 noremap <Down> <NOP>
560 noremap <Left> <NOP>
561 noremap <Right> <NOP>
562 inoremap <Up> <NOP>
563 inoremap <Down> <NOP>
564 inoremap <Left> <NOP>
565 inoremap <Right> <NOP>
566 cnoremap <Up> <NOP>
567 cnoremap <Down> <NOP>
568 cnoremap <Left> <NOP>
569 cnoremap <Right> <NOP>
570 cnoremap <C-K> <Up>
571 cnoremap <C-J> <Down>
572 cnoremap <C-H> <Left>
573 cnoremap <C-L> <Right>
574
575 " close all folds open fold in cursor
576 nnoremap zx zMzxzt
577
578 map <F1> :ls<CR>:b<space>
579
580 " move between windows (skip previewwindow)
581 nnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
582 nnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
583 tnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
584 tnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
585
586 "xterm mouse with middleclick paste
587 nnoremap <MiddleMouse> i<MiddleMouse>
588 vnoremap <MiddleMouse> s<MiddleMouse>
589
590 " fix legacy vi inconsistency
591 nnoremap Y y$
592 " copy to clipboard
593 xnoremap Y "+y
594
595 " allow repeat operator on visual
596 vnoremap . :normal .<CR>
597
598 " add line without changing position or leaving mode
599 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
600 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
601
602 " Don't use Ex mode, use Q for formatting
603 map Q gq
604
605 " break undo sequence before removing word
606 inoremap <C-W> <C-G>u<C-W>
607
608 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
609 nnoremap [oe :set expandtab<CR>
610 nnoremap ]oe :set noexpandtab<CR>
611
612 for idt in range(1,8)
613 exe 'nnoremap co'.idt.' :setlocal tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
614 endfor
615
616 " toggle auto format of text
617 nnoremap coa :set <C-R>=&formatoptions =~ "a" ? 'formatoptions-=a' : 'formatoptions+=a'<CR><CR>
618 nnoremap [oa :set formatoptions+=a<CR>
619 nnoremap ]oa :set formatoptions-=a<CR>
620
621 " space will toggle current fold in normal mode
622 nnoremap <leader><Space> za
623 " create folds around visual selection
624 vnoremap <leader><Space> zf
625
626 " save with sudo
627 cabbrev w!! SudoWrite
628
629 " uppercase previous word
630 inoremap <C-C> <Esc>gUiwgi
631
632 " http://git.io/v3ZeU
633 nmap <silent> <leader>qq :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
634
635 " plugins options {{{1
636 " checkattach {{{2
637 let g:checkattach_filebrowser = 'ranger'
638 let g:checkattach_once = 'y'
639
640 " close-another-window {{{2
641 nnoremap <silent> <C-W>c <NOP>
642 nnoremap <silent> <C-W>cc <C-W>c
643 nnoremap <silent> <C-W>ch :CloseLeftWindow<CR>
644 nnoremap <silent> <C-W>cl :CloseRightWindow<CR>
645 nnoremap <silent> <C-W>cj :CloseBelowWindow<CR>
646 nnoremap <silent> <C-W>ck :CloseAboveWindow<CR>
647
648 " delimitmate {{{2
649 let delimitMate_expand_cr = 2
650 let g:delimitMate_expand_space = 1
651
652 " fswitch {{{2
653 nnoremap <silent> <Leader>ff :FSHere<CR>
654 nnoremap <silent> <Leader>fl :FSRight<CR>
655 nnoremap <silent> <Leader>fh :FSLeft<CR>
656 nnoremap <silent> <Leader>fj :FSBelow<CR>
657 nnoremap <silent> <Leader>fk :FSAbove<CR>
658 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
659 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
660 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
661 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
662
663 " fugitive {{{2
664 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
665 " delete fugitive buffers when closed
666 autocmd BufReadPost fugitive://* set bufhidden=delete
667
668 function! GitToggle()
669 let l:status_buffer = bufname('^fugitive:///*/.git{/worktrees/*,}//$')
670 if buflisted(l:status_buffer)
671 execute 'bdelete '.l:status_buffer
672 else
673 Git
674 16wincmd_
675 endif
676 endfunction
677 command! GitToggle :call GitToggle()
678 command! GToggle GitToggle
679 nnoremap <silent> <leader>gs :GitToggle<CR>
680
681 nnoremap <silent> <leader>gd :Gdiffsplit<CR>
682 nnoremap <silent> <leader>gc :echohl WarningMsg \| echo "use \<leader>gcc instead" \| echohl None<CR>
683 nnoremap <silent> <leader>gcc :tab G commit -v<CR>
684 nnoremap <silent> <leader>gca :tab G commit -v --amend<CR>
685 nnoremap <leader>gcf :tab G commit -v --fixup=
686 nnoremap <silent> <leader>gp :echohl WarningMsg \| echo "use \<leader>gpp instead" \| echohl None<CR>
687 nnoremap <silent> <leader>gpp :Git push \| copen<CR>
688 nnoremap <silent> <leader>gpf :Git push --force-with-lease \| copen<CR>
689 nnoremap <silent> <leader>gll :Git pull<CR>
690 nnoremap <silent> <leader>gru :Git rebase --interactive @{upstream}<CR>
691 nnoremap <silent> <leader>grp :Git rebase --interactive @{push}<CR>
692 nnoremap <silent> <leader>ga :Gwrite<cr>
693 nnoremap <silent> <leader>gb :G blame<cr>
694
695 augroup fugitive_gstatus
696 au!
697 autocmd User FugitiveIndex setlocal winfixheight
698 autocmd User FugitiveIndex nmap <buffer> <leader><space> =
699 augroup end
700
701 " Gundo {{{2
702 nnoremap <F7> :GundoToggle<CR>
703 let g:gundo_prefer_python3 = 1
704
705 " indent-guides {{{2
706 let g:indent_guides_default_mapping = 0
707 let g:indent_guides_guide_size = 1
708 nmap <silent> cog <Plug>IndentGuidesToggle
709 nmap <silent> [og <Plug>IndentGuidesEnable
710 nmap <silent> ]og <Plug>IndentGuidesDisable
711
712 " python-mode {{{2
713
714 let g:pymode_rope_completion = 0
715 let g:pymode_rope = 0
716 let g:pymode_run = 0
717 let g:pymode_folding = 1
718 let g:pymode_lint_ignore = "E221,E266,E501"
719 let g:pymode_lint_cwindow = 0 " don't open cwindow when linting
720 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
721
722 " signature {{{2
723 " disable '[ mappings
724
725 let g:SignatureMap = {
726 \ 'GotoNextLineAlpha' : "",
727 \ 'GotoPrevLineAlpha' : "",
728 \ 'GotoNextSpotAlpha' : "",
729 \ 'GotoPrevSpotAlpha' : "",
730 \ }
731
732 " switch
733 let g:switch_mapping = "<Leader>s"
734 let g:switch_custom_definitions = [
735 \ ['yes', 'no']
736 \ ]
737
738 " spellrotate
739 nmap <silent> z] <Plug>(SpellRotateForward)
740 nmap <silent> z[ <Plug>(SpellRotateBackward)
741 vmap <silent> z] <Plug>(SpellRotateForwardV)
742 vmap <silent> z[ <Plug>(SpellRotateBackwardV)
743
744 " synastic {{{2
745 let g:syntastic_enable_highlighting = 0
746 let g:syntastic_error_symbol='E'
747 let g:syntastic_style_error_symbol='S'
748 let g:syntastic_warning_symbol='W'
749 let g:syntastic_style_warning_symbol='S'
750 let g:syntastic_always_populate_loc_list=1
751 nmap <silent> <leader>y :SyntasticCheck<cr>
752
753 let g:syntastic_cpp_clang_tidy_post_args = "-p build*"
754
755 if ! &diff
756 let g:syntastic_check_on_open=1
757 endif
758
759 " tagbar {{{2
760 map <F5> :TagbarToggle<cr>
761 let g:tagbar_sort = 0
762 let g:tagbar_compact = 1
763 let g:tagbar_autoshowtag = 1
764 let g:tagbar_width = 25
765 let g:tagbar_iconchars = ['+', '-']
766
767 " tcomments {{{2
768 let g:tcomment_textobject_inlinecomment = 'gic'
769 let g:tcomment#filetype#guess = 0
770 "let g:tcomment#options = {'whitespace' : 'no'}
771
772 " ultisnips {{{2
773 let g:UltiSnipsEditSplit = 'vertical'
774 let g:UltiSnipsSnippetDirectories = [ expand("$XDG_CONFIG_HOME/vim/ultisnips") ]
775 if has('fname_case')
776 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
777 endif
778 let g:UltiSnipsExpandTrigger = "<tab>"
779 let g:UltiSnipsJumpForwardTrigger = "<tab>"
780 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
781
782 " UltiSnips completion function that tries to expand a snippet. If there's no
783 " snippet for expanding, it checks for completion window and if it's shown,
784 " selects first element. If there's no completion window it tries to jump to
785 " next placeholder. If there's no placeholder it just returns TAB key
786 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
787 function! g:UltiSnips_Complete()
788 call UltiSnips#ExpandSnippet()
789 if g:ulti_expand_res == 0
790 if pumvisible()
791 return "\<C-n>"
792 else
793 call UltiSnips#JumpForwards()
794 if g:ulti_jump_forwards_res == 0
795 return "\<TAB>"
796 endif
797 endif
798 endif
799 return ""
800 endfunction
801 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
802 let g:UltiSnipsListSnippets="<c-e>"
803
804 " unite {{{2
805 call unite#filters#matcher_default#use(['matcher_fuzzy'])
806 call unite#custom#profile('default', 'context', {
807 \ 'winheight': 20,
808 \ 'direction': 'botright'
809 \ })
810
811 nnoremap [unite] <Nop>
812 nmap <leader>u [unite]
813 nnoremap [unite]u :UniteResume<CR>
814 nnoremap <silent> [u :UnitePrevious<CR>
815 nnoremap <silent> ]u :UniteNext<CR>
816
817 " unite-grep {{{3
818 " seems not respected
819 let g:unite_source_grep_max_candidates = 2000
820 if executable('ag')
821 " Use ag in unite grep source.
822 let g:unite_source_grep_command = 'ag'
823 let g:unite_source_grep_default_opts = '--smart-case --vimgrep --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
824 let g:unite_source_grep_recursive_opt = ''
825 end
826 nnoremap <silent> [unite]a :<C-u>Unite grep:.::\12\17<CR>
827 nnoremap <silent> [unite]A :<C-u>Unite grep:.:-w:\12\17<CR>
828 command! -nargs=+ Ag Unite grep:.::<args>
829
830 " unite-file_rec {{{3
831 if executable('ag')
832 " Use ag in unite rec source
833 let g:unite_source_rec_async_command = ['ag', '--follow', '--nocolor', '--nogroup', '-g', '']
834 end
835 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
836 call unite#custom#source('file_rec/async', 'sorters', 'sorter_selecta')
837
838 " unite-buffer {{{3
839 call unite#custom#default_action('buffer', 'open')
840 nnoremap <silent> [unite]b :<C-u>Unite buffer:-<CR>
841
842 " unite-jumplist {{{3
843 nnoremap <silent> [unite]j :<C-u>Unite output:jumps:<CR>
844
845 " unite-menu {{{3
846 let g:unite_source_menu_menus = {}
847 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
848 let g:unite_source_menu_menus.fugitive.command_candidates = {
849 \ 'Gstatus <Leader>gs' : 'Gstatus',
850 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
851 \ 'Glog' : 'Glog',
852 \}
853
854 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
855
856 let g:unite_source_history_yank_enable = 1
857 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
858
859 " yankring {{{2
860 nnoremap <silent> <leader>p :YRShow<cr>
861 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
862 let g:yankring_replace_n_pkey = ''
863 let g:yankring_replace_n_nkey = ''
864
865 " map Y to y$ for the yank ring
866 function! YRRunAfterMaps()
867 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
868 endfunction
869
870 " vim-easy-align {{{2
871 " start interactive EasyAlign in visual mode
872 vmap <Enter> <Esc>:echohl WarningMsg \| echo "EasyAlign mapped to \16<leader>a now" \| echohl None<CR>
873 vmap <leader>a <Plug>(EasyAlign)
874 nmap <leader>a <Plug>(EasyAlign)
875
876 " vim-gtest {{{2
877 let g:gtest#highlight_failing_tests = 0
878
879 nnoremap <silent> <Leader>tt :GTestRun<CR>
880 nnoremap <Leader>tc :GTestCase<space>
881 nnoremap <Leader>tn :GTestName<space>
882 nnoremap <silent> <Leader>ta :GTestCase *<CR>:GTestName *<CR>:GTestRun<CR>
883 nnoremap <silent> <Leader>tu :GTestRunUnderCursor<CR>
884
885 " vim-json {{{2
886 let g:vim_json_syntax_conceal = 0
887
888 " vim-sneak {{{2
889 let g:sneak#streak = 1
890 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
891 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
892
893 " sneaky f and t
894 nmap f <Plug>Sneak_f
895 nmap F <Plug>Sneak_F
896 xmap f <Plug>Sneak_f
897 xmap F <Plug>Sneak_F
898 omap f <Plug>Sneak_f
899 omap F <Plug>Sneak_F
900 nmap t <Plug>Sneak_t
901 nmap T <Plug>Sneak_T
902 xmap t <Plug>Sneak_t
903 xmap T <Plug>Sneak_T
904 omap t <Plug>Sneak_t
905 omap T <Plug>Sneak_T
906
907 " functions {{{1
908
909 " Convenient command to see the difference between the current buffer and the
910 " file it was loaded from, thus the changes you made.
911 " Only define it when not defined already.
912 if !exists(":DiffOrig")
913 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
914 \ | wincmd p | diffthis
915 endif
916
917 " sort operator {{{2
918 function! SortLinesOpFunc(...)
919 '[,']sort
920 endfunction
921 nnoremap <silent> gs :<C-U>set operatorfunc=SortLinesOpFunc<CR>g@
922 vnoremap <silent> gs :sort<cr>
923
924 " edit configs {{{2
925 function! EditConfig(what, ext = '.vim')
926 let l:dir = split(&runtimepath,',')[0]
927 if a:what == 'vimrc'
928 let l:file = expand($MYVIMRC)
929 elseif ! isdirectory(globpath(l:dir, a:what))
930 echoe a:what." is not valid!"
931 elseif empty(&filetype)
932 echoe 'filetype is empty!'
933 else
934 let l:file = l:dir.'/'.a:what.'/'.&filetype.a:ext
935 endif
936
937 execute ':vsplit '.file
938 execute ':lcd %:p:h'
939 endf
940 nmap <leader>ev :call EditConfig('vimrc')<CR>
941 nmap <leader>ef :call EditConfig('ftplugin')<CR>
942 nmap <leader>es :call EditConfig('syntax')<CR>
943 nmap <leader>ei :call EditConfig('indent')<CR>
944 nmap <leader>eu :call EditConfig('ultisnips', '.snippets')<CR>
945
946 " spell check {{{2
947 " http://tex.stackexchange.com/a/52932
948 let g:myLangList=["en_gb","en_us","de","fr"]
949
950 function! ToggleSpell()
951 if !exists("b:myLang")
952 let b:myLang=0
953 endif
954 execute "setlocal spell!"
955 if (&spell)
956 echo "setlocal spelllang=" g:myLangList[b:myLang]
957 endif
958 endfunction
959
960 function! SwitchSpell()
961 if !exists("b:myLang")
962 let b:myLang=0
963 endif
964 if (&spell)
965 let b:myLang=b:myLang+1
966 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
967 endif
968 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
969 echo "setlocal spelllang=" g:myLangList[b:myLang]
970 endfunction
971
972 nnoremap <silent> coS :call SwitchSpell()<CR>
973 " fix spelling with first choice
974 nnoremap <Leader>f 1z=
975
976 " gitdir or home {{{2
977 " from derek wyatt:
978 " http://git.io/v3GAV
979 function! FindGitDirOrHome()
980 let filedir = expand('%:p:h')
981 if isdirectory(filedir)
982 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
983 let gitdir = system(cmd)
984 if strlen(gitdir) == 0
985 return '~'
986 else
987 return gitdir[:-2]
988 endif
989 else
990 return '~'
991 endif
992 endfunction
993 command! Cd cd %:h
994 command! Cdr execute('cd ' . FindGitDirOrHome())
995 command! LCd lcd %:h
996 command! LCdr execute('lcd ' . FindGitDirOrHome())
997
998 " vim:set et sw=2 ts=2 tw=78: