Quickly navigate Vim's quickfix
and location-list
history using a popup
menu.
Background
Vim remembers the ten last used quickfix lists, and the ten last used
location-lists for each window. The entire quickfix and location-list stack can
be displayed with :chistory
and :lhistory
, respectively. Older quickfix
lists are accessed through :colder
and :cnewer
, or directly with
:[count]chistory
(and similar for location-lists). See :help quickfix-error-lists
for more details.
This plugin will display the quickfix and location-list stack in a popup menu allowing the user to easily switch to an earlier error list. If one of the lists contains different error types, the total number of each error type (E, W, I, N) is shown along with the total number of entries. Unknown error types are displayed in column "?", and empty lists are greyed out.
:Chistory
- Display the quickfix history in a popup window and make the selected list the current list, similar to:[count]chistory
.:Lhistory
- Same as above, but display the location-list history of the current window, similar to:[count]lhistory
.
When switching the quickfix or location list through the popup menu, the plugin
will execute the QuickFixCmdPost
event with the pattern chistory
and
lhistory
, respectively.
Key | Description |
---|---|
j, Down, Tab | Move cursorline down one line. |
k, up, S-Tab | Move cursorline up one line. |
g | Move cursorline to top. |
G | Move cursorline to bottom. |
q | Close the popup menu. |
0 - 9 | Make the respective error list the current list. |
Enter | Accept current selection. Makes the selected list the current list. |
Note: Pressing 0 to 9 will select and automatically close the popup window. 0 will select the 10th error list, or the last one in the stack (most recent one) if there are less than ten lists.
-
Open quickfix and location-list history with Leader+c+h and Leader+l+h, respectively:
nnoremap <Leader>ch <Cmd>Chistory<Cr> nnoremap <Leader>lh <Cmd>Lhistory<Cr>
-
Alternatively, if you're not using the default
Select-mode
mappings (mnemonic: go history):nnoremap gh <Cmd>Chistory<Cr> nnoremap gH <Cmd>Lhistory<Cr>
-
Print a short info of the selected list in the command-line after switching lists:
augroup qf-history autocmd! autocmd QuickFixCmdPost chistory echo printf('Quickfix %d of %d (%d items): %s', \ getqflist({nr: 0}).nr, \ getqflist({nr: '$'}).nr, \ getqflist({size: 0}).size, \ getqflist({title: 0}).title \ ) autocmd QuickFixCmdPost lhistory echo printf('Location-list %d of %d (%d items): %s', \ getloclist(0, {nr: 0}).nr, \ getloclist(0, {nr: '$'}).nr, \ getloclist(0, {size: 0}).size, \ getloclist(0, {title: 0}).title \ ) augroup END
-
Automatically open the quickfix or location-list window after selecting a list in the popup menu:
augroup qf-history autocmd! autocmd QuickFixCmdPost chistory cwindow autocmd QuickFixCmdPost lhistory lwindow augroup END
The appearance of the popup window can be configured through the dictionary
g:qfhistory
. The following entries are supported:
Entry | Description | Default |
---|---|---|
title |
Whether to show a popup window title (0 or 1 ). |
true |
padding |
List with numbers defining the padding inside the popup window. | [1, 1, 1, 1] |
border |
List with numbers (0 or 1 ) specifying whether to draw a border. |
[1, 1, 1, 1] |
borderchars |
List with characters used for drawing the window border. | ['─', '│', '─', '│', '┌', '┐', '┘', '└'] |
borderhighlight |
List with highlight group names used for drawing the border. | ['QfHistory'] |
Note: when only one borderchars
or borderhighlight
item is specified, it
is used on all sides.
The highlighting of the popup window can be changed through the following highlight groups:
Highlight group | Description | Default |
---|---|---|
QfHistory |
Popup window background and normal text. | Pmenu |
QfHistoryHeader |
Top line of the quickfix-history list. | Title |
QfHistoryCurrent |
Character marking the current error list. | Title |
QfHistoryEmpty |
Empty error list. | Comment |
Left: no window border and no window title:
g:qfhistory = {border: [0, 0, 0, 0], title: false}
Center: border with round corners, padding on left and right side:
g:qfhistory = {
padding: [0, 1, 0, 1],
borderchars: ['─', '│', '─', '│', '╭', '╮', '╯', '╰'],
borderhighlight: ['MyBoldPopupBorder']
}
Right: same as middle image but without a window title
g:qfhistory = {
title: false,
padding: [0, 1, 0, 1],
borderchars: ['─', '│', '─', '│', '╭', '╮', '╯', '╰'],
borderhighlight: ['MyBoldPopupBorder']
}
Run the following commands in your terminal:
$ cd ~/.vim/pack/git-plugins/start
$ git clone https://github.com/bfrg/vim-qf-history
$ vim -u NONE -c 'helptags vim-qf-history/doc | quit'
Note: The directory name git-plugins
is arbitrary, you can pick any other
name. For more details see :help packages
. Alternatively, use your favorite
plugin manager.
This plugin was inspired by the Vimways article Colder quickfix lists written by Nick Jensen.
Distributed under the same terms as Vim itself. See :help license
.