Skip to content

Instantly share code, notes, and snippets.

@lericson
Created November 1, 2023 10: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 lericson/99324d94684bd0738d4edff2c60311e9 to your computer and use it in GitHub Desktop.
Save lericson/99324d94684bd0738d4edff2c60311e9 to your computer and use it in GitHub Desktop.
Vim function: Jump to Previous Buffer in Jumplist
fun! JumpPreviousBuffer()
let [jumplist, curjump] = getjumplist()
let tgtjump = curjump - 1
while 0 <= tgtjump && jumplist[tgtjump]['bufnr'] == bufnr()
let tgtjump -= 1
endwhile
if tgtjump < 0
echoerr 'No previous buffer in jumplist'
return
endif
execute "normal! " .. (curjump - tgtjump) .. "\<c-o>"
endfun
nnoremap <Leader>o <Cmd>call JumpPreviousBuffer()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment