RubyMine inserting un-editable text - rubymine

RubyMine has started inserting un-editable text into my Ruby code, and I find it rather annoying. For example, this simple rspec expression:
expect(user.name).to be_truthy
... becomes this:
expect(user.name).to matcher be_truthy
Another example, this:
Part.first.try(:root_id).nil?
... becomes this:
Part.first.try( *a :root_id).nil?
How can I turn this off?

It's called Parameter Names Hinting. You can disable it in preferences.
You can read more about it here: https://www.jetbrains.com/help/ruby/2017.1/parameter-names-hinting.html

Related

Multiline regular expression search in Visual Studio Code

Multiline regular expression search doesn't work in VS Code version 1.27.2 .
Theoretically aaa(\n|.)*bbb should find string starting from aaa and ending bbb but it doesn't work.
The solution mentioned here Multi-line regular expressions in Visual Studio Code doesn't work as well.
Multiline search is added in v1.29 released in November 2018. See multi-line search.
VS Code now supports multiline search! Same as in the editor, a regex
search executes in multiline mode only if it contains a \n literal.
The Search view shows a hint next to each multiline match, with the
number of additional match lines.
This feature is possible thanks to the work done in the ripgrep tool
to implement multiline search.
Multiline search is coming to the Find Widget with v1.38. See multiline find "pre-release" notes.
Multi Line search in Find Widget
The Find Widget now supports multiple line text search and replace. By
pressing Ctrl+Enter, you can insert new lines into the input box.
.
Odd that it is Ctrl+Enter in the Find Widget but Shift+Enter in the Search Panel (see Deepu's answer below). Shift+Enter has other functionality when the Find Widget is focused.
yes, you could use regex for mutliple line search in VScode.
To find a multi-line text block starting from aaa and ending with the first bbb (lazy qualifier)
aaa(.|\n)+?bbb
To find a multi-line text block starting from aaa and ending with the last bbb. (greedy qualifier)
aaa(.|\n)+bbb
I have been looking for a quick way to do this, and I have come to the following:
start_text.*?(.|[\n])*?end_text
with start_text and end_text being the bounds of your multiline search.
breaking down the regex ".?(.|[\n])?":
".?" will match any characters from your start text to the end of the line. The "?" is there to ensure that if your end_text is on the same line the . wont just keep going to the end of the line regardless (greedy vs lazy matching)
"(.|[\n])" means either a character\whitespace or a new line
"*?" specifies to match 0 or more of the expression in the parentheses without being greedy.
Examples:
<meta.*?(.|[\n])*?/> will match from the beginning of all meta tags to the end of the respective tags
<script.*?(.|[\n])*?</script> will match from the beginning of all script tags to the respective closing tags
Warning:
Using .*?(.|[\n])*? with improperly or partially filled in start_text or end_text might crash VS Code. I suggest either writing the whole expression out (which doesn't cause a problem) or writing the start and end text before pasting in the regex. In any case, when I tried to delete parts of the starting and ending text VS Code froze and forced me to reload the file. That being said, I honestly could not find something that worked better in VS Code.
Without using regex.
Multi-line search is now possible in vs code version 1.30 and above without using regex.
Type Shift+Enter in the search box to insert a newline, and the search box will grow to show your full multiline query. You can also copy and paste a multiline selection from the editor into the search box.
You can find and replace in multiple lines by using this simple regex : StringStart\r\nStringEnd
For example
public string MethodA(int x)
{
var user;
}
public string MethodB(string y)
{
var user;
}
public string MethodC(int x)
{
var user;
}
public string MethodD(float x)
{
var user;
}
If you want to replace the name of user variable with customer along with method parameter name to user but only for the int ones.
Then the regex to find will be : int x)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar user
and regex to replace will be : int user)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar customer
See for reference
I had a similar issue, this works better for me:
aaa[.\n\r\t\S\s]*bbb
This includes carriage return (\r), new line (\n), tab (\t), any whitespece (\s) and any non whitespace (\S). There seems to be some redundancy putting "." and "\S" together, but it doesn't work without both in my case.
No regex way: you can copy multiline text and paste it in "Find in files" form:
result of "Replace all":
(.|\n)+? or [\s\S\r]* or [.\n\r\t\S\s]* may be understandable when viewed in isolation, but in an already complex regex expression, they can add that extra layer of complexity that makes the whole thing unmanageable.
On Windows, for files on the local disk, I find the best solution is to switch to using Notepad++. Not only does it handle multi-line out of the box, it also has a pleasant interface for multi-file search and replace, handles macros gracefully, and is quite light-weight. You can switch back to VScode as soon you have finished your regex changes. Personally, I deleted Notepad++ when I found VScode, but reinstalled it later when I found some of what Notepad++ had to offer was missing in VScode. Both are free to use! I'm sure there's an equivalent on the Mac.
If you are willing to search JavaScript, TypeScript or JSON files I can recommend my VScode extension
It allows for formatting agnostic text search and structural code search
You can find it on codeque.co or at VSCode Marketplace
Your query could look like this
aaa$$mbbb
where $$m means optional multiline set of any characters
Make sure to use text mode for this query
CodeQue can make much more than that!
The reason on this behavior is very simple.
Multiple line search isn't implemented yet.
see: Support multi-line search for Global search

RubyMine reformatting

This is in the RubyMine IDE.
It seems really simple but I can't find a way to do it. I want to take a line
[:a, :b, :c]
and as part of the reformatting rearrange each value to one line like so:
[
:a,
:b,
:c
]
And assign a nice little keyboard shortcut.
Any idea how I do this? RubyMine documentation isn't great.
Not familiar with a way to use the IDE reformatter for this need.
But, you can achieve the rearrangement using the find an replace tool (CTRL + R).
Mark the regex checkbox.
In the find box look for space - ().
In the replace box, insert newline - \n\t.
Then hit Replace all - it should do most of the job.

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.

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

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.

Custom key actions in Eclipse

Today I have question about Eclipse. I use this IDE very long and I think it is good, but last time I miss for some functionalities...
Is it possible to set some shortcut which will do something like:
Mark some text ('Hello world'), trigger shortcut (Ctrl+T) and it will do something with that text - in example adds text before and after selected text ($this->_('Hello world'))
?
Thanks for any sugestion !
From this, it appears you have to implement your own command in a plugin. The process looks more involved than simply setting a menu choice.
Equivalent functionality can be defined without commands, if you're willing to give up the keyboard shortcut and use content assist instead.
I'm not sure if it will work with the language you're using (PHP?), but with Java in Eclipse it is possible to use Code Templates.
You would define your own template, when it was applicable and what it would do. This could then be accessed with Ctrl+Space through the possible content assist methods. So in the context of Java statements, I can define:
this.call(${word_selection});
So when I highlight a word, such as "Hello, world", I can use the template to change it to:
this.call("Hello, world");
(There are ways to limit it to only String types instead of word selections, but that will most likely not apply to your language, so I didn't pursue exactly how to do it.)
The Code Templates menu is available through Window->Preferences.