What is the difference between location list and quickfix list in vim

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:

$ vim -O foo.txt bar.txt

  1. Do :lvim foo % in foo.txt to create a location list for the window containing foo.txt.

  2. Do :lne a few times to jump to a few foo in foo.txt.

  3. Focus on bar.txt and do :lne. What happens?

  4. Now, do :lvim bar % in bar.txt to create a location list for the window containing bar.txt.

  5. Do :lne a few times. What matches do you jump to? In which buffer? In which window?

  6. Switch to the other window and do :lne a few times. What happens?

  7. Switch again to bar.txt. What does :lne do?

  8. Now, do :vim bar % in bar.txt to create a quickfix list.

  9. Do :cn a few times to jump to a few bar in bar.txt.

  10. 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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)