Selecting resulting files from grep in vim

前端 未结 4 1795
轻奢々
轻奢々 2021-02-02 01:21

After I run a grep search in vim with :grep, I get a list of files. Is there a way to select one of those files and open it in a new tab at that particular line?

4条回答
  •  心在旅途
    2021-02-02 01:48

    Just for completeness, as well as the :copen command, there's also :cw, which only opens the "quickfix" window if there are entries (so if your grep has no results, it won't appear).

    I think the easiest way (without defining a mapping) of making the files open in a new tab would be to do:

    :cw                " Open the quickfix window
    Ctrl-W T           " Switch the window into a new tab
                " Open the file/line
    

    Alternatively, you could do:

    :cw                " Open the quick fix window
    Ctrl-W      " Open the file/line in a new window
    Ctrl-W T           " Move the new window to a new tab
    

    If you want to do it by default, you could probably use the BufEnter and BufLeave autocmds to create and remove a mapping when entering and leaving the quickfix window; however, this is probably not trivial.

    :help :cw
    :help :copen
    :help quickfix
    

提交回复
热议问题