bairui

Buffalo() the buffer follower

Mar 9th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.53 KB | None | 0 0
  1. " Automatically open buffer when shortest partial tab expands to unique name
  2. " Barry Arthur, Mar 10 2012
  3.  
  4. function! Buffalo()
  5.   call g:bl.update()
  6.   let cmdline = getcmdline()
  7.   let cmd = substitute(cmdline, '^\(\w\+\s\+\).*', '\1', '')
  8.   let partial = substitute(cmdline, '^'.cmd, '', '')
  9.   let bl = g:bl.filter('v:val["name"] =~ "' . partial . '"')
  10.   if len(bl.buffers) == 1
  11.     return substitute(bl.to_s('%n'), "^".partial, '', '') . "\<CR>"
  12.   else
  13.     return "\<c-d>"
  14.   endif
  15. endfunction
  16.  
  17. cnoremap <expr> <tab> Buffalo()
Advertisement
Add Comment
Please, Sign In to add comment