Eclipse - custom quick fix - Add some text before and after selection - eclipse

I could use a dummy guide or directions how to add a custom quick fix or if it is even possible.
Let's say I select a text inside code - "foo foo". Now I want to add something before that text and something after. The content before and after remains the same across many files and it has to be done manually.
Is there a way I could write my own quick fix in eclipse, which would add this text automatically.
Ctrl + 1 -> "Add ... before and ... after" -> And get the desired output?
This seems somewhat useful if not the correct thing, but I can't exactly read out how to accomplish this: FAQ How do I implement Quick Fixes for my own language?
Any easier explanations and guides are appreciated. Or what other ways would I have to accomplish this desired behavior without typing/copying repetitive things
Edit: Found this little macro thing which is one way to solve my problem. start with cut, write, paste and end macro. But I'm not sure if this is the best way. Practically Macro

I suggest this solution that allow you to get the result using Eclipse search.
CTRL+H to do a search and choose Files Search
Fill Containing text with "foo foo". Tweak other parameters to get the files you want
Check Regular expression
Click on Replace
Fill With: <prefix>$0<suffix>. For example if you want to substitute "foo foo" with "this is a foo foo example" write this is $0 example
Check Regular expression (if unchecked).
Done. I think that this solution is quite flexible (as long as you are familiar with regexp to get desidered strings) and easy to apply.

Related

How to auto-uppercase MySQL after typing keywords?

I type pretty fast so I want MySQL Workbench to auto-capitalize keywords after I type them. I've seen a solution to a similar question which is MySQLWorkbench-> Preferences-> Query Editor-> Change keywords to UPPER CASE. However this only provides uppercase for autofill. The problem is that the dropdown menu takes a second to load and hinders my work flow.
Is there any solution to this problem? Could I create a trigger for this or is that not helpful?
Not an automatic solution but something useful: look in the Edit -> Format menu. It has entries to upcase + downcase keywords, as well as other formatting commands.

Netbeans: Auto-replace emtpy with empty

I'm doing a lot of php-programming in Netbeans. It occurs like at least once a day that I write emtpy instead of empty (dunno why). Costs me each time at least 15s to test, see and find the mistake and correcting it (and I'm really annoyed each time).
Is there an option to automatically replace every emtpy with empty or at least highlighting it (like with big fat flashy arrows? :P)
Couldn't find anything of the sort with a quick search.
Thanks for any suggestion!
P.S.: I want it to be like in Word, when you type the first two characters in CApital it will auto replace it by only the first letter Capital. Please see comments as well, before replying.
No a real solution but maybe an improvement of your situation:
You could (mis)use a code template for that: Tools / Options / Editor / Code Templates. Select your language and create a new abbreviation (empyt) and as "expanded text" you use "empty". Make sure to set "Expand Template on" to "Space".
Drawback is, that it only works if you are pressing space after typing "empty" or "empyt".

Netbeans Find and replace all strings

Is there any way to find all Strings in my source code regardless of their content. In other words I want to find everything that starts and ends with " . What I want to do afterwards is replace all found strings with someMethod(string).
Edit:
I think I have not expressed myself clear. I want to find all strings no matter what the content between the " is and the "encapsulate" them. In your example syso("test") should become syso(somethod("test"))
You can use the Find In Project functionality using the Basic Wildcards options.
Then use the * wild card and search for syso(*) . This will return all occurrences of this method. Then manually you can replace the text you want.
CTRL+F - search for " and replace manually:
search for : the thing you want to replace(e.g. ")
replace with: the thing you want to past instead (e.g.someMethod())
-> But look out for errors! think about replacing bevor you try it- because if you replace all " with somemethod, you have a lot of errors! Look at this example:
syso("test");
//---replace actoin: someMethod() instead of "
syso(someMethod()testsomeMethod())
-> best way is to make this kind of manipulations (in my oppinion): manually!
Perhaps there are some Refactoring-Tools in Netbeans which could help you-but i donĀ“t think that there is a "simple and easy" solution.
If you are searching for a solution for the whole project you are working on, go into the Edit menu-y there ou should find a item for "Replace in Project";
I hope i understood you right & could help a little!

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.