]> git.rmz.io Git - dotfiles.git/blobdiff - vim/vimrc
vim: add more config bindings (ftplugin,syntax,indent)
[dotfiles.git] / vim / vimrc
index fba48a5ec9dc2ce6cea0672d1832387861b64231..2cdb19d88c477dd9ea177477e9c527d25e1e73e6 100644 (file)
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -16,40 +16,52 @@ Plugin 'gmarik/vundle'
 
 Plugin 'airblade/vim-gitgutter'
 Plugin 'bling/vim-airline'
+Plugin 'derekwyatt/vim-fswitch'
 Plugin 'elzr/vim-json'
-Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
+Plugin 'firef0x/pkgbuild.vim'
 Plugin 'junegunn/vim-easy-align'
 Plugin 'kien/ctrlp.vim'
+" Plugin 'klen/python-mode'
+Plugin 'wilywampa/python-mode'
 Plugin 'kshenoy/vim-signature'
 Plugin 'majutsushi/tagbar'
+Plugin 'raimondi/delimitmate'
 Plugin 'rking/ag.vim'
 Plugin 'scrooloose/nerdtree'
 Plugin 'scrooloose/syntastic'
-Plugin 'sirver/ultisnips'
 Plugin 'sjl/gundo.vim'
 Plugin 'tomtom/tcomment_vim'
+Plugin 'tpope/vim-endwise'
 Plugin 'tpope/vim-fugitive'
 Plugin 'tpope/vim-repeat'
 Plugin 'tpope/vim-surround'
 Plugin 'tpope/vim-unimpaired'
 Plugin 'valloric/youcompleteme'
+Plugin 'vim-scripts/yankring.vim'
+
+" snippets
+Plugin 'sirver/ultisnips'
+Plugin 'honza/vim-snippets'
 
+" ros
 Plugin 'ompugao/ros.vim'
 Plugin 'ompugao/ctrlp-ros'
 
-Plugin 'firef0x/pkgbuild.vim'
-Plugin 'derekwyatt/vim-fswitch'
 " seems to have problems right now... may be add later?
 " Plugin 'jalcine/cmake.vim'
 " Plugin 'powerman/vim-plugin-viewdoc'
 
-" endwise needs to be after delimitmate
-Plugin 'raimondi/delimitmate'
-Plugin 'tpope/vim-endwise'
-Plugin 'lokaltog/vim-easymotion'
+" find an alternative
+Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
+" Plugin 'lokaltog/vim-easymotion'
+Plugin 'justinmk/vim-sneak'
 Plugin 'chrisbra/checkattach'
-Plugin 'klen/python-mode'
 Plugin 'nathanaelkane/vim-indent-guides'
+Plugin 'alx741/vinfo'
+
+Plugin 'kana/vim-textobj-user'
+Plugin 'julian/vim-textobj-variable-segment'
+Plugin 'sgur/vim-textobj-parameter'
 
 " remove entries first
 set runtimepath -=$HOME/.vim
@@ -161,7 +173,7 @@ set foldmethod=marker           " folding type
 set foldlevelstart=0            " value for 'foldlevel' when starting to edit a file
 
 " save and restore folds
-set viewoptions=folds,cursor    " don't save local options
+set viewoptions=cursor          " only save cursor position
 
 " diff mode {{{2
 set diffopt=filler,vertical
@@ -169,19 +181,30 @@ set diffopt=filler,vertical
 " reading and writing files {{{2
 set modeline                    " read modelines
 set modelines=2                 " only check first/last 2 lines
+
 set writebackup                 " write a backup file before overwriting a file
 set backup                      " keep a backup after owerwriting a file
-set backupdir=$XDG_CACHE_HOME/vim//
+set backupdir=$XDG_CACHE_HOME/vim/backup//
+
+set backupskip+=.netrc          " skip netrc
+set backupskip+=/dev/shm/pass*  " skip passwordstore files
 
 set undofile                    " persistent undo history
-set undodir=$XDG_CACHE_HOME/vim//
+set undodir=$XDG_CACHE_HOME/vim/undo//
+
+augroup undoskip
+    au!
+    au BufWritePre .netrc         setlocal noundofile
+    au BufWritePre /dev/shm/pass* setlocal noundofile
+    au BufWritePre /tmp/*         setlocal noundofile
+augroup END
 
 set autowrite                   " automatically write a file when leaving a modified buffer
 set autoread                    " automatically read a file that has been modified
 
 " the swap file {{{2
 set noswapfile
-set directory=$XDG_CACHE_HOME/vim//
+set directory=$XDG_CACHE_HOME/vim/swap//
 
 " command line editing {{{2
 set history=5000                " how many command lines are remembered
@@ -202,7 +225,7 @@ set wildignore+=*.orig                           " Merge resolution files
 set virtualedit=block           " let cursor move past last char in <C-V> mode
 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
 
-set viewdir=$XDG_CACHE_HOME/vim
+set viewdir=$XDG_CACHE_HOME/vim/view//
 
 " autocmds {{{1
 " Resize splits when the window is resized {{{2
@@ -241,6 +264,7 @@ augroup END
 map <space> <leader>
 
 " make
+nnoremap <leader>r :make<cr>
 nnoremap <leader><cr> :make<cr>
 
 " unhighlight search
@@ -250,9 +274,6 @@ nnoremap <silent> <Leader>/ :silent nohl<CR>
 nnoremap <leader>[ :tabprev<cr>
 nnoremap <leader>] :tabnext<cr>
 
-" Wrap
-nnoremap <leader>W :set wrap!<cr>
-
 " paste from selection
 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
 " paste from clipboard
@@ -271,15 +292,12 @@ noremap ' `
 " Select (charwise) the contents of the current line, excluding indentation.
 nnoremap vv ^vg_
 
-" Toggle [i]nvisible characters
-nnoremap <leader>i :set list!<cr>
-
 " Unfuck my screen
 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
 
 " Ranger
-nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
-nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
+nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
+nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
 
 " Use sane regexes.
 nnoremap / /\v
@@ -335,9 +353,6 @@ cnoremap <C-L>   <Right>
 " close all folds open fold in cursor
 nnoremap zx zMzxzt
 
-" edit vimrc in new tab
-nmap <leader>ev :tabedit $MYVIMRC<CR>:lcd %:p:h<CR>
-
 map <F1> :ls<CR>:b<space>
 
 nnoremap <C-L> <C-W>w
@@ -360,8 +375,7 @@ noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 " Don't use Ex mode, use Q for formatting
 map Q gq
 
-" allow undoing in insert-mode
-inoremap <C-U> <C-G>u<C-U>
+" break undo sequence before removing word
 inoremap <C-W> <C-G>u<C-W>
 
 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
@@ -380,19 +394,23 @@ autocmd BufWinEnter *.* silent loadview
 " save with sudo
 cnoremap w!! w !sudo tee % > /dev/null
 
-" plugins {{{1
+" uppercase previous word
+inoremap <C-C> <Esc>gUiwgi
+
+" plugins options {{{1
 " ag {{{2
 let g:AgSmartCase = 1
 nnoremap <leader>ag yiw:Ag \12"<cr>
 vnoremap <leader>ag y:Ag \12"<cr>
 
 " airline {{{2
-let g:airline_detect_whitespace=2
+let g:airline#extensions#whitespace#enabled = 1
 let g:airline#extensions#tabline#enabled = 1
 let g:airline_powerline_fonts = 1
 
 " checkattach {{{2
 let g:checkattach_filebrowser = 'ranger'
+let g:checkattach_once = 'y'
 
 " delimitmate {{{2
 let delimitMate_expand_cr = 2
@@ -438,7 +456,10 @@ autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTree
 " python-mode {{{2
 
 let g:pymode_rope_completion = 0
+let g:pymode_rope = 0
 let g:pymode_folding = 1
+let g:pymode_lint_ignore = "E221,E266,E501"
+let g:pymode_syntax_space_errors = 0    " don't bother me when I'm typing
 
 " synastic {{{2
 let g:syntastic_enable_highlighting = 0
@@ -465,16 +486,49 @@ let g:tagbar_iconchars = ['+', '-']
 let g:UltiSnipsEditSplit = 'vertical'
 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
-let g:UltiSnipsExpandTrigger = "<C-L>"
-let g:UltiSnipsJumpForwardTrigger = "<C-L>"
-let g:UltiSnipsJumpBackwardTrigger = "<C-H>"
+let g:UltiSnipsExpandTrigger       = "<tab>"
+let g:UltiSnipsJumpForwardTrigger  = "<tab>"
+let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
+
+" UltiSnips completion function that tries to expand a snippet. If there's no
+" snippet for expanding, it checks for completion window and if it's shown,
+" selects first element. If there's no completion window it tries to jump to
+" next placeholder. If there's no placeholder it just returns TAB key
+" https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
+function! g:UltiSnips_Complete()
+    call UltiSnips#ExpandSnippet()
+    if g:ulti_expand_res == 0
+        if pumvisible()
+            return "\<C-n>"
+        else
+            call UltiSnips#JumpForwards()
+            if g:ulti_jump_forwards_res == 0
+               return "\<TAB>"
+            endif
+        endif
+    endif
+    return ""
+endfunction
+au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
+let g:UltiSnipsListSnippets="<c-e>"
+
+" yankring {{{2
+nnoremap <silent> <leader>p :YRShow<cr>
+let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
+let g:yankring_replace_n_pkey = ''
+let g:yankring_replace_n_nkey = ''
+
+" map Y to y$ for the yank ring
+function! YRRunAfterMaps()
+    nnoremap Y   :<C-U>YRYankCount 'y$'<CR>
+endfunction
 
 " youcompleteme {{{2
 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_autoclose_preview_window_after_insertion = 1
+let g:ycm_autoclose_preview_window_after_insertion = 0
 "let g:ycm_extra_conf_vim_data = ['%:p']
 nnoremap <leader>jd :YcmCompleter GoTo<CR>
 
@@ -490,6 +544,24 @@ let g:tex_flavor='latex'
 let g:Tex_DefaultTargetFormat='pdf'
 let g:Tex_MultipleCompileFormats='pdf'
 
+" vim-sneak {{{2
+let g:sneak#streak = 1
+let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
+let g:sneak#use_ic_scs = 1  " follow 'ignorecase' and 'smartcase'
+
+" sneaky f and t
+nmap f <Plug>Sneak_f
+nmap F <Plug>Sneak_F
+xmap f <Plug>Sneak_f
+xmap F <Plug>Sneak_F
+omap f <Plug>Sneak_f
+omap F <Plug>Sneak_F
+nmap t <Plug>Sneak_t
+nmap T <Plug>Sneak_T
+xmap t <Plug>Sneak_t
+xmap T <Plug>Sneak_T
+omap t <Plug>Sneak_t
+omap T <Plug>Sneak_T
 
 " functions {{{1
 
@@ -501,6 +573,28 @@ if !exists(":DiffOrig")
                   \ | wincmd p | diffthis
 endif
 
+" edit configs  {{{2
+function! EditConfig(what)
+    let l:dir = split(&runtimepath,',')[0]
+    if a:what == 'vimrc'
+        let l:file = expand($MYVIMRC)
+    elseif ! isdirectory(globpath(l:dir, a:what))
+        echoe a:what." is not valid!"
+    elseif empty(&filetype)
+        echoe 'filetype is empty!'
+    else
+        let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
+    endif
+
+    execute ':vsplit '.file
+    execute ':lcd %:p:h'
+endf
+nmap <leader>ev :call EditConfig('vimrc')<CR>
+nmap <leader>ef :call EditConfig('ftplugin')<CR>
+nmap <leader>es :call EditConfig('syntax')<CR>
+nmap <leader>ei :call EditConfig('indent')<CR>
+nmap <leader>eu :UltiSnipsEdit<CR>
+
 " spell check {{{2
 " http://tex.stackexchange.com/a/52932
 let g:myLangList=["en_gb","en_us","de","fr"]
@@ -527,23 +621,6 @@ function! SwitchSpell()
   echo "setlocal spelllang=" g:myLangList[b:myLang]
 endfunction
 
-nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
-nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
+nnoremap <silent> coS :call SwitchSpell()<CR>
 " fix spelling with first choice
 nnoremap <Leader>f 1z=
-
-" Toggle line numbers {{{2
-function! g:ToggleNumber()
-    if !exists("b:relanum")
-        let b:relanum=1
-    endif
-    if &l:number
-        let b:relanum = &relativenumber
-        setlocal nonumber norelativenumber
-    else
-        let &l:relativenumber = b:relanum
-        setlocal number
-    endif
-endfunction
-nnoremap <silent><leader>n :call g:ToggleNumber()<cr>
-nnoremap <silent><leader>N :setlocal relativenumber!<cr>