+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>"
+
+" unite {{{2
+call unite#filters#matcher_default#use(['matcher_fuzzy'])
+call unite#custom#profile('default', 'context', {
+ \ 'winheight': 20,
+ \ 'direction': 'botright'
+ \ })
+
+nnoremap [unite] <Nop>
+nmap <leader>u [unite]
+
+" unite-grep {{{3
+" seems not respected
+let g:unite_source_grep_max_candidates = 2000
+if executable('ag')
+ " Use ag in unite grep source.
+ let g:unite_source_grep_command = 'ag'
+ let g:unite_source_grep_default_opts = '--smart-case -w --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
+ let g:unite_source_grep_recursive_opt = ''
+end
+nnoremap <silent> [unite]a :<C-u>Unite grep -input=\12\17<CR>
+
+" unite-file_rec {{{3
+if executable('ag')
+ " Use ag in unite rec source
+ let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
+end
+nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
+
+" unite-buffer {{{3
+call unite#custom#default_action('buffer', 'goto')
+nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
+
+" unite-menu {{{3
+let g:unite_source_menu_menus = {}
+let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
+let g:unite_source_menu_menus.fugitive.command_candidates = {
+ \ 'Gstatus <Leader>gs' : 'Gstatus',
+ \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
+ \ 'Glog' : 'Glog',
+ \}
+
+nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
+
+let g:unite_source_history_yank_enable = 1
+nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
+
+" 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