Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Created December 13, 2011 14:22
Show Gist options
  • Select an option

  • Save AndrewRadev/1472282 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewRadev/1472282 to your computer and use it in GitHub Desktop.
Simple jumping through buffers
command! -nargs=1 -complete=custom,s:TabjCompletion Tabj call s:Tabj(<f-args>)
function! s:Tabj(name)
for i in range(tabpagenr('$'))
let tabnr = i + 1
for bufnr in tabpagebuflist(tabnr)
if stridx(bufname(bufnr), a:name) >= 0
exe 'tabnext '.tabnr
while bufnr('%') != bufnr
wincmd w
endwhile
return
endif
endfor
endfor
echoerr 'Buffer "'.a:name.'" not found'
endfunction
function! s:TabjCompletion(A, L, P)
let buffer_names = {}
for i in range(tabpagenr('$'))
let tabnr = i + 1
for bufnr in tabpagebuflist(tabnr)
let buffer_names[bufname(bufnr)] = 1
endfor
endfor
return join(keys(buffer_names), "\n")
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment