Is there a shortcut to copy the current path/file to the clipboard?
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.
Make your
Package Explorer
link with editor, you can active this by click the double-arrow icon at top-right corner.Set up a hot-key for
Show View (Package Explorer)
ex : Alt + 1Set 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
- 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/
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'.
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.
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.
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).
Alt+Enter - open properties
Alt+L - go to path location
Shift+End - select path
Ctrl+C - copy
- Go to Project Explorer View in Eclipse which is at the left panel.
- Click on link with editor.
- After linking, your opened file will get selected.
- Right-click on the selected file. You will get the option 'Copy Qualified Name' which is just below 'Copy' option.
- 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.
- In the folders address bar, the address will be like this:
D:\project
. - Paste in front of this address like:
D:\project/abc/source/com/connect.java
- Delete the java file name(connect.java) and press
enter
.
You will be in folder 'com'.
The video demonstrating the technique was prepared for Eclipse in Windows. In Linux you have to change:
- External Tools Configurations - Location: /home/username/path/to/script.sh
- External Tools Configurations - Arguments: ${selected_resource_loc}
- External Tools Configurations - Standard Input and Output - CHECK "Allocate console (necessary for input)"
- 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)
来源:https://stackoverflow.com/questions/8006250/copy-path-file-name-in-eclipse-to-clipboard