vim中的位置列表和quickfix列表有什么区别

 翔云飘雪9_694_492 发布于 2023-02-06 14:22

以下内容来自有关quickfix列表和位置列表的文档.但我不确定究竟有什么不同.下图显示了位置列表和quickfix列表中的相同内容.我什么时候在vimgrep和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

我从这里找到了以下内容.

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列表的窗口和用于位置列表的本地窗口.但是我可以从任何其他窗口打开位置列表.那么有什么不同呢?

1 个回答
  • 位置列表是当前窗口的本地列表,因此您可以拥有与窗口一样多的位置列表:30个窗口?没问题,这是您的30个并发位置列表.

    quickfix列表是全局的,因此您一次不能有多个可用的列表.有些命令允许您将当前的quickfix列表替换为前一个,但是您不能有两个并发的quickfix列表.

    不要将位置/ quickfix"列表"(数据结构)与位置/ quickfix"windows"(显示这些数据结构内容的窗口)混淆."窗口"有类似的行为,但"列表"没有.差别很重要,因为这些窗口不仅是与这些列表交互的唯一方式:有许多命令允许我们在打开相关窗口的情况下浏览这些列表,并且知道这些列表之间的差异是有效使用这些命令的关键.

    动手插图示例:

    $ vim -O foo.txt bar.txt

      不要:lvim foo %foo.txt创建包含窗口的位置列表foo.txt.

      :lne了几次跳几个foofoo.txt.

      专注bar.txt并做:lne.怎么了?

      现在,:lvim bar %进入bar.txt为包含的窗口创建位置列表bar.txt.

      :lne几次.你跳到什么地方?在哪个缓冲区?在哪个窗口?

      切换到另一个窗口并做:lne几次.怎么了?

      再次切换到bar.txt.怎么:lne办?

      现在,做:vim bar %bar.txt创建quickfix列表.

      :cn了几次跳几个barbar.txt.

      现在,关注foo.txt,做:cn什么?

    您跳转到的位置:lne取决于您所在的窗口,但跳转到的错误:cn始终相同(直到您将当前的quickfix列表替换为另一个).

    两个列表都有相对清晰的角色IMO:quickfix列表(因此quickfix窗口)通常和逻辑上专门用于错误,位置列表似乎(对我来说)适合搜索.

    2023-02-06 14:34 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有