Intellij: How to copy/paste a file in order to duplicate it? - intellij-idea

I can not seem to find a way to do this? I have a file named X in some folder, I want to create Y with the same contents in the same directory. The way I do in eclipse is to select the file and ^C, ^P, eclipse prompts for the new name.
UPDATE
Apparently this problem only occurs if compilation unit contains more than one type.

F5 will duplicate selected file prompting you to enter a name for the new file.

⌥ + drag
MacPress Option key and drag the original file.
PCPress Alt key and drag the original file.
You will be prompted for a new name.
Works for classes too:

As for a keyboard only solution to duplicate a file in IntelliJ:
On Linux:
Press Alt+Home to activate the navigation bar, then either press F5, or press Ctrl+C to copy the file and then press Ctrl+V to paste it, a dialog will appear to name your new file.
On Mac:
Press Cmd+Up to activate the navigation bar, then either press F5, or press Cmd+C to copy the file and then press Cmd+V to paste it, a dialog will appear to name your new file.

I found that ctrl+c/ctrl+v will not copy files on IDEA in Linux (using x2go to connect on a Windows box). I was able to get it working if I close xclipboard but then copying between Windows and Linux dialogs stops working.

Ctrl + C on target file/folder
Ctrl + V on destination folder
Enter new name and press Enter...

Related

Can I open a file in a new split screen tab with a keyboard shortcut in IntelliJ?

In VS Code I can press command + P to search for files and then when I find the one I'm looking for I can press Command + Shift + Enter to open the file in a new tab that adds a split pane to the window.
I can browse in a similar way in IntelliJ pressing Shift twice, but I can't figure out how to open the file in a tab in a split pane, just in a new tab in the same pane on pressing Enter. Is there a way to do it?
On the tab line, where all of your files are tabbed and opened, you can right click and see the option Split Vertically and Split Horizontally. They will split your window as needed. You can bind these options to a macro and automatically have anything split in a second.
Then you can just open any file with your explorer, and then run your key combination to split it!
Edit: you can create key mapping from the Settings -> Keymap menu.
Mr. Robot
I think, it's too late to answer this question.
But anyways, there is already a predefined keymap binding as per your requirement to open a new file in a split window.
keymap is Shift + Enter
After searching any file, you just have to press this combination and it will open that new file in a split window.
*This keymap is for Mac, it may be different for other OS.

How do you configure IntelliJ IDEA to place the cursor in the editor window after hitting enter on a file in the project window?

I'm big on not using the mouse, especially while writing code. I've noticed in IntelliJ IDEA 2016.1 that when I'm navigating in the project window, hitting Enter while a particular file is selected opens the file in an editor, but it doesn't place the cursor in the editor. Interestingly, if I double-click on the file in the project window, the cursor is placed in the editor.
How do I configure IntelliJ to place the cursor in the editor after opening the file via Enter from the project window?
To the best of my knowledge, I do not believe there is a way to configure what you are looking for. A search for focus in the settings didn't turn up anything.
That said, hitting Esc when in the project view will return you to the editor. So you would need to do Enter, Esc. If having to type two keys in a row bothers you, you could always record a macro (Edit > Macros) to do that key sequence and map it to a shortcut.

Shortcut for locate current file in Project Explorer in IntelliJ?

I read this post:
Locate current file in IntelliJ
Still the problem is that I do not want to have Autosccroll from Source enabled because my Project Explorer will be jumping up and down. Rather I need a shortcut to locate the current file in the Project explorer when I need to. ALT + F1 does work but you need to select from a context menu where you would like the file to be shown. In Resharper for example the shortcut is ALT+SHIFT+L but I am not able to find such a shorcut in IntelliJ?
There is no shortcut for this action in IntelliJ IDEA other than Alt-F1.
There is no default way of doing this.
I can think of 4 options:
You can install the plugin 'Scroll From Source' which will allow you set such a shortcut in the keymap settings (Default: Meta + Ctrl + S)
Use the target symbol in the project explorer, no shortcut but is default option.
Get used to having to press Alt + F1 and then Enter
Record a macro for the above key presses but this may be unreliable. You could then assign a shortcut key to play this marco.

Appcode shortcut key for "Scroll from source" ?

if you open a file in Appcode via a find or Shift + Cmd + O you don't see which folder that file is in in the project. in the project explorer there is a button on the top bar on the left that shows where the file is ( the icon looks like a cross - x ) called "scroll from source" if you hover over it.
Anyone know what the shortcut key for it is? it is not in the listed Appcode shortcuts
Thanks
Unfortunately there isn't a single shortcut, but it can be done in two: Alt+F1, then Enter
Don't know the shortcut, but in project explorer, next to the icon you've mentioned, there is a settings ('gear') icon, where you have an option to 'Autoscroll from source'. Every time you open file using Shift+Cmd+O it will show in project explorer automatically. Handy.
Basically it's Alt+F1( + fn if needed) then Enter, which you can find in the AppCode settings keyboard mapping as "Select in..." and can rebind as in Xcode with Cmd + Shift + J

How do I create a new class in IntelliJ without using the mouse?

Is there a way to create a new class in a desired location without using the mouse in IntelliJ?
I understand there is no keyboard binding in the default keymap.
If you are already in the Project View, press Alt+Insert (New) | Class. Project View can be activated via Alt+1.
To create a new class in the same directory as the current one use Ctrl+Alt+Insert (New...).
You can also do it from the Navigation Bar, press Alt+Home, then choose package with arrow keys, then press Alt+Insert.
Another useful shortcut is View | Select In (Alt+F1), Project (1), then Alt+Insert to create a class near the existing one or use arrow keys to navigate through the packages.
And yet another way is to just type the class name in the existing code where you want to use it, IDEA will highlight it in red as it doesn't exist yet, then press Alt+Enter for the Intention Actions pop-up, choose Create Class.
You can also use: ctrl+alt+insert
With Esc and Command + 1 you can navigate between project view and editor area - back and forward, in this way you can select the folder/location you need
With Control +Option + N you can trigger New file menu and select whatever you need, class, interface, file, etc. This works in editor as well in project view and it relates to the current selected location
// please consider that this is working with standard key mapping
For Mac Os, command + 1 , then press control + return
On Mac OS 10.14.5, Idea Intellij 2019.1.3 - Press command + 1 to navigate to project files then press control + n
On Mac you can navigate to the location in Project view where you want to create your class and then use ⌘N followed by Enter.
I do this a lot, and I don't have an insert key on my laptop, so I made my own keybinding for it. You can do this by opening Settings > IDE Settings > Keymap and navigating to Main menu > File > New... (I would recommend typing "new" into the search box - that will narrow it down considerably).
Then you can add a new keyboard shortcut for it by double clicking on that item and selecting Add Keyboard Shortcut.
Alt-Home until you're in Packages view
Down-arrow until package is highlighted
Alt-insert
Enter X 2
Type name
$PROFIT$
If you use Mac, you are in luck. One can change the keymap for Intellij as Mac OS X, then you can use option+C.
In my (linux mint) system I can not get working combination alt+insert so I do the next steps:
alt+1 (navigate to "tree") --> "context button - analog right mouse click" (between right alt and ctrl) -- then with arrows (up or down) desired choice (create new class or package or ...)
Hope it helps some "mint" owners )).
I also searched this answer. Equivalent of command+N on Mac OS for Windows is ctr + alt + insert which #manyways already answered. If you searching this in settings it is in Settings > IDE Settings > Keymap, Other > New ...
If the difficulty is in finding the option that makes .java or .class files (Like me), then simply,
click on the folder you want to create file on. select new, and type file's name along with extension.
For example, instead of, helloWorld type helloworld.java or any file extension you desire.