Search code examples
vimvim-plugin

Explore filesystem/directories in vim?


What is the best way/plugin to explore filesystem and to open files and directories?


Solution

  • The best way to explore filesystem/directories in Vim is the one that best suits your needs. As it is phrased, this question can't get an answer because there's no "way" universally agreed upon.

    On the other hand, if you want to have an overview of the many ways to explore the filesystem in Vim then, yes, that is a question that can be answered. In a non-exhaustive way, though.

    NERDTree and netrw are already covered. These plugins show you a tree-like list of files and directories that you can act on. Before trying NERDTree, I'd suggest you try your hands on netrw as it comes with Vim by default and offers a much wider range of features than NERDTree. You should look around on http://www.vim.org because there are a bunch of similar plugins.

    On the opposite side of the spectrum, you have Vim's own file handling capabilities. Here is a sample of commands you can use from Vim to open files:

    :e filename     edits filename
    :sp filename    edits filename in an horizontal split
    :vs filename    edits filename in a vertical split
    :tabe filename  edits filename in a new tab
    

    You have tab-completion, just like in the shell:

    :e <tab>        goes through all the directories/files in the working directory
    

    You can use wildcards, of course:

    :e **/*.js<tab> shows all the js files in the working directory and its subdirectories
    

    Assuming you have set wildmenu in your ~/.vimrc, you can make tab-completion even better with an horizontal menu which can be customized further…

    You can also use "args"… but that will be for another time.

    Somewhere between Vim's default commands and netrw/NERDTree you can find a bunch of "fuzzy" and less fuzzy file openers more or less modeled after a feature introduced in TextMate a while ago: FuzzyFinder, LustyExplorer, Command-T, CtrlP and many other variations on the same theme. The core concept is to provide you with a list of choice that you narrow down by typing more characters in a prompt until the file ou want to edit is selected.

    If you decide you want to go down the plugin road, I'd suggest you visit http://www.vim.org, compare what's there, try a few plugins and decide for yourself.

    Anyway, you should get used to the basics before looking for a plugin.