Last active
June 6, 2022 13:23
-
-
Save bfrg/2efcf50c6bda43dc9277de4bc346d5dc to your computer and use it in GitHub Desktop.
Print the quickfix (or location-list) history and switch to selected list
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
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