Last active
August 29, 2015 14:09
-
-
Save keith/3d967e331adbb481fd60 to your computer and use it in GitHub Desktop.
Filter buffers through selecta
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! 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
BuffersCommand
function could easily be altered to take a Vim command so that buffers could be opened in other splits and such.