Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigating filesystem in vim -> :find vs. :edit

Tags:

vim

When opening files in Vim I almost always do something like this:

:e subDir/**/file<ctrl-d>

But in the docs and basically every StackOverflow/blog post I have read it seems that people use "find" the way I use "edit".

What am I missing by using the edit command instead of the find command?

like image 923
Jonathan.Brink Avatar asked Oct 02 '15 00:10

Jonathan.Brink


People also ask

How do I navigate to a file in vim?

Select a file or directory name and press Enter to open that file or directory. (For example :e /home/user displays the contents of that directory.) To return to the explorer window, press Ctrl-^ (usually Ctrl-6). You can also "edit" a directory to explore that directory.

How do I navigate faster in vim?

TL;DR: Use for small navigation. Use with relative line numbers. h , j , k and l are the basic movement keys in Vim. They should be used instead of the usual arrow keys on the keyboard to, as discussed above, keep your fingers on the home row as much as possible.


1 Answers

:edit is restricted by default to the working directory: if you need to edit a file that is not under your working directory you will have to provide its absolute path or a path relative to the working directory. Also, you need to provide the necessary globs.

:find is superficially very similar to :edit but the (big) difference is that it finds files in the directories specified in the path option. path is what makes :find a lot more interesting than :edit.

With set path=,, you essentially get the same behavior as :e foo.

With set path=** you essentially get the same behavior as :e **/foo except you don't have to use any glob.

With set path=.,** you also get access to files in the same directory as the current file.

With set path=.,**,/path/to/some/central/vendor/directory you also get access to files from that directory… and so on.

like image 150
romainl Avatar answered Sep 20 '22 22:09

romainl