Fandom

Vim Tips Wiki

Jump to recent buffers

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

JumpBuffers() is a routine that will present a list of recent buffers, gathered from the jumplist. Mappings can, of course, be set to taste. I myself use these:

" Note this overrides :goto
nmap go :<C-U>call JumpBuffers()<CR>
nmap <C-G><C-O> 2go
" Remap builtin 'go'
nnoremap g<C-O> go

Note that a count preceding the mapping will bypass the prompt and jump directly to the referenced buffer.

Screenshot

Screen Shot 2016-07-22 at 13.43.07

JumpBuffers source

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

For downloading the latest version, see: https://gist.github.com/themadsens/a446ac55e39b4e770a7a2d997725e662

CommentsEdit

Also on Fandom

Random Wiki