I can use getqflist() to get the whole list. But how can I know which is the currently selected item in the list? It is used if :cc [nr] without specifying nr. It is also used for cnext and cprev. But I have no way to extract this info.

  • You can use getline(‘.’) in the quickfix window to get the current line no which essentially is the index. – Ankit Jain Sep 4 '18 at 18:03

If your Vim version is greater than 8.0.1112, then you could ask the value of the 'idx' property of the quickfix list:

:echo get(getqflist({'idx': 0}), 'idx', 0)

See :h getqflist():

If the optional {what} dictionary argument is supplied, then
returns only the items listed in {what} as a dictionary. The
following string items are supported in {what}:

idx     index of the current entry in the list

Note that 'idx' seems to be missing from Neovim at the moment, along with a few other properties.

| improve this answer | |
  • thanks. I do use neovim only. Do you know any plan of neovim to include this feature? – Liu Sha Sep 3 '18 at 2:44
  • Unfortunately, I don't know when this feature will be implemented. I opened the issue #8363 4 months ago, for a similar issue (a new quickfix property not correctly supported). If you know C, you could try to port the Vim patch 8.0.1112 using this tutorial. – user938271 Sep 3 '18 at 10:21
  • Otherwise, you could try this command: :echo matchstr(execute('cc'), '\d\+'), but it may not work in some contexts (e.g. in a code evaluated for a statusline (:h E523)). Also, your cursor position may change; you could move back in the jumplist, or save & restore your position with winsaveview() and winrestview(). – user938271 Sep 3 '18 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.