8

In PhpStorm:

Is there a fast way for inserting relative path to other file (ex. css,js, image files) in another one? (Perhaps by dragging file in code position)

6
  • 1) No -- there was this kind of request (to create <script> tag when drag&drop js file into document), but it was rejected. 2) Unfortunately No :( Commented Feb 23, 2012 at 13:38
  • 1
    On another hand -- if you select such file in Project View panel, then you can use context menu -> Copy reference -- this will be relative to the resources root. Commented Feb 23, 2012 at 14:52
  • 1
    "Drag and drop coding is not our style." -- I personally agree with such statement. But will not object if such funtionality would be present either. youtrack.jetbrains.com/issue/WI-9767 Commented Feb 23, 2012 at 18:39
  • 1
    In any case -- search Issue Tracker for issue #2. If not there -- you can submit a Feature Request -- I would vote for it. Commented Feb 23, 2012 at 18:40
  • 1
    +1 I completely agree that this is a missing feature in PhpStorm. Assistance with relative paths is an essential IDE feature, IMO. Commented Feb 24, 2012 at 8:35

2 Answers 2

16

Ctrl + Space + Space

Hold Ctrl and press Space twice...

Autocompletes relative path...

Sign up to request clarification or add additional context in comments.

1 Comment

This is the best solution, though dragging it in would be great too. in my example, create an <img src="your-image.png then press Ctrl + Space + Space and the relative path auto completes. Thanks for this @Ishan!
6

No, there isn't anything that I would consider "fast" but there are a few tricks that I've found to be useful.

In a large number of contexts PHPStorm will by way of it's auto-complete help you form your relative files references. For example, when typing a PHP require statement, you can use completion to get a list of files and directories in the auto-complete popup, and use that to help you navigate and create the string you want:

enter image description here

The auto-complete doesn't seem to always happen automatically, but you can invoke it. My keyboard shortcut is CTRL+SPACE. From the menu, it's Code -> Completion -> Basic.

You can also use the Copy Reference function available by right-clicking on the file in the Project explorer. This will put a string in your clipboard starting at the project root directory. For example, if your project is located at c:\my\project, and your file is located at c:\my\project\web\assets\js\myscript.js, the string copied will be \web\assets\js\myscript.js.

enter image description here

I tend to use either of these methods depending on what context my cursor is currently in, and whether or not my hand is on the mouse at that moment or not. By far the most useful feature is the auto-complete. I use it very often when creating strings to resources in both HTML and PHP files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.