What is the difference between location list and quickfix list in vim
The following is from the documentation about the quickfix list and location list. But I am not sure what actually different. The image below shows the same things from the location list and quickfix list. When do I use one or another in vimgrep and lvimgrep.
In Vim the quickfix commands are used more generally to find a list of positions
in files.For example, |:vimgrep| finds pattern matches. You can use the positions
in a script with the |getqflist()| function. Thus you can do a lot more than the
edit/compile/fix cycle!
...
...
*location-list* *E776*
A location list is similar to a quickfix list and contains a list of positions
in files. A location list is associated with a window and each window can have
a separate location list. A location list can be associated with only one window.
The location list is independent of the quickfix list.
...
UPDATE
I found the following from here.
These commands all fill a list with the results of their search. "grep" and
"vimgrep" fill the "quickfix list", which can be opened with :cw or :copen,
and is a list shared between ALL windows. "lgrep" and "lvimgrep" fill the
"location list," which is local to the current window, and can be opened
with :lw or :lopen. Both of these lists can be used to instantly jump to
the matching line in whatever file it occurs in.
So the difference is all windows for quickfix list and local window for location list. However I can open location list from any other windows. So what is the difference then??
Solution 1:
The location list is local to the current window so you can have as many location lists as windows: 30 windows? No problem, here are your 30 concurrent location lists.
The quickfix list is global so you can't have more than one available at a time. There are commands that allow you to replace the current quickfix list with a previous one but you can't have two concurrent quickfix lists.
Don't confuse the location/quickfix "lists" (the data structures) with the location/quickfix "windows" (the windows displaying the content of those data structures). The "windows" have similar behaviors but the "lists" don't. The difference is important because those windows are thankfully not the only ways to interact with those lists: there are many commands that allow us to move through those lists without opening the associated windows and knowing the difference between those lists is key to using those commands efficiently.
Hands-on illustrated example:
-
Do
:lvim foo %
infoo.txt
to create a location list for the window containingfoo.txt
. -
Do
:lne
a few times to jump to a fewfoo
infoo.txt
. -
Focus on
bar.txt
and do:lne
. What happens? -
Now, do
:lvim bar %
inbar.txt
to create a location list for the window containingbar.txt
. -
Do
:lne
a few times. What matches do you jump to? In which buffer? In which window? -
Switch to the other window and do
:lne
a few times. What happens? -
Switch again to
bar.txt
. What does:lne
do? -
Now, do
:vim bar %
inbar.txt
to create a quickfix list. -
Do
:cn
a few times to jump to a fewbar
inbar.txt
. -
Now, focus on
foo.txt
, what does:cn
do?
Conclusion: the location you jump to with :lne
depends on the window you are in, which makes the location list local to a window, but the error you jump to with :cn
is not, which makes the quickfix list global.
Both lists have relatively clear roles IMO: the quickfix list (and thus the quickfix window) is usually and quite logically devoted to errors and the location list seems (to me) fit for search.