Visual Studio 2017: Disable Intellisense for CodeSnippets - visual-studio

I'm using Visual Studio 2017 Enterprise, Version 15.3.3
I looks like IntelliSense has some new features for code completion. On of this feature is, that a field name is automatically suggested when a type is written.
SpacePosition s.. // starting with s, Intellisense suggest "space", "position" and "spacePosition"
I like this feature in general but not for code snippets. Using a code snipped I have the problem, that the name of a literal is automatically replaced by IntelliSense after pressing tab (which is used for navigate to the next literal).
In my example I want to name the property "other" and then jump the the next literal inside the snippet. But because of IntelliSense, the property name is replaced by "spacePosition".
Is there any way to disable the IntelliSense feature inside code snippets?
I found a solution for the same problem in Visual Studio Code:
stackoverflow article but not for Visual Studio

Disable the name suggestions in Tools/Options/TextEditor/C#/IntelliSense. That's what is causing this nonsense. Seems MS realized later that they flipped coders up by adding that feature that changes old behaviour greatly without giving them a way to disable it. Now there is such a checkbox.
I nearly uninstalled this studio because of this lol. Not sure, may be it's a good feature, but i'm too used to Tab code snippets around, that I'm better without it.

How to: Manage Code Snippets
To access the Code Snippets Manager
1.) On the Tools menu, click Code Snippets Manager. Shortcut Ctrl+K,Ctrl+B
How to: Change snippet behavior
To change snippet behavior.
1.) Go to Tools > Options > Text Editor > IntelliSense > Snippet Behavior
2.) See images.

Now there has no such option to disable this intellisense feature inside code snippets, but you can try to click 'Esc' key after type 'other', then click 'Tab' key to jump to next literal, please check the following:

This actually works correctly in Visual Studio 2019 for classes if it is a class that is valid for the current context (i.e. Doesn't exist in a namespace not in the current class namespace or in the using statements for the file).
Here is my example snippet
Snippet Definition
Snippet Use
And here is an example where I use two different classes as the second snippet, one that is a valid class name and works to use tab to autocomplete, and one doesn't work because the class requires adding an additional namespace using statement that is currently missing from the file:
So I see two options.
Use the sucky to cancel any auto-complete logic.
Ensure you have the proper using statements. You can even add using statements to your snippet using the imports declaration:

Related

Visual Studio XAML Intellisense not working until I open a tag

Intellisense working when I open a tag
But I want to use Intellisense without opening a tag. Like in the picture.
I am able to do this with ctrl + Space combination. Is there any way to do it automatically?
I think you cannot get what you want so far. And XAml Intellisense is special and it should work with < and >. So invoke the Intellisense should be with them. There is no such automatic way as you wished by default.
After all, it is not the type of c# or c++ code that can type some word to invoke Intellisense. And Xaml Intellisense is not flexible as you expected.
VS does not design that by default and there is no such vs extensions I found to realize so far.
If you still want your feature, you could suggest a feature on the DC Forum and then share the link here when you finish it. Anyone who is interested in it including us will vote it to help get the feedback from the Microsoft as soon as possible.

Code snippet doesn't show up in IntelliSense

I am accustomed to use code snippets in Visual Studio. I just type cw <Tab> <Tab> and I get Console.WriteLine();. But often that code snippet does not show up in IntelliSense under my cursor. That means IntelliSense will not automaticly fill that code snippet to the code, instead it will fill another keyword, in this case char.
btw. I am using VS 2017, I also have VS 2015, there it works normally.
IntelliSense without cw
If snippets don't appear in IntelliSense list in VS 2019, a workaround is to insert the snippet manually:
Edit|IntelliSense|Insert Snippet or
Right-Click Insert Snippet or
CtrlK, CtrlX.
You're then provided a menu to select between existing snippets, including custom ones.
I had this problem with XAML snippets, which for some reason don't appear normally in the popup.
You can check Tools -> Options -> IntelliSense -> Snippets Behavior is "Always include snippets" or not.
I solved same problem with check this option in vs.
None of the suggestions worked for me. I used Resharper instead:
Create a live/surround template | ReSharper
https://www.jetbrains.com/help/resharper/Creating_a_Live_Template.html

Is there a code snippet editor for Intellij Idea 13?

Visual Studio has Snippet Designer extension available for creating and managing custom code snippets. Is there something like this extension for Intellij Idea 13, or a way to simply add custom code snippets?
There's no extension that I'm aware of (and I'm not familiar with Snippet Designer), but that functionality exists in IntelliJ Idea.
Hit Preferences and start typing to find "Live Templates". Expand one of the existing ones to see some of the available functionality. You can set tab stops, cursor position, references to local variables. It's very handy.

How to triple-slash selected text in Visual Studio 2010

In Visual Studio 2010 we can Comment selected text via Ctrl+E,C - This prefixes selected lines with the double-slash.
Is there a way to select text and have VS2010 prefix the selected lines with a triple-slash?
For the curious; I am adding XML comments to my c# code. Specifically, I am adding example code within the <example><code></code></example> section of my comments. I'm am building the sample code in a throw-away console app (just to make sure I'm creating code that works). When satisfied with the sample code, I copy/paste it into my app that I'm adding XML Comments to. When I paste the sample code, I have to manually add all the triple-slashes. I'm getting kinda bored doing this, so I'm hoping there is a way I can have VS2010 do this for me.
There is no built-in command to do that, AFAIK.
However, you can do it using VS's built-in advanced text-editing features.
Hold down Alt, select a zero-width column of text at the beginning of the lines, then type ///. This will type into all of the lines simultaneously.
You can select that with the keyboard by pressing Home (as applicable), then repeatedly pressing Alt+Shift+↓.

How can I sort Fields, Properties and Methods in Visual Studio?

I know that for clarity in codes, I have to write first fields then constructor and then methods etc. But how can I automate it in Visual Studio?
I think CodeMaid is the best free option for code formatting in Visual Studio.
To sort your file, open the file via solution explorer:
Right click the open file
Code Maid menu (likely near the top of the right click menu)
Click Reorganize Active Document
Alternatively, using the default CodeMaid hotkeys CTRL+M,Z to sort your active file.
ReSharper can sort your class members (fields, constructors, methods, delegates) by name, accessibility, type, readonly, etc... You can also surround specific members with regions. What I like the most is the ability to group interface members (e.g., #region IDisposable with void Dispose() method in it) and methods that handle an event.
ReSharper provides both - an easy way to configure and trigger the sorting of class members.
Configuration
Create a XML file within Visual Studio and copy-paste the default type member layout (ReSharper Options > Languages > C# > Type Members Layout) into that file. Download the latest XSD schema. Add the schema file to Visual Studio's schema files (Menu > XML > Schemas... > Add). You should be able now, to edit the XML file with the help of IntelliSense.
Triggering
If you use the Visual Studio keyboard scheme (ReSharper Options > Visual Studio Integration) and press Ctrl+E,F for Silent Code Cleanup. A dialog will pop up, where you can select a Code Cleanup setting. For this setting you should check Reorder type members. The second time you press the shortcut, ReSharper will automatically reorder your class members.
1: ReSharper Type Members XSD Schema
Visual Studio has no feature that allows re-ordering already written code. That's the domain of add-ons. Resharper has a "Reordering type members" feature but that's only supported for C#, not for VB.NET code. NArrange seems to be able to do this. No idea, never used it myself.
Limited sorting of lines is included with Visual Studio 2022.
To use: select the lines you want to sort and in the top menu click:
Edit > Advanced > Sort Lines
Another option I found is XArrange. It is free and can be installed from the Extension Manager.
Issues I took with it...
It puts methods before constructors.
It removes any comments between members,properties,methods, etc.
It's configuration is very limited. No way to change sorting order.
If Code Sorting is your only concern, you can try the Visual Studio Extension CodeSorter
CodeSorter is highly customizable extension that allows its users to
sort C# code itby various conditions such as names, types (method,
class, struct, ...), visibility modifiers (private, public, ...),
constness modifiers (const, static, readonly) and virtuality modifiers
(virtual, override, new, ...).
It is possible to assign multiple search criteria to have the same
priority, for example place protected and private members first, and
then publics and internals.
Names are compared in a way that leading "m_" and "_" is stripped.
This allows fields and properties (eg. _foo and Foo) to be right next
to each other.
One-lined declarations are placed without delimiting blank line, while
multi-lined declarations are separated by a blank line. The exception
is that one-lined field followed by a multi-lined property without
comment of the same name will be placed without the delimiting blank
line.

Resources