<commit_before>" original problem: :B command that extends :b such that I don't have to hit *
" Authors: Antony_, igemnace, markzen on #vim

function! QuickBuffer(pattern) abort
  redraw
  let p = substitute(a:pattern, '\s\+$', '', '')
  if empty(p)
    call feedkeys(":B \<C-d>")
    return
  elseif p is '*'
    call feedkeys(":ls!\<cr>:B ")
    return
  elseif p =~ '^\d\+$'
    execute 'buffer' p
    return
  endif
  let l:globbed = '*' . join(split(p, '\s\+'), '*') . '*'
  try
    execute 'buffer' l:globbed
  catch
    call feedkeys(':B ' . l:globbed . "\<C-d>\<C-u>B " . p, 'n')
  endtry
endfunction

command! -nargs=* -complete=buffer B call QuickBuffer(<q-args>)<commit_msg>Integrate upgrades into quick-buffer.vim<commit_after>" original problem: :B command that extends :b such that I don't have to hit *
" Authors: Antony_, igemnace, markzen on #vim

function! QuickBuffer(pattern, split) abort
  redraw

  " normalize commands between split and non-split
  if a:split
    let bufcmd = "sbuffer"
    let qbcmd = "SB"
  else
    let bufcmd = "buffer"
    let qbcmd = "B"
  endif

  " trim trailing whitespace
  let pattern = substitute(a:pattern, '\s\+$', '', '')

  " catch known patterns
  if empty(pattern)
    call feedkeys(":".qbcmd." \<C-d>")
    return
  elseif pattern is '*'
    call feedkeys(":ls!\<cr>:".qbcmd." ")
    return
  elseif pattern =~ '^\d\+$' || bufexists(pattern)
    execute bufcmd pattern
    return
  endif

  " add globstars where spaces exist
  if stridx(a:pattern, ' ') isnot -1
    let globbed = '*' . join(split(pattern, '\s\+'), '*') . '*'
  else
    let globbed = pattern
  endif

  try
    execute bufcmd globbed
  catch
    " :buffer throws when there are several matching buffers
    " in which case, display matching buffers with <C-d>
    " then repopulate commandline for convenience
    call feedkeys(qbcmd . globbed . "\<C-d>\<C-u>" . qbcmd . ' ' . pattern, 'n')
  endtry
endfunction

command! -nargs=* -complete=buffer B call QuickBuffer(<q-args>, 0)
command! -nargs=* -complete=buffer SB call QuickBuffer(<q-args>, 1)
{'fraction_non_alphanumeric': 0.15139826422372227, 'fraction_numerical': 0.0014464802314368371, 'mean_word_length': 3.1666666666666665, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '939276', 'n_tokens_mistral': 737, 'n_tokens_neox': 710, 'n_words': 220}