Eduardo Wada
Eduardo Wada

Reputation: 2647

Is there a Visual Studio "go to file in selection" hotkey?

I have some code that looks like this:

@Html.Partial("~/Views/Shared/MyComponent/MyPartial.vbhtml")

The same way I can put the cursor over methods and press F12 to go to the method's definition, I'd like to be able to put my cursor over the "~/Views/Shared/MyComponent/MyPartial.vbhtml" string and press some hotkey combination to navigate to that file.

Is there such hotkey in visual studio?

Vim and Resharper shortcuts accepted

[Edit] Just to add context to one of the scenarios I encountered, I have a folder structure that goes something like this:

.
├─ _Views
|  ├── _Shared
|  |   └── SomePartial.vbhtml
|  └── _SomeComponent
|      └── Index.vbhtml

When I'm in Index.vbhtml I can use @Html.Partial("SomePartial.vbhtml") because asp.net mvc has a convention that if a file can't be found in the current directory it will search in the "Shared" directory.

Upvotes: 1

Views: 561

Answers (2)

Eduardo Wada
Eduardo Wada

Reputation: 2647

In the end I went with Resharper's go to file shortcut, contrary to the documentation mine was unbound and I had to set it to ctrl+shift+t before I could use it.

The difference to VsVim's gf is that it searches the whole visual studio solution rather than the current directory and accepts the "~" character in the path when searching so I can type something like vi" ctrl+shift+t.

Upvotes: 0

Sébastien Lavoie
Sébastien Lavoie

Reputation: 897

The quickest way is gf, as mentioned by @Doktor OSwaldo. Note that this also works in visual mode!

However, there are other interesting options found with :h gf, including:

  • <Ctrl-W><Ctrl-F> to open in a split buffer.
  • If you want any text under the cursor to be opened as a new file when you enter gf, you can create the following mapping: :map gf :e <cfile><CR>
  • If a number follows the name of the file under the cursor (like eval.c:10 or eval.c 40), typing gF will position you at that line number.

Upvotes: 3

Related Questions