Can you batch select text between quotes in IntelliJ IDEA? - java

Given the following Java code
On the MacBook in IntelliJ IDEA, I can hold the option key and mouse click 'n drag to select a block of text.
Is it possible to batch select just the text between the quotes all at once within a specific block of code, similar to Option+MouseClickAndDrag feature above, like this?
Notes added based on comments below
Cmd+W doesn't work since it expands the selection to highlight the full line, and eventually the entire code block. It does not select just the strings.
Shift+Alt+double-click is a closer solution, but requires you to manually double-click each string. I'd like a solution that selects them all at once.

If you use CMD/CTRL + W multiple times, you can expand your selection from the current cursor word to the enclosed string, to current line, depending on how many times your press it. This is depending on where your cursor is, at the time, unfortunately.
This tripped me up when I first started, because I always thought I was closing a tab

You can use a regex search to achieve this fairly easily.
If you are looking to find and replace you can go select regex searching and search for this Regular Expression:
(?<=").*(?=")
This will select all text between double quotes.

Use column select
You can cleverly get three cursors on the variable names, CTRL arrow over to start of strings, hold SHIFT + END, and then move the cursor back using the arrow keys.
For getting the column:
Windows: CTRL + CTRL(Hold) + ↑ / ↓
Mac: ⌘ + ⌘(Hold) + ↑ / ↓.
To place caret at the end of rows: move caret to top row, clone down to bottom, and click END.
Change Multi-caret Hotkey
To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.
I mapped mine to ALT+SHIFT+↑ / ↓ on Windows and ⌘+↑ / ↓ on Mac.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.

As of now, ⌥ + ↑ expands the current selection on my mac.
What you're looking for is extend selection and shrink selection in the keymap.

This is the best result I have reached by now.
You can divide in two steps:
Select opening or closing quote:
If line structure is identical before or after your strings you can place multiple cursors before or after your string, very fast with MIDDLE MOUSE CLICK + DRAG or MIDDLE MOUSE CLICK + DRAG. Then CTRL + LEFT/RIGHT ARROW to reach the double quote: After Example
Then you select the quotes with SHIFT + LEFT/RIGHT ARROW. Important you have to end with cursor inside quotes, otherwise future shrink selection will fail.
CTRL + W to extend selection to quotes and inner text.
CMD/CTRL + SHIFT + W to shrink selection to only the string contained.
Note. Unfortunately by now in Intellij IDEA you can't find into selection, otherwise there would be many tricks to achieve the same result.

Related

How can I change the post fix template in Eclipse? [duplicate]

I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println(); when tab-completed.
This is very useful but sometimes, I need to wrap some existing code in a System.out.println();
In Eclipse internals, the template is defined as being able to wrap a "selected word". But how can I use the snippet with selected text since typing "sysout" obviously removes the selected text.
Any idea?
The sysout template acts upon entire Java statements.
Highlight a statement in the editor.
Hit CTRL-SPACE (or whatever you have set up for content assist.)
Type sysout then hit enter. Note that when you're typing sysout it will temporarily overwrite your statement (but it will come back wrapped by System.out.println when you hit enter.)
Eclipse has "Surround Width" Option which can do this for you.
SHIFT + ALT + Z should get you that to see how that templates meta-data layout.
I don't think you can do it in one go, but what about cutting the selected text and then: tab+space, ctrl+v
it's just one key combination more.
if you use content assist (ctrl-space on Windows), at the end of the list will be the sysout option. you might want to augment the template with quotes around the word selection so you dont need to type them in.
Preference>General>Keys.
then search "content assist" or "content" in "type filter text".
don't press Enter.
choice "content assist".
type Binding and set your own shortcuts.
such as "control+space".
The main part is into:
Java->Editor->Templates
This can accessed by:
Preferences window: into Java->Editor->Templates.
Surrounding a text and press:
Windows: SHIFT + ALT + Z (as sadhasivam said)
Mac: CMD + OPT + Z
to display the Preferences Window

Hitting the tab key in the middle of the line inserts a tab instead of indenting

In Eclipse for Java, when I hit the tab key in the middle or at the end of a line, it inserts a tab instead of indenting. I can't find the setting to fix this, and an hour of googling has gotten me infinite pages about tabs vs. spaces and no answers. Please, help!
There is a setting I found under Java -> Editor -> Typing called "Tab key adjusts the indentation of the current line." It is definitely checked, but the indentation is only adjusted if the cursor is at the beginning of the line.
Several things you can do:
To indent several lines at once, you can select a portion of the text and press tab. This of course works for a single line too.
Press command-I to auto-indent, pretty handy trick.
Neither of these options do exactly what you asked for (quickly indent this line one tab to the right), but that's all I can think of in Eclipse.

Typing comment block in eclipse

I have just started to learn Java and I am a beginner to Eclipse.
When I start writing a source file, I start with a comment, for example:
/*
* This is the format of the comment I intend to get.
*/
To do so, I type /**/ and the take in cursor to the middle of it and press Enter.
To Eclipse's credit, it automatically starts the next comment lines with *, which is what I also want, however, here is something annoying happening which I haven't been able to figure out how to get rid of:
When I go to the middle of /**/ and press Enter, it gives me
/*
* */
*/
instead of intended
/*
*/
Which means that every time I have to go to the end and delete the extra /*. How can I avoid getting that extra */?
Just type:
/*
and then 'enter'.
It will start a comment block for you with just the single ending
*/
and your cursor in the middle. At least, that's what I think you are asking?
All you need to do is typ /* and then enter and it will create what you want. You can also change the template for the way eclipse does comments (or the way elcipse does anything automatically). Follow the link if you want to learn more about how to customize the settings in eclipse.
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcodestyle%2Fref-preferences-code-templates.htm
Hope this helps. Cheers.
You can also comment out a line of code by placing the cursor anywhere on that line and pressing CNTL + /.
You can also highlight several consecutive lines and comment them all out by pressing CNTL + / (multiple single-line) or CNTL + SHIFT + / (Block commented out)
Try using shortcuts, makes your life a lot easier.
On Windows,
Ctrl + / for single line comment
Ctrl + Shift + / for multiple line comment
On Mac/OS X replace Ctrl with ⌘
More shorcuts
http://www.shortcutworld.com/en/win/Eclipse.html#link_7

How can I stop the cursor in Eclipse from jumping around automatically?

Let's say I have a String and I want to remove every comma in the string. I want to use theString.replace(",", "") I start to type and the autocomplete comes up:
I hit enter and it completes the method name:
I type the first quote. All is well:
Then I type the comma. However, Eclipse thinks that the comma I typed is to separate the parameters, and my cursor jumps to the second parameter:
This interrupts my typing and I'm tired of it. Eclipse preferences are a maze, so how do I turn this off?
Unfortunately, Eclipse doesn't understand when you're typing in a string that the , you hit doesn't mean go to the next parameter. This is something hard-coded into their parser.
Take a look after the r in newChar; that's the border you're looking for.
You'll want to hit Esc when you auto-complete since you are in refactoring mode (notice the border around the parameters).
This is similar to when renaming a method or field using Alt+Shift+R - the border appears, indicating what you're doing is supposed to be "smart".

How to use the "sysout" snippet in Eclipse with selected text?

I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println(); when tab-completed.
This is very useful but sometimes, I need to wrap some existing code in a System.out.println();
In Eclipse internals, the template is defined as being able to wrap a "selected word". But how can I use the snippet with selected text since typing "sysout" obviously removes the selected text.
Any idea?
The sysout template acts upon entire Java statements.
Highlight a statement in the editor.
Hit CTRL-SPACE (or whatever you have set up for content assist.)
Type sysout then hit enter. Note that when you're typing sysout it will temporarily overwrite your statement (but it will come back wrapped by System.out.println when you hit enter.)
Eclipse has "Surround Width" Option which can do this for you.
SHIFT + ALT + Z should get you that to see how that templates meta-data layout.
I don't think you can do it in one go, but what about cutting the selected text and then: tab+space, ctrl+v
it's just one key combination more.
if you use content assist (ctrl-space on Windows), at the end of the list will be the sysout option. you might want to augment the template with quotes around the word selection so you dont need to type them in.
Preference>General>Keys.
then search "content assist" or "content" in "type filter text".
don't press Enter.
choice "content assist".
type Binding and set your own shortcuts.
such as "control+space".
The main part is into:
Java->Editor->Templates
This can accessed by:
Preferences window: into Java->Editor->Templates.
Surrounding a text and press:
Windows: SHIFT + ALT + Z (as sadhasivam said)
Mac: CMD + OPT + Z
to display the Preferences Window

Categories

Resources