Skip to content

Instantly share code, notes, and snippets.

@bfrg
Last active June 6, 2022 13:23
Show Gist options
  • Save bfrg/2efcf50c6bda43dc9277de4bc346d5dc to your computer and use it in GitHub Desktop.
Save bfrg/2efcf50c6bda43dc9277de4bc346d5dc to your computer and use it in GitHub Desktop.
Print the quickfix (or location-list) history and switch to selected list
vim9script
# Print the quickfix (or location-list) history and switch to the selected list
# Alternative: https://github.com/bfrg/vim-qf-history
def Errorlists(loclist: bool)
const Xgetlist = loclist ? function('getloclist', [0]) : function('getqflist')
const nr: number = Xgetlist({nr: '$'}).nr
if !nr
echomsg 'No entries'
return
endif
execute loclist ? 'lhistory' : 'chistory'
echohl Question
inputsave()
const answer: number = input('Switch to ' .. (loclist ? 'location-list' : 'quickfix') .. ' number: ', '')->str2nr()
inputrestore()
echohl None
if answer < 1
return
endif
silent execute ':' .. (answer > nr ? nr : answer) .. (loclist ? 'lhistory' : 'chistory')
enddef
nnoremap <leader>ch <scriptcmd>Errorlists(false)<cr>
nnoremap <leader>lh <scriptcmd>Errorlists(true)<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment