Vim Recipes ‣ Other Uses of Vim ‣ Browsing Directories
You want to see the contents of a directory, perhaps so as to select a file to edit. For instance, if working on a project comprising multiple files you want to see a list of the files in a separate window.
Invoke Vim with a directory name as an argument, e.g. vim ~/projects/flying-pigs/. From within Vim use the :Ex (mnemonic: Explore) command. By default it shows the contents of the current file's directory, but you can provide a directory name if you wish. For example: :Ex ~/projects/flying-pigs. The directory is shown in a split screen if the current file has been modified.
To force a directory listing in a split pane, so you can view a file and its directory listing at once, use :SexNo, that's not a joke; the concept is synonymous with Vim. Similarly, :Vex to browse in a vertical split, and :Tex to browse in a new tab.
By default Vim lists every file contained in a directory. To get a more ls-style listing you can specify a hiding list with :let g:netrw_listhide='\^\..*'. (This is a comma-separated list of regular expressions). When you're browsing a directory files starting with a period will now be hidden. By Unix/Linux convention filenames which begin with a period are designated hidden. By default file browsers and other utilities ignore these files unless explicitly commanded not to. If you hit a once you'll invert the hiding list (showing only hidden files). If you hit a again you'll remove the hiding list, showing everything.
To change how directory entries are sorted you can modify the g:netrw_sort_sequence variable. By default its value is, deep breath:
[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
The order of the patterns is the order of the sort. For instance, the first pattern matches directories, so they're shown first. The next pattern matches file names ending with *.h (C header files), so they're shown next. And so on. The * pattern matches everything not matched by the other patterns. You can change this pattern on-the-fly by hitting S while viewing a directory listing.
You can change into a directory by selecting it and hitting Enter. The same thing works for files. If you'd rather open a file in a new buffer use p. P will open the file in a split screen.
If you want to operate on the files you see read Using Vim as a File Manager.