Created
June 8, 2010 19:01
-
-
Save codekoala/430481 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
" Allows you to do ":b ", type the beginning of some open buffer's name, and hit <Tab> to see/select possible matches | |
set wildcharm=<Tab> wildmenu wildmode=full | |
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 | |
" Bind the BufSel() function to a user-command | |
command! -nargs=1 Bs :call BufSel("<args>") | |
" Allows you to hit F14 and begin typing the name of a buffer. If it's not unique, you will see a list of possible options. | |
nnoremap <F14> :Bs<Space> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment