38

Is there a shortcut to copy the current path/file to the clipboard?

uvsmtid
  • 4,187
  • 4
  • 38
  • 64
user710818
  • 23,228
  • 58
  • 149
  • 207

10 Answers10

25
  • Just select the file tab and hit Ctrl+C to copy file basename into clipboard.
  • Hit Alt+Enter to bring up the file properties with absolute path and copy it manually.
  • Additionally you can use an Eclipse macro plugin that can do the steps in one go: http://sourceforge.net/projects/practicalmacro/files/
uvsmtid
  • 4,187
  • 4
  • 38
  • 64
Peter Szanto
  • 7,568
  • 2
  • 51
  • 53
  • "bring up the file properties with absolute path and copy it manually." --> doesn't work in the remote system explorer perspective: amazingly the path text cannot be selected in the window (Eclipse 4.5). – Franck Dernoncourt Jan 23 '17 at 22:15
  • Alt+Enter prevents it from pasting into Office as an embedded copy of the class. Thanks. – Noumenon Mar 07 '17 at 21:51
  • 1
    Alt+Enter doens't work everytime. In several cases you'll get "No property pages for ..." – phuclv Apr 06 '18 at 06:22
23

There is Copy Qualified Name function in Eclipse, it will copy the full name of the element you select (or element on cursor).

For example :

/MyProject/src/app/Application.java : when you select Application.java in Package Explorer

java.util.HashSet<String> : when you copy while cursor at HashSet<String>

However, it required you to select the element you want.

So, here is what I do.

  1. Make your Package Explorer link with editor, you can active this by click the double-arrow icon at top-right corner.

  2. Set up a hot-key for Show View (Package Explorer) ex : Alt + 1

  3. Set up a hot-key for Copy Qualified Name ex : Alt + Ctrl + Shift + c

Whenever I need these information in current file, I just press the hot-key to call my Package Explorer Since it links with editor and will always select the file in current editor, you can just copy with the hot-key. Then you can use F12 back to your editor, or simply ESC if you use fast view.

Not perfect, but it works :D

Rangi Lin
  • 9,303
  • 6
  • 45
  • 71
  • I do this complex sequence to open the current file in the system text editor: Shift+Ctrl+W, P, Left, Shift+F10, H, Enter, S. – mikeslattery Nov 21 '12 at 22:51
12

There is yet another plugin that supports copying the path along with a number of other related functions:

http://code.google.com/p/pathtools/

Just search Eclipse Marketplace within Eclipse for 'pathtools'.

enter image description here

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
ThomasW
  • 16,981
  • 4
  • 79
  • 106
  • This is what I use and it works well except that sometime it gets confused about the selected element. – Ashutosh Jindal Aug 07 '12 at 19:42
  • The [version on Eclipse marketplace](https://marketplace.eclipse.org/content/path-tools) is newer and works on my machine™. But I can't copy the path of an editor tab (Edit: must right click the editing area, not the tab!) – Qwertie Nov 07 '18 at 01:33
  • 1
    Crap. This tool will not allow copying the path of a file that is not part of the workspace (the Path Tools menu won't appear.) – Qwertie Nov 09 '18 at 02:19
5

You can do it with a single keystroke by configuring an Eclipse external tool (a much underused tool in my opinion). Takes about a minute to configure the first time you use it but then it's always available. Here's a YouTube video demonstrating the technique.

Tod
  • 8,192
  • 5
  • 52
  • 93
  • Unfortunately External Tools prompt you to save all files first, even if you disable the "Build before launch" option in the "Build" tab. Worse, it doesn't work (as of Eclipse 4.9) if the open file is not part of the workspace. It gives the following error message: `Unable to resource a selected resource: ${selected_resource_loc}`. – Qwertie Nov 09 '18 at 03:00
4

An alternative to the answer of Rangi Lin, which provides some additional functionality: The StartExplorer plugin for Eclipse. The solution mentioned by Rangi Lin doesn't work in all cases. It doesn't work in my case e.g. in the Team Synchronizing perspective in the Synchronize view. However, the StartExplorer's context menu command "Copy Resource Path To Clipboard", as well as the default keyboard shortcut for it (Ctrl+Alt+C) works also there. The advantage of this plugin is that it additionally allows you to open the file manager at the location of the selected file etc.

krm
  • 2,074
  • 2
  • 18
  • 21
3

Another option is EasyShell. It has a single entry in the context menu, under which you'll find copying of the path, opening explorer, a dos box and others (configurable).

Legolas
  • 894
  • 1
  • 11
  • 25
  • 1
    Excellent! This is the only answer that does not require the file to already be in the workspace! Plus, the context menu is easier to spot and easier to reach than the one in Path Tools. It doesn't offer some options like "Open Command Prompt here" on my Linux box, but it appears this can be customized in Preferences. – Qwertie Nov 09 '18 at 03:15
3

Alt+Enter - open properties

Alt+L - go to path location

Shift+End - select path

Ctrl+C - copy

Mark
  • 17,887
  • 13
  • 66
  • 93
1
  1. Go to Project Explorer View in Eclipse which is at the left panel.
  2. Click on link with editor.
  3. After linking, your opened file will get selected.
  4. Right-click on the selected file. You will get the option 'Copy Qualified Name' which is just below 'Copy' option.
  5. Open the directory where your project resides. e.g. if your project is 'abc' and it's in the directory 'project', go to the 'project' directory.
  6. In the folders address bar, the address will be like this: D:\project.
  7. Paste in front of this address like: D:\project/abc/source/com/connect.java
  8. Delete the java file name(connect.java) and press enter.

You will be in folder 'com'.

Nander Speerstra
  • 1,496
  • 6
  • 24
  • 29
Irshad N
  • 21
  • 3
0

The video demonstrating the technique was prepared for Eclipse in Windows. In Linux you have to change:

  1. External Tools Configurations - Location: /home/username/path/to/script.sh
  2. External Tools Configurations - Arguments: ${selected_resource_loc}
  3. External Tools Configurations - Standard Input and Output - CHECK "Allocate console (necessary for input)"
  4. Create a script /home/username/path/to/script.sh as follows

echo $1 echo $1 > /home/username/clipboard_tmp.txt xclip -in -selection clipboard /home/username/clipboard_tmp.txt xclip -selection clipboard -o

I don't know why, but following command echo $1 | xsel --clipboard doesn't work in the script. It was checked in Ubuntu 12.04 LTS and Eclipse IDE for C/C++ Developers (Version: Kepler Service Release 2, Build id: 20140224-0627)

Andrzej
  • 1
  • 2
  • This unfortunately prompts you to save all files first, even if you disable the "Build before launch" option in the "Build" tab. Worse, it doesn't work (as of Eclipse 4.9) if the open file is not part of the workspace. It gives the following error message: `Unable to resource a selected resource: ${selected_resource_loc}` – Qwertie Nov 09 '18 at 02:59
  • Having said that, there's no need to create a script file on Linux. I suggest the following easier steps: 1. Open "External Tools Configurations" and create an entry called "Copy File Path to Clipboard" under "Program". 2. Set location to `/bin/sh` 3. Set arguments to `-c 'echo "${selected_resource_loc}" | xclip -in -selection clipboard'` 4. In the Build tab, uncheck Build Before Launch 5. In the "Common" tab, under "Display in Favorites Menu", check "External Tools" 6. Apply and Close 7. Make sure xclip is installed (on some distros, `sudo yum install xclip`) – Qwertie Nov 09 '18 at 03:06
0

In Eclipse Version: 2020-03 (4.15.0)

In Project Explorer

Select your file> right Click> Copy Qualified Name Explanation

Aman
  • 586
  • 8
  • 20