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