Last active
July 22, 2016 11:59
-
-
Save themadsens/a446ac55e39b4e770a7a2d997725e662 to your computer and use it in GitHub Desktop.
In vim, show a list of recent buffers to jump to. List is created from the jumplist
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! JumpBuffers() | |
let jumptxt = "" | |
redir! => jumptxt | |
silent jumps | |
redir END | |
let byName = {} | |
let byIndex = [] | |
for line in reverse(split(jumptxt, '\n')) | |
let name = strpart(line, 16) | |
let bufno = bufnr(name) | |
if len(name) > 0 && bufno >= 0 && !has_key(byName, name) | |
let byIndex += [{'name': name, 'bufno': bufno, 'ix': len(byIndex)+1}] | |
let byName[name] = len(byIndex) | |
endif | |
endfor | |
if v:count > 0 | |
if len(byIndex) >= v:count | |
echomsg "Count ".v:count." Jumps to ".byIndex[v:count-1].bufno | |
execute "buffer ".byIndex[v:count-1].bufno | |
endif | |
return | |
endif | |
echohl Special | |
echo "No Buffer Name" | |
echohl None | |
for ent in byIndex | |
echo printf("%2d %6d %s", ent.ix, ent.bufno, ent.name) | |
endfor | |
let ix = input("Type number and <Enter> (empty cancels): ") + 0 | |
if ix > 0 && ix <= len(byIndex) | |
execute "buffer ".byIndex[ix-1].bufno | |
endif | |
endfunc | |
nmap g<C-O> :<C-U>call JumpBuffers()<CR> | |
" Note this overrides :goto | |
nmap go :<C-U>call JumpBuffers()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment