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