Created
November 9, 2010 15:29
-
-
Save fernandotakai/669230 to your computer and use it in GitHub Desktop.
This file contains 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
function! BufSel(pattern) | |
let bufcount = bufnr("$") | |
let currbufnr = 1 | |
let nummatches = 0 | |
let firstmatchingbufnr = 0 | |
while currbufnr <= bufcount | |
if(bufexists(currbufnr)) | |
let currbufname = bufname(currbufnr) | |
if(match(currbufname, a:pattern) > -1) | |
echo currbufnr . ": ". bufname(currbufnr) | |
let nummatches += 1 | |
let firstmatchingbufnr = currbufnr | |
endif | |
endif | |
let currbufnr = currbufnr + 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment