-
-
Save billy3321/86545 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" buffer sel by pattern {{{ | |
" ==================================== | |
function! BufSel(pattern) | |
let buf_count = bufnr("$") | |
let cur_bufnr = 1 | |
let nummatches = 0 | |
let firstmatchingbufnr = 0 | |
while cur_bufnr <= buf_count | |
if(bufexists(cur_bufnr)) | |
let currbufname = bufname(cur_bufnr) | |
if(match(currbufname, a:pattern) > -1) | |
echo cur_bufnr . ": ". bufname(cur_bufnr) | |
let nummatches += 1 | |
let firstmatchingbufnr = cur_bufnr | |
endif | |
endif | |
let cur_bufnr = cur_bufnr + 1 | |
endwhile | |
if(nummatches == 1) | |
execute ":buffer ". firstmatchingbufnr | |
elseif(nummatches > 1) | |
let desiredbufnr = input("Enter buffer number: ") | |
if(strlen(desiredbufnr) != 0) | |
execute ":buffer ". desiredbufnr | |
endif | |
else | |
echo "No matching buffers" | |
endif | |
endfunction | |
function! BufSelInput() | |
let pattern = input( "pattern: " ) | |
call BufSel( pattern ) | |
endfunction | |
"Bind the BufSel() function to a user-command | |
command! -nargs=1 Bs :call BufSel("<args>") | |
nmap <leader>bf :call BufSelInput()<CR> | |
" ==================================== | |
" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment