IntelIJ copy line without selection - java

I was wondering if there is a way to just remove the selection when I copy a line by doing ctrl + c on a line
before: I just have my cursor in a line:
after: I just press ctrl + c
I dont like how I have to do an extra step to unselect, there must be a way to just remove the select without removing any functionality. Vscode has it working perfectly but I would love to have the same experience in IntelIJ

You can simply use Ctrl+D to copy a complete line without selecting it.
More info in JetBrains Help

To just copy and paste the line, you don't need to select it at all.
Just use action Duplicate line or selection Ctrl + D
and Move Statement Up/Down Alt+Shift+Up or Alt+Shift+Down to the desired position with .
See JetBrains blog :
Like cut, we can copy a whole line with ⌘C, or Ctrl+C, without having to highlight it first, and paste this too. Sometimes it might be more useful to duplicate the line instead with ⌘D, or Ctrl+D.
When duplicating a line, the line will be copied directly as new line below and cursor is placed where it has been before.
Watch the youtube demo IntelliJ IDEA Tricks - Lecture 7: Duplicate and Delete Lines (0:41)
See also:
How to select/copy current line without using mouse in IntelliJ IDEA
JetBrains IDEA help: Write and edit source code, section Lines of Code
Dev.to blog: IntelliJ style line duplication in Visual Studio Code

Related

Intellij: How can I wrap a piece of text in Javadoc?

So, for example, if I were to insert a Javadoc comment for a field from some external source on web, I would copy paste the relevant part from the website and then move on to my Class to incorporate the copied content as a Javadoc comment for the field.
But the problem is, I can't find any support from Intellij regarding this. Currently, I have to type, /** + Enter to generate a stub then paste the content there, which doesn't get properly pasted - I mean, a paragraph of 5 lines comes as a single long line and the Javadoc * on the side disappears.
I was looking for something like, paste the content copied raw in the place then select it and if Intellij provides some shortcut to wrap it as a Javadoc comment, do it except I couldn't find any support from Intellij for this approach.
So my question is, does anyone know of any such tool/plugin/built-in Intellij support or any other workaround for doing this as this is time consuming?
You will have to start with the /** and Return to get the basic javadoc comment. Then you can paste your text with ctrl+V (⌘+V on OSX) as the cursor is positioned at the right place.
All that is left then is use the keyboard shortcut that is defined for reformatting. In the menu you will find that under _Code/Reformat Code, on my Mac it is ⌘+⌥+L.

Eclipse editor code editing

First of all, I was unsure what the title of this question should be so I just gave it my best shot. I just started using Eclipse as my IDE, it's a great IDE and all but I get annoyed when I highlight a portion of code to be edited or replaced, any code after it gets deleted. So for example:
System.out.println(theScanner.nextLine());
I want to replace nextLine with nextDouble. I would highlight nextLine and type in nextDouble but then the ()()(); would be erased and I would have to type them in again. Is there a way to fix this?
Click Windows > Preferences. Type content assist in search box. Select Completion overwrites option as shown below
Keep cursor after character t then press Ctrl + Space.
Then type d then select nextDouble method press Enter

Eclipse IDE Scope Highlighting?

When I first learned Java, I was using an IDE called "BlueJ." It had this feature called "Scope Highlighting" which made it very easy to read blocks of code. Now I've moved on from BlueJ and began using Eclipse. I'm currently in the process of customizing Eclipse to my liking and would like this Scope Highlighting feature inside Eclipse.
I've searched everywhere for an answer on how to do it but I cannot find any information pointing to a solution for doing it in Eclipse.
Here's a picture to demonstrate what Scope Highlighting looks like:
I think the best option for you is EditBox, a scope highlighting plugin for Eclipse:
http://editbox.sourceforge.net/
I'm afriad that closest you can get is Shift + Alt + arrow_up
It is selecting wider block of code. pressing this few times will give you very similar result to what you are searching for. I use it often.. it is useful, also for refactoring.
EDIT: As #j2emanue said: you can just double click the delimiter (like a bracket) and it will highlight the entire scope.
you can use Shift + Alt + arrow_up but many people dont realize you can just double click the delimiter (like a bracket) and it will highlight the entire scope. Try double clicking your if statements bracket for example and watch eclipse highlight the entire scope. It works with any delimiter. so you can use parenthesis as well.
as a side note: if your using intelliji checkout this plugin works great: https://github.com/izhangzhihao/intellij-rainbow-brackets#screenshots
This isn't exactly what you're after but you can put your cursor in a method and then click the Show Source Of Selected Element only button on the toolbar. Your editor gets reduced to just that method. Click again and your back to your entire file.
I doubt eclipse does have the same function as blue j.The best advise I can give you, is to change your theme to your liking which would enable you to easily select and highlight the block of code...and to customise your theme , go to http://eclipsecolorthemes.org/. ....
If you still have a problem, go to http://codejava.co.uk/contact.html and send your email.you can create a dummy one if want, then I will send you XML files I use for my eclipse themes.
can Bracketeer do this ? its an eclipse plug in ..
http://marketplace.eclipse.org/content/bracketeer-java-jdt#.UK6sY4fAdLc
Maybe you will also like the VSCode extension "Blockman". It highlights nested code blocks based on curly/square/round brackets, html/xml tags and Python/Yaml indentation. (I am the author of Blockman).
.
https://i.ibb.co/31F0rm9/vscode-blockman-intro-leodevbro-extension3.png
.
.

Eclipse text cursor has changed and editor behaves differently

I pushed a magic button and now my cursor (the blinking thing that shows where you type) split itself and now Eclipse is acting like a plain text editor/like Microsoft Word. The cursor, which usually looks like "|", now looks like "¦" (what Wikipedia calls a 'broken bar' or a 'parted rule' rather than a normal 'vertical bar').
I just want to know how to get Eclipse to act normal again, and what I accidentally did so I don't do it again.
It sounds like you have accidentally switched from Smart Insert mode to Insert mode.
Press Ctrl + Shift + Insert or tick Smart Insert Mode on the Edit menu to switch back.
Smart Insert is the feature that automatically insert closing quotes and brackets when you type the opener and places semi-colons at the end of the line when you press semi-colon (if you have the preference for that enabled.)
Maybe you pressed the insert key, which will change the Eclipse editor to Overwrite rather than Smart Insert (see the info bar at the bottom of the editor), and will change the cursor to a block rather than a vertical line?
Update: Thanks for clarification - see mikej's answer which is correct. I'll leave this answer in case anyone has the similar, related problem that I describe.
Just double click on "Smart Insert" / "Overwrite" in eclipse status bar
For reference, I am adding image.
If nothing works, restart eclipse. That is what I did !
Just click
Toggle Vrapper Icon in Toolbar..
That may causes some issues like these. Because I'm also faced the same issue until today.
Please refer the below images to get clear idea about this.
Make sure that it is in disable mode in status bar
On my windows computer I press Shift + 0 but the zero has to be on the numeric keypad not the top row numbers.
Shift + 0 toggle my cursor.
#Jeremy by saying " I have a vertical line with a gap in the middle of it, like the character above the forward slash " i guess you are referring to the ' Pipeline 'symbol, the one you use to denote' OR ' in programming languages. As people already answered, you are in Raw Insert Mode (as opposed to Smart Mode) so try Edit->Smart Insert Mode (Ctrl+Shift+Insert by default).
For more info you can visit this thread http://www.eclipse.org/forums/index.php/t/53833/
And remember, the symbol is called 'Pipe' symbol or 'Pipeline' symbol.
I also had same problem, you can fix this by pressing just INSERT button on keyboard (on windows platform) also.
It worked for me.
or you can restart your eclipse.
I've encountered this symptom in Eclipse 3.7 before. And after I restarted machine, it disappeared.
If your cursor symbol is " + " then press Alt+Shift+A.
or else we can use Edit menu options ==> Toggle Block Selections
If you are using spring tool suite then you can double click on highlighted Smart Insert . Some keyboards do not have insert button.
enter image description here

Eclipse copy/paste entire line keyboard shortcut

Anyone know the keyboard shortcut to copy/paste a line into a new line in Eclipse, without having to highlight the entire line?
ctrl-alt-down turns my whole screen upside down (I'm on windows). Interestingly, that's what's specified in the windows->preferences.
Ctrl-Alt-Down: copies current line or selected lines to below
Ctrl-Alt-Up:: copies current line or selected lines to above
Ctrl-Shift-L: brings up a List of shortcut keys
See Windows/Preference->General->Keys.
(Tested on Windows) [Per below comments, works as well in Ubuntu, IBM RTC 4 / RSA 9]
In Eclipse, press Ctrl+Shift+L two
times in succession (or Ctrl + 3 > type: Keys > Enter).
In 'type filter text' (search) text box, type Copy Lines
Select the filtered row, right click the 'Binding' field, and do Select All
Press Ctrl+Shift+V
Give OK
From now on, for any line you want to duplicate, just press Ctrl+Shift+V.
You have to turn off the graphics hot keys that flip the screen. If you're on Windows, you need to right click on the Windows desktop and select "Graphics Properties..." (or something similar depending on your version of Windows). This will bring up a screen where you can manage graphics and display options, look for a place where you can disable hot keys, sometimes it's hidden under something like "Options and Support". Turn off the CTRL + ALT + ↑ and CTRL + ALT + ↓ hotkeys (alternatively you can just disable all graphics hot keys if you're not using them).
If you want to copy a line to the clipboard you can also use the trick:
Ctrl-Alt-Down
followed by
Ctrl-X
The drawback is that the file where you copy the line from becomes dirty.
Ctrl-D would delete a line
Ctrl-Z would undo deletion, with highlithing entire line
Ctrl-X/C cut or copy entire line
The advantage over Ctrl-Alt-Down followed by Ctrl-X suggested by other users is that it doesn't make eclipse think that the file was changed in any way. It's also faster and causes no problems even if the user has rotating screen issue with Ctrl-Alt-Down/Up keyboard shorcut. So there's no need to remap shorcuts for this.
Another way to go would be hitting Alt-Shift-Up until the entire line gets selected. If you've gone too far, of course you can select less with Alt-Shift-Down.
If Your Window pc, you may try this, it's also for STS:
Ctrl + win + Alt + Down :: Copy current line or selected line to below
Ctrl + win + Alt + Up :: Copy current line or selected line to above
I've written the linecopypaste plugin for Eclipse that mimics Visual Studio's copy/cut/paste behaviour. I've also found copycutcurrentline which appears to do the same.
On my Mac the default setting is is ALT+CMD+Down
You can change/view all key bindings by going Eclipse -> Preferences (shortcut CMD+,) and then General -> Keys
Ctrl+Alt+Down Copies current line to below like notepad++ (Ctrl+D)
If your whole screen is 180° rotted then you should disable your hotkey settings.
Right Click -> Graphics Options -> Hot Keys -> Disable
That it now you done try shortcut Ctrl+Alt+Down
Try this in MAC.
ALT + COMMAND + DOWN
it works.
If anyone using Mac computer the CTRL + ALT + DOWN keys doesn't work.
Try it with,
ALT + COMMAND + DOWN
It works.
We can assign any command to any action(given) in Eclipse
From Menu Bar go to
Window > Preferences
then search for the keys
then search copy line
then click on copy line and then click on command in Binding
and peform a command which you wish to use for duplicating line i use ctrl+shift+d
you can choose whatever you want
On Mac, I've tried the linecopypaste and it works great
cmd+c -> Copy current (unselected) line, just like "yy" command in Vi/Vim
cmd+v -> Paste it, like "p" command in Vi/Vim
Thank's Larsch for your work!
PD: Using Eclipse Luna 4.4.2 in Yosemite
I have to change the assigned key,
e.g.
Windows/Preference --> General --> Keys
Select "Duplicate Lines" under command
Click on "Binding"
Ctrl + Shift + D
Just another approach:
1) Alt+Up and Alt+Down (or Alt+Down and Alt+Up, order does not matter)
2) Ctrl+C
But of course vim's "yy" is the fastest :)
Disabling the hot keys for the Intel Driver worked for me for Windows 7. However, for Windows 8, when I tried that, it prevented eclipse from getting the Ctrl-Alt-Down keystoke. I had to change the Intel driver key binding to Ctrl-Alt-F10 (or something else it will accept). Eclipse then gets the Ctrl-Alt-Down and copies the line.
For mac, shift+alt+down_arrow works in netbeans' editor.
It's working with me on ,
Eclipse + Spring tool suite .
ALT + COMMAND + DOWN
I am using Windows 7. To disable that all I did is to Right click on the Windows desktop and select "Graphics Properties" ->Options. Then selected "Off" at the left side on the resulting screen. This disabled all hotkey combination. I think there is no way to disable only some them, its all or none. Anyway I didn't need them. So now crtl+Alt+Up and Crtl+Alt+down works for me in Eclipse and my screen stays same :)
I think similar option also exist in other versions of Windows. Have fun :)
For personal usage, I add a vim plugin like Vrapper to Eclipse and just use yy to copy entire line.
The Ctrl+Alt+Down / Ctrl+Alt+Up flips my screen so I overrode that in the Eclipse shortcuts via
Window => Preferences => General => Keys.
Search for "dupl" to find the Duplicate Lines command. I overrode the default and chose Ctrl+Shift+D. For me, that's easy to remember just like Ctrl+D to delete lines
ctrl+alt+down/up/left/right takes precedence over eclipse settings as hot keys. As an alternative, I try different approach.
Step 1: Triple click the line you want to copy & press `Ctrl`-`C`(This will
select & copy that entire line along with the `new line`).
Step 2: Put your cursor at the starting of the line where you want to to paste
your copied line & press `Ctrl`-`V`.(This will paste that entire line & will
push previous existing line to the new line, which we wanted in the first place).
The combination of Ctrl + Shift + Alt + Down worked for me on Linux.
To copy text from the begining of line to the cursor position: ctrl + insert
It does the job and save a lot of time for me.
Another shortcut way to do this is press Ctrl+Shift+L and select which command you want to perform and hit enter
its best practice for beginner.
See how to make the eclipse default shortcut work ctrl alt↓
Select line: Put cursor on the line to copy, select line with ShiftHome if cursor in the end of line or ShiftEnd if cursor is in starting of line
Duplicate line below (default expected behavior) or above ctrl alt↓ or ctrl alt ↑ but the key here is you need to select the line/block
Some answers focus on disabling the screen Rotation in Windows or any other OS, that applies to prevent accidental keypress.

Categories