Search code examples
vimvim-plugin

Search a file and open its folder vim


I am using silver searcher in vim. A lot of times I want to search a file BUT open its folder (to see the other files that are there). How can I do it?


Solution

  • Unless you have a very specific workflow that you didn't disclose, ag is a red herring, here.

    You can open the built-in file explorer in the parent directory of the current file with:

    :Ex
    

    You can also do:

    :e %:h
    

    because of the way Vim falls back to Netrw when you ask it to edit a directory.

    See :help :Explore and its variants, as well as :help filename-modifiers for the :h bit.