Resharper completion without overwriting existing code - resharper

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.

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'.

Any way to surround selection with braces automatically on typing {, using VS2012 and ReSharper 8?

I know I can make a selection and use the ReSharper action-menu to surround with braces, or use one of the many "Surround with..." keyboard shortcuts.
What I am looking for is a way to do the following (aka the laziest possible way):
Select some code
Press {
The selected text is now surrounded with braces.
This works in e.g. Xamarin Studio (for [,{,( braces).
Is there any way to achieve this in Visual Studio, either using built-in functionality or a plugin?
You should be able to write a resharper plugin to do it. You can register a typing assist handler for a particular character (such as '{') by calling ITypingAssistManager.AddTypingHandler. Your handler should look to see if the document has a selection, and modify the document to insert the open and closing character around the selection contents.
The only problem might be precedence - the '{' character will already have a handler for C# documents. Adding another handler will add it to the end of the chain of handlers, and the existing handler might jump in first. In which case, you could register yourself with ITextControlManager.AddTypingHandler, which is what TypingAssistManager does, but it allows specifying a priority, so you can be called before TypingAssistManager.
As ever, point dotPeek at the ReSharper bin folder and start spelunking for usages of AddTypingHandler, or look at the implementation of TypingAssistManager.

Visual Studio hot key - switch Find context/location

Is there a hot key to toggle the search context/location in the "Find"/"Find in Files" commands (Ctr+F and Shift+Ctrl+F respectively )? I'm talking about the drop down that asks where to search for example Current Project, Current Document, Entire Solution etc.
"Find" is probably my most used feature since working with markup and CSS very often I can't just F12 to a selector definition or Shift+F12 to Find Usages, a regular text search is really the only option and I want to make this as efficient as possible.
Yes, I can tab to it but this takes 6-tabs and if I do it fast, often get the count wrong and prematurely execute bad searches; so it's not cutting it.
If there isn't a hotkey how can I set one? Ctrl + F3 would work well since F3 is "Find Next"
Thanks
I'm not sure if there is a command in Visual Studio that does what you are looking for.
If there is one, you can set the shortcut key in the Tools\Options menu (Environment\Keyboard).
In the screenshot, I'm searching for all the VS command that contain "find". Perhaps one of these is what you need.
Then move to the Press shortcut keys textbox and choose your desired key binding.

Shortcut for deleting a line in dreamweaver?

What is the shortcut for deleting the current line where the cursor positioned.
ex: eclipse have crtl+d
To delete line(s)
Mac: Command+Shift+D
Windows: Ctrl+Shift+D
https://helpx.adobe.com/dreamweaver/using/keyboard-shortcuts.html
There are no direct shortcuts as far as I know but here is a list of commands for dreamweaver.
http://cpaoffers.com/design/dw-shortcuts.php
My typical method to do this is to hit the home > shift+end > del.
Or you could try shift+up or shift+down to select the line above or below and then hit delete.
Danilo Celic's answer helped me with CS6, just use the second one. Although it's in Japanese, just install and use it.
If you want to know more: Then, find the installed files in your own
C:\Users\[your user name]\AppData\Roaming\Adobe\Dreamweaver CS6\[your CS6 language]\Configuration\Commands
There you can open the just-installed files and check them. The comments are in Japanese. The code are in Javascript and are easy to read.
There are 5 commands in that file. To use only the "Delete line" function: In CS6, open history panel, go to design mode, do any action like press a key, right click on that action from history panel and record that action. Then you can find the record action in the Commands folder mentioned above, and then you can copy the javascript from the downloaded one into your own recorded action file.
I've seen two extensions that add the delete line functionality:
http://xtnd.us/dreamweaver/codeextras
http://yoropan.com/en/archives/544
I haven't used either one. I've been told that the first one may not work in Dreamweaver CS6, no idea about the other one. once installed, you should be able to add a keyboard shortcut (Edit -> Preferences, Dreamweaver -> Preferences on Mac) for functionality that you're looking for.
You can add a custom keyboard shortcut for deleting lines in Dreamweaver.
Dreamweaver uses Brackets for its text editor, and this is what handles the Delete Line command, not the traditional Menu system for rebinding most other Dreamweaver commands.
Create a Brackets keyboard shortcut configuration file.
Windows: %APPDATA%\Adobe\Dreamweaver CC 2019\en_US\Configuration\Brackets\keymap.json
Mac OS: ~/Library/Application Support/Adobe Dreamweaver CC 2019/en_US/Configuration/Brackets/keymap.json (untested)
Create an override in this file, according to the Brackets User Key Bindings JSON Data Format. Make sure you use the - separator between key names, not +.
{
"overrides": {
"Ctrl-E": "edit.deletelines"
}
}
Rebind any conflicting keyboard shortcuts in Dreamweaver. In my Ctrl+E example above, it collides with Quick Edit.
In Dreamweaver, go to Edit → Keyboard Shortcuts.
Make a new Set if you're using the default Dreamweaver Standard Set.
Find the command you want to change. Quick Edit is in the Code Editing section.
Highlight the shortcut you want to modify.
If you want to unbind that shortcut, click the - button.
Otherwise, rebind that shortcut by typing the new shortcut in the Press Key field, and then clicking Change.
Click OK to save your changes.
If your change is not persisted, you can usually fix this by editing the following files.
%APPDATA%\Adobe\Dreamweaver CC 2019\en_US\Configuration\Menus\Custom Sets\*.xml
%APPDATA%\Adobe\Dreamweaver CC 2019\en_US\Configuration\Menus\menus.xml
Restart Dreamweaver for your new Brackets keyboard shortcuts to be read.
To bind other commands besides Delete Line, see the full Brackets Shortcuts command ID column.
I used these steps with Adobe Dreamweaver 2019 (19.2) on Windows.

Tab behavior Resharper Intellisense Options

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();

Resources