Tab behavior Resharper Intellisense Options - resharper

A product like Resharper has many settings, and I can't seem to find the right settings to get the exact behavior I desire from it.
The behavior I am trying to change is this:
Suppose the endresult I want is
but the line currently is
As you expect I start typing:
and after a tab I get this
but I wanted it to become
Does anyone know how I can change the Resharper settings in such a manner that my desired behavior is realized?
Thank you.
EDIT: Note that tab does perform the desired behavior in the default VS Intellisense.

In this particular case, here's what you should do:
Go to ReSharper > Options > Environment > IntelliSense > IntelliSense Behavior, and set Automatically insert parentheses after completion to Opening only.
Now, with the caret right before SomeMethod(), type in Math.Ab, and complete Abs with Enter, as correctly suggested by Rob H. You'll end up with Math.Abs(SomeMethod();
Finally, press Ctrl+Shift+Enter to invoke the Complete Statement, which in this case will insert the required parenthesis at the end of the statement, and put the caret on the next line.
Keep in mind though that this might not be the optimal solution provided that you probably have plenty of other usages of code completion that could conflict with this kind of settings change.
If that kind of similar code modification is required in multiple places, you should possibly create a search and replace pattern instead.

Hitting Enter instead of Tab will insert without overwriting, although you then end up with
Math.Abs()SomeMethod();

Related

Android Studio: disable warning "if statement can be simplified"

Android studio marks warnings in Java code, some of them I consider useless and want to disable them.
I know I can configure Inspections that are enabled, but for some of these I can't find where it can be disabled. Then code is marked to have issues, and I want to have clean code so that I see real problems.
Example of warning:
'if' statement can be replaced with 'return ...'
And I don't want to put annotations to my code, rather I'd like to switch this off in IDE.
Thanks
When you click on the lightbulb and then on the suggested action's arrow, you get submenu with options. First one should be "Edit inspection profile setting", which should navigate you to the exact place in Settings, where you can edit given inspection.
This is a more general answer for future viewers. These are various ways to suppress the warning.
Statement
Add the following comment above the line with the if statement.
//noinspection SimplifiableIfStatement
if (...)
Method
Add the following line at the beginning of the method.
#SuppressWarnings("SimplifiableIfStatement")
private boolean myIfMethod() {
if (...) return false;
return (...);
}
Class
Add the following line at the beginning of the class.
#SuppressWarnings("SimplifiableIfStatement")
public class MyClass { ... }
Current project
Position your cursor on the if statement and press Alt + Enter. Then choose Simplify > Disable inspection.
All projects
Position your cursor on the if statement and press Alt + Enter. Then choose
Reapplying the inspection
If you disabled the inspection by mistake, you can turn it on again.
Go to File > Settings > Editor > Inspections > J2ME issues
Check the line for "if statement may be replaced with && or || expression"
Notes
The inspection is there for a purpose. It would generally be better to follow the warnings advice and just simplify the if statement. (However, sometimes I find the "simplification" harder to read. Thus my answer here.)
You don't really need answers like this. You can autogenerate the suppression code for any warning by clicking on the code with the warning and pressing Alt + Enter and then expanding the options the lightbulb. You will be given options to suppress the warning for the statement, method, class, etc.
Settings -> Editor -> Inspections -> Java -> Control flow issues -> Redundant 'if' statement
You can type "if statement" in the search box to highlight all inspections involving if.
In Android Studio 3.4.1 at least, if you right click on the Analysis marker at top right of the code pane you can change the level of highlighting there. I've set my level to 'Syntax only'.

2 spaces indentation in google Docs

To prepare an exam, I have to learn coding using google docs rather than using an IDE. It may seem idiot or impratical but the teacher really insists on that. It seems that is the same thing as Google interviews for example...
So far, I really got used with using two spaces indentation (I hate using tab indendation). And I want to learn how can I do that quickly in Google docs. Is there a shortcut or a "tips" (add-on?) for that?
For example, if you have an "if-condition" starting at the position number 4 and you want to move to the following line, it can be really convenient to have the cursor position at 4. Then, you'll add two spaces to start your block at position number 6. (ALL the if block will have at least position 6). But in Docs, when you move to the following line, the cursor always start at the beginning of the line except if you use the tab indentation. And it's really shitting if you want to indent your code properly...
Do you have a solution for that please ?
I was facing the same problem.
To write Python code in google docs, my solution is:
Switch off auto-capitalization, auto-correction and smart quotes. And other auto-substitutions so that you may write code without docs like formatting.
To do this: Tools> Preferences and uncheck the above items. Screen shots attached below.
Set tab to two spaces.
Right-click on ruler on top of page. Add left-tab stop, an arrow will appear, move this tab stop to 2 spaces from left of ruler. Try adding tab in the current line and if the tab size is OK, save this formatting.
To save:
Format > Paragraph Styles > Normal Text > Update 'Normal Text' to match.
Last, to add color(synatx highlight), you may use 'code blocks extension'.
Click install.
Now, write code in docs, select the code in google doc, click on:
Add-ons > Code Block. A pop up opens up.
Choose language : 'python' for me.
Choose theme: 'atom-one-dark'
click Format.
The code looks much like IDE, and writing more code is easier too.
While I understand that sometimes a point can be made by making students do things in a way that might not seem logical, this one doesn't make any sense to me.
Students don't learn anything useful by pressing space twice instead of letting an editor or IDE do it for them.
I wonder, is it because he/she wants it delivered in Google Docs or because they want you coding that way? If it's the latter, you won't have to hide your workaround.
I can only suggest using a good text editor, I always use the excellent and free Notepad++, and copy and paste it to and from Google Docs. Your instructor will never know. In fact, I'd be hunting around to see of there was a way to access your code files directly in Google Docs from Notepad++, or to auto-sync a folder with Google docs.
Notepad++ has syntax colouring - which will save your life - and can be set to indent with tabs or spaces to whatever indent width you specify. If not using an IDE, I only use Notepad++.
Your instructor sounds like some I had, people who cross a line from being quirky but with a point to make to just being a dick. There is absolutely no point in telling a student to code only in Google docs. Google docs is a great thing, I love it, but it is by no stretch of the imagination a coding tool.
(I see that this is an aged thread, but I'll respond in case someone else with a similar issue - like this year's class for that course - comes looking for an answer.)
You could try (ab)using bulleted lists:
Insert a bulleted list
Right click on the bullet, select "More bullets..."
In the "Symbol" selection list, choose "Format & whitespace" and select one of the whitespace options as bullet char
Repeat for as many levels (of bullet sub-lists) as you think you may need in your program
Fix indentation to match whatever feels best for you
Every time you need to write a nested block, you will have to press "tab" only once, then bullet list level is kept and the indentation with it. To go back to the outer block, just press shift-tab.
However, IMHO it doesn't worth the trouble. Generally, interview question solutions are not that large and hitting spacebar a couple of times is not much of an overhead.
It's somewhat cumbersome but you can set as many tab stops as you want, and docs will move nested tabs to the next tab stop as well. For example:
You can add tab stops by right clicking on that tab bar where you want the tab stop to be and clicking Add left tab stop. You'll want to have all text in the document selected if you want the tab stop to apply everywhere.

MacVim/YADR Autocomplete Issue

I have installed MacVim, and https://github.com/skwp/dotfiles (including all the dependencies such as zsh, etc). and I am having trouble getting auto complete to work.
When I'm typing
<tit a pink box shows up with <title>Index</title> and according to the https://github.com/skwp/dotfiles documentation pressing tab will make it autocomplete. Which sometimes works, sometimes it just adds two spaces, however that's not really my question.
When it does auto complete it turns it into
<<title>Index</title>> notice the two < and >
How can I fix this?
Wow… 79 plugins? Really?
At a low level, your problem is that you give someone else too much power over your configuration, your toolset and your workflow.
At a higher level, you are probably misusing your config's auto-completion feature. I think that you have a conflict between the neocomplcache, delimitmate and snipmate plugins: the 1st deals with auto-completion, the 2nd automatically closes pairs of characters (<>,"",()…) while the 3rd does "tab-expansion" on the tit keyword.
Basically, I believe that you are supposed to type tit<Tab> instead of <tit<Tab> to avoid triggering delimitmate.

Perform structural search and replace in bulk

In an existing code base, the call to parse dates depends on the machine's culture. I created a custom resharper search/replace pattern that can spot and fix these calls.
Is there a way quickly find and fix all the hits of this search replace pattern? I'm now doing them one by one and it's going to take forever ...
Isn't the 'Global Fix' at the end of that very blog post you link to exactly what you want?
Global Fix What we’ve just done is a manual local fix,
that is, locate the offending entry and hit Alt+Enter to apply a
QuickFix. We can do this at a global scope by using the
Pattern Catalog tool window.
1. Undo the prefix fix (so as to have several instances) 2.
Open up the Patterns Catalog 3. Select the
recently created Pattern and click on Search now.
This time, instead of the Find Results dialog, we get a Replace dialog
which displays all matching patterns and a Replace
button
4. We can select
the entries we want replacing (by default all checked). Click
Replace We’re done! ReSharper will now
replace all occurrences. So we’ve applied a QuickFix
globally.

Resharper completion without overwriting existing code

In Resharper when I go back to edit some existing code.. eg. wanting to insert a String.Format into this code:
<td>
<%= Html.Encode(item.Address) %>
</td>
I move the cursor to before 'item' and type in 'String.F', getting Resharper's intellisense completion list that includes the 'Format' method.
However if I press TAB then it replaces 'item' with '.Format()'
Is there a way to use completing without replacing the existing text?
Stumbled upon using Enter instead of TAB to choose from the completion list. That does exactly what I want. It surrounds (in this case) 'item.Address' with the String.Format( .. ).
There are two techniques you can use.
The first is to use the Enter key, the second is to pop a space between where you are going to start typing and the next bit of code, which will prevent the next bit of code from being overwritten.
There is an actual setting now to disable this (annoying) behavior.
Go to the Options dialog (Menu -> Resharper -> Options).
In this Options dialog go to Environment -> IntelliSense -> Completion Characters.
Here you can set the Tab behavior to Insert instead of Replace.
Screenshot of Options
Resharper documentation about Completing Characters
This is an addition to the answer in 2010, for everyone that reaches this post via populair search engines ;)
You could also use the String.Format surround template but you may have to map a hotkey to it for easier access.
The keyboard command you want to use is called: Resharper_ForceCompleteItem. So if you go into Visual Studio's Tools > Options > Environment > Keyboard you could assign a keyboard shortcut there. Not sure if it would be possible to use Tab, though.

Resources