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.
Asked
Active
Viewed 672 times
4
doraemon
- 1,667
- 11
- 27
-
You can use getline(‘.’) in the quickfix window to get the current line no which essentially is the index. – Ankit Jain Sep 04 '18 at 18:03
1 Answers
4
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.
user938271
- 5,947
- 1
- 15
- 24
-
thanks. I do use neovim only. Do you know any plan of neovim to include this feature? – doraemon Sep 03 '18 at 02:44
-
Unfortunately, I don't know when this feature will be implemented. I opened the issue
#83634 months ago, for a similar issue (a new quickfix property not correctly supported). If you knowC, you could try to port the Vim patch8.0.1112using this tutorial. – user938271 Sep 03 '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 withwinsaveview()andwinrestview(). – user938271 Sep 03 '18 at 10:22