Switching from Tabs to Spaces in our Java project, I am looking for the Eclipse shortcut so basic that I can't remember it which allows, on a given line, to move the caret to the next "group of spaces".
With tabs, it is pretty easy, because they count as a single character, so just using arrow keys is okay, but with spaces, if, let's say, the indentation level is based on 4 spaces, Left or Right arrows must be pushed down 4 times before accessing the next indentation level.
Thanks!
Default indentation: Ctrl+I
Right indentation: Tab
Left: Shift+Tab
Related
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.
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.
I have CheckStyle set to check for lines over 80 characters in Eclipse, and I have a margin line set up in my editor at 80 characters. If I put my cursor at the end of a line of code in my editor, the co-ordinates read (for example) 1433, 77, indicating the 77th character column from the left - yet when I run CheckStyle over the same line it says the line is 88 characters long! There are no extraneous tabs or other whitespace characters at the end of the line, it's definitely 77 long. Is CheckStyle broken?
From the Checkstyle documentation:
The calculation of the length of a line takes into account the number of expanded spaces for a tab character ('\t'). The default number of spaces is 8. To specify a different number of spaces, the user can set TreeWalker property tabWidth which applies to all Checks, including LineLength; or can set property tabWidth for LineLength alone.
http://checkstyle.sourceforge.net/config_sizes.html#LineLength
To do this in Eclipse:
Open Window->Preferences from the Menu.
Select Checkstyle.
Type TreeWalker into the search box under Known modules.
Select TreeWalker on the list on the right.
Click Open.
Change the tabWidth to 4.
Click OK, and OK again.
Is CheckStyle broken?
Probably not.
I expect you/Eclipse and CheckStyle have a different idea of the width of a TAB character. It sounds you think it means 4 spaces, whereas CheckStyle thinks it means 8 characters (its default).
One way around this is to configure Eclipse to not use TAB characters in your source file, then re-indent your source files.
Another way is to make use that CheckStyle and Eclipse agree on the TAB width; e.g. see #MartinEllis's answer.
(I prefer the first approach because it means that my source code will look correctly indented, irrespective of the platform's default TAB width; i.e. Windows versus Linux/Unix. Hard TAB characters in source code are a bad idea.)
By default, pressing the Comment out shortcut keys Ctrl + /, has behavior like this:
Notice that the // get added at the left-most position of the row.
Is there a way to set it so that the // appear at the same level of indention as the code that is being commented out?
e.g.
Perhaps a Python habit, but I find it much easier to parse when everything is at the same indention level.
Is there a way to change where the slashes show up?
Yes, it's possible.
go to this link for detailed info
First go to Preferences, then
On the left side of the box, expand the Java option, then expand Code
Style and finally click Formatter
You'll land on the Java-Profile page:
The other, temporary way is via CTRL+SHIFT+F shortcut ( Eclipse: Change the block comment style of ctrl+shift+/ ) . So you'd highlight those comments, and press the combo.
I would then also use a shortcut for CTRL+SHIFT+F , like ALT+F5 (press CTRL+3 , 'keys' to get the preferences page.
I've been using Eclipse to do my CS assignments, as recommended by my professor. However, I've noticed that if I open my source code in a different text editor, my beautiful, perfect formatting looks wrong. I believe the problem lies in tabs. A tab character seems to take up less space in eclipse than in other text editors.
A good chunk of our grade is determined by the neatness of our code. I'm not sure if our programs are graded in eclipse or not, so I'd like to figure out how to make source code have the same formatting regardless of text editor.
Is this a problem with Eclipse? Are there settings I can fiddle with?
This is probably due to your settings for the tab symbol. If you really want to indent using tab, make sure it is set to 8 spaces everywhere.
From the Java coding convention:
Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).
Personally I always use spaces to indent my code due to the fact that some people have their tab symbol set to show as 4 spaces.
To set Eclipse to always use spaces, go to
Window -> Preferences -> Java -> Code style -> Formatter -> Edit
and set Tab policy to Spaces Only.
The tab size is probably different in other editors. It still is in its raw form a \t. Depending on what the editor will display when it encounters one is probably found in the preference. Either way it should be consistent in size all the way across the file.
You could also convert tabs to spaces so it is always the same regardless of editor.
The tab character does not have a defined display width. In notepad, it is displayed as the same width as 8 spaces wide. All code editors should allow the viewer to change the displayed tab width. The convention for code is normally a width equivalent to 4 spaces.
If you're desperate, you could replace all tabs with 4 spaces. However, this is frowned upon by some, and may lose you marks. I'm pretty sure that the advised java coding style advocates the use of tabs, not spaces.
At the end of the day, the marker is a fool if he'll turn down syntax highlighting, and the code editor that comes with it.