"Goto File" by Selection

From EditPlus Wiki
Jump to: navigation, search

In some programming languages which allows "include" or "import", you might reference several files in a file, and sometimes, you will need to open the referenced file while you editing the main file. You may wish to open the file in a easier fashion without navigating through several folders in the "Directory" window.

Purpose

Let's take a look at an example:

You have opened a file "C:\web\webpage\sample.html", and a line in that file looks like that:

<script language="javascript" src="../script/client.js"></script>

So, the location of the "client.js" is "C:\web\script\client.js". You highlight (select) the string "../script/client.js" in that line, and wish to open the file immediately, without navigating to the "C:\web\script" folder.

Solution

Deprecated: Nowadays, from EditPlus 2.20 build 236 on, you can use File Menu/Other/Open Selection command to do things discussed in this topic, there's no need to use this trick any more. (However, the author has not provided a button to do this yet.)

Here's the trick:

  1. Open the "Preferences" dialog
  2. Configure your Editplus to run in Single Instance mode (in the General category of the dialog, UNCHECK the "Allow multiple instances").
  3. Add a new User Tool in the "Tools/User Tools" section of the "Preferences" dialog.
    1. Menu text: "Goto File" (or something else you like)
    2. Command: the location of your EditPlus, for example, mine is "D:\Projects\EditPlus\editplus.exe" (WITHOUT quotation marks). For long directory and file names, use "dos-notation": "C:\progra~1\EditPl~1\editplus.exe"
    3. Argument: "$(CurSel)" (WITH quotation marks)
    4. Initial directory: $(FileDir)
    5. Uncheck all checkboxes below
  4. Press "OK" to close the "Preferences" dialog.
  5. Try it. When you want to open a file by text selection, use the tool that we created just now.

Usage

  1. Open a file that references other files
  2. Select (highlight) the refenrece string, such as "../script/client.js" (WITHOUT quotation marks)
  3. Hit the tool "Goto File"
  4. EditPlus should open the file, located relative to the currently opened file, if it exists.

Go Further! For Programmers (NOT deprecated yet)

For C++, C#, Java programmers, they are likely to save their classes, interfaces in forms like these: CMyClassName.cpp, MyClassName.cs, MyInterface.Java. Here we go further to help our programming a little easier. With the tool below, we can quickly switch/open/create files of the same type in the same folder.

  1. Do as the Solution section says in this trick: Configure your Editplus to run in Single Instance mode, add a new User Tool...Everything is the same except the Argument: "$(CurSel).$(FileExt)" (WITH quotation marks, NOTICE we should append ".$(FileExt)" after the "current selection" here)
  2. Try it. When you want to open a file by text selection, use the tool that we created just now.
    1. First we open a file like "CMyClass.cpp",
    2. Select "CMyAnotherClass", If the "CMyAnotherClass.cpp" file is in the same folder as the active file, you can immediately swtich to it or open it. We only select "CMyAnotherClass" in this example, however, the corresponding CPP file is opened--it is the magic of "$(FileExt)", which makes EditPlus attempt to open a file with the same extension name as the active file.
    3. You can also quickly create a file in "$(CurSel).$(FileExt)" format by selecting something and lauching this tool.
  3. You can also explicitly set "$(FileExt)" as "cpp" or "cs" regardless the current active file extension

This trick is originally provided by W. Jordan