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