Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Project browsing using find
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Project browsing using find
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=1146 |previous=1142 |next=1147 |created=2006 |complexity=basic |author=gautamvsg |version=5.7 |rating=12/6 |category1=File Handling |category2= }} This tip is for loading project files that you know the names for, but do not remember their paths. Usually when you are working on a project and you want to load a particular file that is somewhere deep in the directory hierarchy, you have to either find the file on the command line and then load it into vim, or use vim tab completion to navigate and load the file. You can use vim's "find" feature instead. Make the following entry in you vimrc: <pre> set path=$PWD/** </pre> This will set your path variable to current directory (from which you launched vim) and to all directories under current directory recursively. Now all you have to do is to open vim/gvim from the base directory of your project. Then if there is a file that you want to open but dont remember the path for it, do a <pre> :find <full-file-name-including-extension> </pre> and it will open the file that you want. '''Caveats''' * If you have multiple files with the same name, then you are in trouble. Find will not [[VimTip1234|list them out]] (like cscope/ctags) before it opens the file. You may end up making edits in the wrong file. However, enabling [[Great wildmode/wildmenu and console mouse|wildmenu]] solves this by displaying the possible matches and allows you to choose which file you want to edit. * The find does not take any wildcards. So you cannot afford to make spelling mistakes in the file names (esp. java names) In spite of the caveats, finding in this manner is far faster than navigating through directories to look for files (esp. if you are a touch typist.) '''Variations''' * You can change your path variable anytime to change the find path. * You can use <code>:sfind</code> instead of <code>:find</code> to open it in a split window, and <code>:tabf</code> to open it in a new tab. * Coupled with cscope (see :help cscope) you editing code across files becomes very convenient. ==Comments== Since v58 of netrw, there's <pre> :Explore **/pattern </pre> which brings up directory listings based on files matching the pattern. For example: <pre> :Explore **/*.txt </pre> The cursor is left on the matching file so it can be brought up easily. To skip from one matching file to the next: <pre> :Nexplore (or, if you have a mouse enabled: <s-down>) :Pexplore (or, if you have a mouse enabled: <s-up>) </pre> ---- See also {{script|id=949|text=qf}}. ---- There was a previous tip in the same thematics. See [[Open file under cursor]]. Regarding the fact several files may match, you can have a look at the plugin {{script|id=229|text=SearchInRuntime}} I'm maintaining. The commands defined don't have any problem with wildcards, they even support auto-completion. It does not provide a command to edit in the current buffer, but two commands to edit in a split (horizontally or vertically) window. If the file is already opened in a window, we jump to that window. Vim 7 is required. (Surely you mean "edit in the current window", not buffer.) ---- On Windows use, <code>set path=.\**</code> ----
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:Script
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab