Remove blank line in Eclipse - eclipse

How can I remove lines that only contain spaces when using Eclipse Find/Replace prompt. I checked the "Regular Expression" check box, and tried the following, neither of which worked.
^[:space:]*$
and
^\s*$

Find: ^\s*\n
Replace with: (empty)

sry this might be an different answer but you can set the number of blank lines you wish to have after fields, methods and blocks in the formatting dialog of the eclipse preferences. then you can hit ctrl-shift-f to automatically format your code depending on your custom definitions.
have fun!

I was suprised that for XML files edited with Eclipse there is a good solution:
Select the checkbox value named 'Clear all blank lines' in Formatting panel
Window->Preferences->XML->XML Files-> Editor
Save and use the "Ctrl+Shift+F' shortcut
The blank lines will dissappear!

for the find/replace operation, "\n\r\s" regex will work on windows, for unix based system, "\n\s" can be used
as already suggested, you can format your code by Ctl+Shift+F
for manual work, locate a blank line and press Ctl+D (Cmd+D on Mac) <- gives u satisfaction of killing the line with your own bare hands :)
cheer!

This one worked for me for years:
Replace this: [\t ]+$
With nothing
Hope this helps!

Many thanks to lamamac.
In genereal, when you want to do search replace with regular expressions in eclipse the $ sign doesn't work as it should.
Use '\s*\n' instead of '$'

As already suggested, regular expression and replacement is the solution, but such response would have been saving some minutes to me:
click on ctrl+f
use this replacement:

Related

How to convert embedded CRLF codes to their REAL newlines in Vscode?

I searched everywhere for this, the problem is that the search criteria is very similar to other questions.
The issue I have is that file (script actually) is embedded in another file. So when I open the parent file I can see the script as massive string with several \n and \r\n codes. I need a way to convert these codes to what they should be so that it formats the code correctly then I can read said code and work on it.
Quick snippet:
\n\n\n\n\nlocal scriptingFunctions\n\n\n\n\nlocal measuringCircles = {}\r\nlocal isCurrentlyCheckingCoherency
Should covert to:
local scriptingFunctions
local measuringCircles = {}
local isCurrentlyCheckingCoherency
perform a Regex Find-Replace
Find: (\\r)?\\n
Replace: \n
If you don't need to reconvert from newlines to \n after you're done working on the code, you can accomplish the trick by simply pressing ctrl-f and substituting every occurrence of \n with a new line (you can type enter in the replace box by pressing ctrl-enter or shift-enter).
See an example ctrl-f to do this:
If after you're done working on the code you need to reconvert to \n, you can add an invisible char to the replace string (typing it like ctrl-enter invisibleChar), and after you're done you can re-replace it with \n.
There's plenty of invisible chars, but I'd personally suggest [U+200b] (you can copy it from here); another good one is [U+2800] (⠀), as it renders as a normal whitespace, and thus is noticeable.
A thing to notice is that recent versions of vscode will show a highlight around invisible chars, but you can easily disable it by clicking on Adjust settings and then selecting Exclude from being highlighted.
If you need to reenable highlighting in the future, you'll have to look for "editor.unicodeHighlight.allowedCharacters" in the settings.

Replacing a string in Rubymine with a string with newlines

I want to use the Search and Replace dialogue in Rubymine, or something similar to replace something like "Scenario:" with "#Desktop\nScenario"
I'm trying to replace every instance of Scenario: in a large Cucumber test suite with
#desktop
Scenario:
Any best ways to do this?
Update:
Thanks to #ryan2johnson9 comment, I realise there's now an easier option (tested on 2017.3).
By clicking on the "New Line" (or using the shortcut Ctrl+Shift+Enter / Alt+Enter), the input becomes multilines.
Original Answer
In the search and replace box, if you tick the "Regex" option you can do:
Search: "Scenario:"
Replace by: "#desktop\nScenario:"
The only trick is to tick the "Regex" option :)
Rubymine has macros (http://www.jetbrains.com/ruby/webhelp/binding-macros-with-keyboard-shortcuts.html) but I dont think they are powerful enough for this example.
It's possible that you could solve it with some elaborate feature hidden inside Rubymine, but I think it would be a lot easier to do this with a tool like perl/sed from the Terminal. If you are using Windows I assume you could search the net and find a text search/replace tool that fits your need.
In OSX I there are a bunch of Text Substitutions app too.
I would go that route since Rubymines macro tool isnt up to the task.
Here's a cheap and sleazy alternative:
Copy a newline character from between two empty lines in the file being edited. Temporarily add two empty lines if you don't have any.
Set up search/replace and enter the string you want to replace into the search text input box.
Paste the newline you just copied into the replacement text box plus whatever other text you want. You will be able to see the height of the replacement text input box grow vertically by one line due to the newline.
Perform the search/replace.
For this, the use of the Rubymine regex is optional.

Simple eclipse search problem

I use the eclipse File Search option very much to search all files in my workspace for a certain content. But how do I specify that it should only return hits from a fixed search criteria? As an example I would like to find all occurrences of the string:
com.mystuff.data
but I also get all the hits for:
com.mystuff.data.ui
How do I make a "this-string-only-search" when searching files in my workspace??
If I understand you correctly, Eclipse don't provide option to search exact word.
You can use regular expression for it.
You can use \bSearchKeyword\b to find exact word.
I suggest that you use regular expressions.
Here are the steps:
Select the checkbox "Regular expression" which is located beside the "Containing text" field.
In the "Containing text" field write: com.mystuff.data\D\W
Note that:
\D means "no digit"
\W means "no alphanumeric"
In case you would like to refine the regular expression, click Ctrl-SPACE, in order to get the regular expression assistance.
Hope this helps.
Best regards
Maybe slightly off-topic but this got me tripped and brought me here - maybe useful for somebody else:
In the Eclipse standard Find/Replace dialogue the section 'Options' (that includes the option 'Whole Word') may be hidden if the Find/Replace dialogue window was previously resized to a smaller size, without any clue to its presence. Resizing it larger brings back the options section. See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=355206
and attached shots.
Eclipse standard Find/Replace dialogue search for Whole Word regards several characters (including period) besides a space as a word delimiter, so you indeed cannot distinguish between "com.mystuff.data" and "com.mystuff.data.ui"
E.g. search 'Stack' with option 'Whole Word' checked:
will match:
Stack
Stack overflow
Stack.overflow
Stack,overflow
Stack[overflow]
Stack(overflow)
Stack-overflow
Stack/overflow
will not match:
Stackoverflow
Stack2overflow
Stack_overflow
Simplest way is to add space in the start and end of your search term.
Try SHFT+ CTRL+R, then on right upper angle select Working Set, then name and specify your resources.
Create Work Set as above, then CTRL+H check checkbox All occurency, then select your Work Set. Or maybe you can create work set in CTRL+H.

Hungry Backspace in Eclipse?

In some editors there exist plugins implementing a feature called "hungry backspace" or "hungry delete".
If this mode is active in a text editor then one hit to the backspace key will automatically delete all whitespace chars backwards from the current cursor position up to the first non-whitespace character.
For example, this feature exists for Emacs and IntelliJ IDEA.
Does anyone know if it is also available in Eclipse?
Alt-Del is probably as close as you're going to get without writing a plugin yourself. Others have asked for this feature (coming from intelliJ) but so far it doesn't exist, or it's not published.
-Adam
CTRL-backspace is pretty close too: delete previous word:
function(); (4 spaces)
+ CTRL-BACKSPACE gives:
function
Other than that, AnyEdit plugin can convert trailing spaces into tabs (but also into "", effectively removing them)
Ctrl+Shift+Left, Backspace always works for me. works in notepad, web browsers, everywhere.
Stick to the standards :)
In SciTE, and Eclipse (3.4), Ctrl+Shift+Del with the caret after the last visible character will delete these spaces. Ie. it deletes from caret to end of line.
Actually, in SciTE I don't need to do that, since I have set it up to automatically remove these trailing spaces when saving.
Note: In Preferences > General > Keys, there is a Remove Trailing Whitespace binding (without key assignment by default) which seems to apply to File.
From eclipse Windows menu/Preferences
Search for Keys and filter to "Delete Previous Word"and Bind it to the Ctrl+Backspace

In Eclipse, how do I replace a character by a new line?

In Eclipse 3.3.2, I would like to replace a character (say ',') by a new line in a file.
What should I write in the "Replace with" box in order to do so ?
EDIT : Many answers seems to be for Eclipse 3.4. Is there a solution for Eclipse 3.3.X ?
Check box 'Regular Expressions' and use '\R' in the 'Replace with' box
It's a new feature introduced with Eclipse 3.4, See What's New in 3.4
Check box 'Regular Expressions' and use '\n' in the 'Replace with' box
Like the others said, just use regular expression, but instead of just \r, put \r\n
if the file search is performed with Regular Expressions checkbox checked, then replace all / replace selected will also allow regular expression and will transform \n to a newline in the file(s)
I'm using Helios and it works, however I had some issues with replacement... I wanted to place a line break between any of these brackets "><" (to make each new XML tag go to a new line)... first I had to place a chacter between the 2 brackets, for instance /r, after this i checked the "regular expressions" box and replaced the /r with \R, which resulted in the correct linebreak. otherwise, the replace seemed to be greyed out.
I've just found an article about that problem. It seems to be a bug.
There's a workaround which is to copy a new line in clipboard and then paste it inside the "replace" box.