]> git.rmz.io Git - dotfiles.git/blobdiff - vim/vimrc
vim/qf: open quickfix windows at the very bottom
[dotfiles.git] / vim / vimrc
index 9303fc47d24442ff354b29fc8fa093faa3c5cef3..2cbf3b6d53ee1c46bcd7f58631f7fd55e5a6ee78 100644 (file)
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -266,6 +266,8 @@ set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but s
 
 set viewdir=$XDG_CACHE_HOME/vim/view//
 
+set sessionoptions+=unix,slash  " damn windows and it's silly ways
+
 " autocmds {{{1
 " Resize splits when the window is resized {{{2
 augroup resize
@@ -297,6 +299,24 @@ augroup cursor_pos
                 \ endif
 augroup END
 
+" Check for file modifications automatically {{{2
+" (current buffer only)
+" Use :NoAutoChecktime to disable it (uses b:autochecktime)
+fun! MyAutoCheckTime()
+  " only check timestamp for normal files
+  if &buftype != '' | return | endif
+  if ! exists('b:autochecktime') || b:autochecktime
+    checktime %
+    let b:autochecktime = 1
+  endif
+endfun
+augroup MyAutoChecktime
+  au!
+  au FocusGained,BufEnter,CursorHold,InsertEnter * call MyAutoCheckTime()
+augroup END
+command! NoAutoChecktime let b:autochecktime=0
+command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime
+
 " bindings {{{1
 
 " allow both <space> and / to be <leader>
@@ -318,8 +338,21 @@ nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
 " paste from clipboard
 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
 
-" Clean trailing whitespace
-nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
+" strip trailing whitespace
+function! StripWhitespace(line1, line2, ...)  " {{{2
+  let s_report = &report
+  let &report=0
+  let pattern = a:0 ? a:1 : '[\\]\@<!\s\+$'
+  let oldview = winsaveview()
+  exe 'keepjumps keeppatterns '.a:line1.','.a:line2.'substitute/'.pattern.'//e'
+  if oldview != winsaveview()
+    redraw
+  endif
+  call winrestview(oldview)
+  let &report = s_report
+endfunction  " }}}2
+command! -range=% -nargs=0 -bar Untrail keepjumps call StripWhitespace(<line1>,<line2>)
+nnoremap <silent> <leader>ww :Untrail<CR>
 
 " Source
 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
@@ -403,7 +436,9 @@ nnoremap <MiddleMouse> i<MiddleMouse>
 vnoremap <MiddleMouse> s<MiddleMouse>
 
 " fix legacy vi inconsistency
-map Y y$
+nnoremap Y y$
+" copy to clipboard
+xnoremap Y "+y
 
 " allow repeat operator on visual
 vnoremap . :normal .<CR>
@@ -426,6 +461,11 @@ for idt in range(1,8)
   exe 'nnoremap co'.idt.' :set tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
 endfor
 
+" toggle auto format of text
+nnoremap coa :set <C-R>=&formatoptions =~ "a" ? 'formatoptions-=a' : 'formatoptions+=a'<CR><CR>
+nnoremap [oa :set formatoptions+=a<CR>
+nnoremap ]oa :set formatoptions-=a<CR>
+
 " space will toggle current fold in normal mode
 nnoremap <leader><Space> za
 " create folds around visual selection
@@ -525,7 +565,9 @@ let g:tagbar_iconchars = ['+', '-']
 " ultisnips {{{2
 let g:UltiSnipsEditSplit = 'vertical'
 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
-let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
+if has('fname_case')
+  let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
+endif
 let g:UltiSnipsExpandTrigger       = "<tab>"
 let g:UltiSnipsJumpForwardTrigger  = "<tab>"
 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
@@ -615,9 +657,11 @@ let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
 let g:ycm_extra_conf_vim_data = ['getcwd()']
 let g:ycm_add_preview_to_completeopt = 1
+let g:ycm_complete_in_comments = 1
+let g:ycm_complete_in_strings  = 1
 let g:ycm_autoclose_preview_window_after_insertion = 0
 "let g:ycm_extra_conf_vim_data = ['%:p']
-nnoremap <leader>jd :YcmCompleter GoTo<CR>
+nnoremap gd :YcmCompleter GoTo<CR>
 
 " vim-easy-align {{{2
 " start interactive EasyAlign in visual mode