2014-01-05 118 views
64

以下是關於quickfix列表和位置列表的文檔。但我不確定實際上有什麼不同。下圖顯示了位置列表和quickfix列表中的相同內容。我什麼時候在vimgrep和lvimgrep中使用一個或另一個。vim中位置列表和quickfix列表有什麼區別

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. 

... 

enter image description here

UPDATE

我發現下面的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. 

所以區別在於quickfix列表和本地窗口的位置列表的所有窗口。不過,我可以從任何其他窗口打開位置列表。那麼有什麼區別?

回答

72

位置列表位於當前窗口的本地,因此您可以擁有與windows一樣多的位置列表:30個窗口?沒問題,這是您的30個併發位置列表。

quickfix列表是全局性的,因此一次只能有一個以上的可用空間。有一些命令允許你用前一個替換當前的quickfix列表,但你不能有兩個併發的quickfix列表。

請勿將位置/ quickfix「lists」(數據結構)與位置/ quickfix「windows」(顯示這些數據結構的內容的窗口)混淆。 「窗口」具有相似的行爲,但「列表」則不行。區別很重要,因爲這些窗口並不是與這些列表進行交互的唯一方式:有許多命令允許我們移動這些列表而不是打開關聯的窗口,並且知道這些列表之間的區別是使用這些列表的關鍵命令有效。

動手圖示的例子:

$ vim -O foo.txt bar.txt

  1. 不要在foo.txt:lvim foo %創建用於包含foo.txt窗口中的位置列表。

  2. :lne幾次跳轉到foofoo.txt

  3. 專注於bar.txt和做:lne。怎麼了?

  4. 現在,請:lvim bar %bar.txt中創建包含bar.txt的窗口的位置列表。

  5. :lne幾次。你跳到什麼比賽?在哪個緩衝區?在哪個窗口?

  6. 切換到另一個窗口,並幾次執行:lne。怎麼了?

  7. 再次切換到bar.txt:lne做什麼?

  8. 現在,做:vim bar %bar.txt創建一個quickfix列表。

  9. :cn幾次跳到幾個barbar.txt

  10. 現在,重點關注foo.txt:cn做什麼?

你跳與:lne位置取決於你在窗口上,但你跳與:cn誤差始終是相同的(除非您更換爲另一個當前quickfix列表)。

這兩個列表都具有相對明確的角色IMO:quickfix列表(因此quickfix窗口)通常在邏輯上專門用於錯誤,而位置列表似乎適合於搜索。

+6

更一般地說:當您的搜索或編譯涉及多個文件時,quickfix列表是最好的,當只涉及單個文件時,最好的位置列表。 –

+1

特別是,如果你用'-q errors.txt'啓動vim,在把'errors.txt'(即'gcc-Wall * .c> errors.txt 2>&1')編譯錯誤後,vim會填充quickfix列表中的編譯錯誤列表,非常方便。 – Kevin

+0

Yahoo!很好的解釋! –

相關問題