Skip to content

Instantly share code, notes, and snippets.

@keith
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keith/3d967e331adbb481fd60 to your computer and use it in GitHub Desktop.
Save keith/3d967e331adbb481fd60 to your computer and use it in GitHub Desktop.
Filter buffers through selecta
function! Buffers()
let ids = filter(range(1, bufnr('$')),
\ 'empty(getbufvar(v:val, "&bt"))'
\ . ' && getbufvar(v:val, "&bl")')
let names = []
for id in ids
call add(names, bufname(id))
endfor
return join(names, "\n")
endfunction
function! BuffersCommand()
let buffers = Buffers()
try
let selection = system("echo \"" . buffers . "\" | selecta")
let idx = index(split(buffers), split(selection)[0])
catch /Vim:Interrupt/
redraw!
return
endtry
redraw!
execute ":buffer" . (idx + 1)
endfunction
nnoremap <leader>v :call BuffersCommand()<CR>
@keith
Copy link
Author

keith commented Nov 12, 2014

The BuffersCommand function could easily be altered to take a Vim command so that buffers could be opened in other splits and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment