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 JainCommented Sep 4, 2018 at 18:03
Add a comment
|
1 Answer
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.
-
thanks. I do use neovim only. Do you know any plan of neovim to include this feature?– doraemonCommented Sep 3, 2018 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 knowC
, you could try to port the Vim patch8.0.1112
using this tutorial. Commented Sep 3, 2018 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()
. Commented Sep 3, 2018 at 10:22