Visual Studio 2022 turn off auto indenting - c#

So i upgraded to VS 2022. and anytime i add a semicolon. the whole code block gets backtabbed. does anyone know how to turn this off? getting tired of hitting ctrl z repeatedly..
Before.
After

Go to VS2022 Tools - Options Menu
Type indent in search
Look for Indentation under formatting option which appears under
Text Editor - C# - Code Style - Formatting Indentation
check / uncheck boxes to see how your code will look and save when happy

After consolidating code blocks to one block on the razor page... this seems to have corrected the issue. the indenting I believe may have been caused by some bug where the indenting fails due to attempting to address other formatted code. this is not really a solid answer but i did find that moving things around prevented this from occuring and this was nothing to do with any indenting settings within the tools text editor options.

I'm not sure if you ever found the correct answer to your question, but I was having the same problem, and reading the other two answers led me to figuring it out. The problem is with the adaptive formatting option being turned on. To turn it off, go to
Tools -> Options -> Text Editor -> Advanced
You should see
Uncheck 'Use adaptive formatting'
Save, and restart Visual Studio
This should do the trick for you.

In visual studio 2022 community:
Go to Tools -> Options -> "Generate .editorconfig file from settings"
Open .editorconfig in some text editor
Search for "indent_size" and "indent_style" and adapt them to your needs
effects are reflected without even restarting visual studio

There is another option under Tools - Options
Text Editor - All Languages - Tabs.
Try to specify Tab size and indent size

Related

Disable "Name can be simplified" IDE0003 fix hint

Visual Studio 2017 shows a hint for unnecessary this qualifiers even when the inspection is disabled in the options.
This is how it looks:
(First line is the culprit, second line is how I want this to always look like.)
Hovering over the grayed out this and clicking on the light bulb shows this suggested fix:
I can't find a way of disabling this completely. Sometimes I want to have "unnecessary" this qualifiers and sometimes I don't, so I don't want VS to comment about this at all.
"None" is the least severe option yet it still shows this annoying, different color.
Is there any possibility of complete disabling this inspection?
You can use a ruleset file to disable any analysis if you know its diagnostic id (in this case 'IDE0003')
On the References node of you project right click on Analyzers and select Open Active Rule Set
Once the ruleset editor is open just search for IDE0003 and uncheck the checkbox. Then save the ruleset file. Then save the project.
The following XML will be added to you project file. You can add this ruleset file to any project where you want this rule disabled.
<CodeAnalysisRuleSet>ConsoleApp9.ruleset</CodeAnalysisRuleSet>
Looks like the current process is more complicated for .NET Core and .NET Standard projects.
From MS VS Docs:
If you have a .NET Core or .NET Standard project, the process is a little different because there's no Code Analysis property tab. Follow the steps to copy a predefined rule set to your project and set it as the active rule set. After you've copied over a rule set, you can edit it in the Visual Studio rule set editor by opening it from Solution Explorer. [emphasis mine]
Taking the first link in that quote will eventually take you, after a little sleuthing, to Code style rule options, that finally tells you how to add the file:
In Visual Studio, you can generate this file and save it to a project at Tools > Options > Text Editor > [C# or Basic] > Code Style > General. Then, click the Generate .editorconfig file from settings button.
NOTE: This produces a tiny warning just under your toolbars that an .editorconfig has been added to your solution. Select the "Yes" button to include it in your solution.
And now you can open and edit your new .editorconfig file.
Looks like this is the "offending" section:
# this. and Me. preferences
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = true:suggestion
dotnet_style_qualification_for_property = false:suggestion
If that dotnet_style_qualification_for_property is changed to = true:suggestion (explanation here), I think you're golden [at least for properties, of course -- make edits as appropriate].

Collapse all #regions only(!) in C# (Visual Studio)

There's a number of keyboard shortcuts and menu commands to automatically expand or collapse all foldables in the current document. Ctrl+M,
Ctrl+L toggles all foldables recursively, from the top namespace down to the inner methods and comments. Basically everything that has a [+] icon in the left margin. Ctrl+M, Ctrl+O does it bit less, but it still touches methods and comments inside the class.
I'm looking for a function that specifically only regards #region foldables and nothing else. Not namespaces, classes, comments, or methods. I really only want to fold those areas that are explicitly marked as such with the #region keyword.
Is there any hidden shortcut or an extension for that?
I'd prefer a keyboard solution, for Visual Studio 2015 (RC for now).
In case somebody asks why: I want to get an overview of the file, but immediately see all the details when I decide to look inside one region.
Update:
Solution in 2020
As this question has received many answers, some of them useless, others outdated, the working solution for Visual Studio 2019 can be found in this underappreciated answer here: https://stackoverflow.com/a/58999093/143684 Link to VS 2022 version in the comments.
in Visual Studio 2017 I have to activate 'Collapse #regions when collapsing to definitions' in
Tools -> Options -> Text Editor -> C# -> Advanced
explicitly to collapse all when pressing Ctrl+M+O
Ctrl+M+O will collapse all.
Ctrl+M+L will expand all. (in VS 2013 - Toggle All outlining)
Ctrl+M+P will expand all and disable outlining.
Ctrl+M+M will collapse/expand the current section.
These options are also in the context menu under Outlining.
Right click in editor -> Outlining to find all options. (After disabling outlining, use same steps to enable outlinging.)
To collapse regions : Tools > Options > Text Editors > C# > Advanced >
Check "Collapse #regions when collapsing to definitions"
Update for VS2022: https://github.com/mdmower/CollapseRegionExtension/releases/tag/v1.5 (thanks #ygoe)
I know this is an old question, but here's an update for visual studio 2019:
The Quick Tasks solution from #ygoe's answer does not work for Visual Studio 2019, because that version changed the way the Quick Task bar searches. Plus it was never the preferred solution to the original question, since you needed to type a quick action instead of having a keyboard shortcut.
I found a different solution on the marketplace which does exactly the collapsing and expanding of all regions in the currently opened file with keyboard shortcuts: Collapse Region
From the extension page:
Default key bindings are (Ctrl+R, Ctrl+Num+) and (Ctrl+R, Ctrl+Num-).
Can be changed in Tools->Options->Environment->Keyboard.
The Visual Studio extension Productivity Power Tools 2015 from Microsoft has a feature called Quick Launch Tasks that adds new commands to the Quick Launch menu. One of them is CollapseRegions and it does exactly that.
The opposite command is ExpandRegions and it expands all regions for quick browsing of the entire file. These commands can be used pretty quickly by pressing the CtrlQ hotkey and typing Coll resp. Exp, then pressing Enter (supposed you don't have other commands with the same prefix).
tick the Checkmark in Settings -> TextEditor -> C# -> Advanced -> (section Outlining) Collapse #regions when collapsing definitions.
then right click in the editor > outlining > collapse to definitions
I dont know if this is new, but there is a setting for the c# text edior:
Settings -> TextEditor -> C# -> Advanced -> Collapse #regions when collapsing definitions.
When its set CtrlM CtrlO will collapse the #regions.
Looks like the closest thing is Ctrl+M, Ctrl+S
Which will collapse the current region you are in, while Ctrl+M, Ctrl+E will expand the current region you are in.
List of default keyboard shortcuts:
https://msdn.microsoft.com/en-us/library/da5kh0wa(v=vs.140).aspx
I recommend using the free Visual Studio extension "Menees VS Tools Extension for Visual Studio." Just search for it in Tools --> Extensions and Updates in Visual Studio. Once installed you just have to hit Ctrl+M+K and just the regions will be collapsed. Here is their website https://marketplace.visualstudio.com/items?itemName=BillMenees.MeneesVSTools2013
To edit the settings look under Tools --> Options --> Menees VS Tools --> General.
For Visual Studio 2022, here is the tool that works well:
https://marketplace.visualstudio.com/items?itemName=EngineDesigns.CollapseAllRegions
CTRL-M CTRL-R
to collapse all #region groups.
Not sure about previous Visual Studio versions, but in VS 2022 we have new shortcut
CTRL + M + M
It will collapse any part of code like namespace, class, region etc.,
Steps:
Go to #region piece of code.
Select #region or click on #region anywhere in that word.
From Keyboard click CTRL + M + M
If you want for entire namespace to collapse, you can do same steps by selecting or clicking namespace.
Select All via Ctrl A and then Ctrl M M
i.e. Press M twice while holding down Ctrl

Indenting changed after I re-installed Visual Studio 2010

When I edit C# file in Visual Studio 2010, it looks ok, but when I open it in another IDE or push to github, I notice that indenting is wrong. It happened after I reinstalled Visual Studio.
Any idea how put this on the line again? I do not remember changing any indenting options in previous installation, and I definitely didn't do anything to it this time either.
UPDATE:
By wrong I mean this (faked, since it cannot if copy/pasted it gets ok):
_req = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(_options["url"]));
_req.Method = _options["method"];
// disable buffering (this only works for ClientHttp version)
//_req.AllowWriteStreamBuffering = false; // causes silent crash on Mac OS X 10.8.x
in Visual Studio it looks ok. Basically any new line that I add (that didn't exist in files created in previous installation), I get weird indenting.
Probably in your previous installation of VS you have a different settings for your tabs.
Now, the reinstall resetted everything to the default settings.
Check the menu Tools, ->Options, ->Text Editor, ->C#, Tabs
and try with different settings
You can change the automatic formatting of text in Visual Studio by going to Tools --> Options --> Text Editor --> C#.
There you can change the way indentation is done in the Tabs submenu and in --> Formatting --> Indentation.

No intellisense in VS2010

I've got no intellisense at all in my VS2010 installation.
I've look at the answers on here, the relevant boxes in Tools->Options are selected and I've tried the "Ctrl-alt-space" shortcut that is also mentioned but nothing.
It's not even showing "Go to definition" when I right click on a variable or auto-tabbing new lines to the right place.
Any hints?
I've tried repairing my installation - I'm not sure if my attempts to install it on my second drive (which I then abandoned) have resulted in some issues but any help would be appreciated.
For the record, if anyone finds this later I had to use:
http://archive.msdn.microsoft.com/vs2010uninstall
To uninstall and then reinstall VS2010.
Have you tried:
Tools->Import and Export Settings-> select "Reset all Settings"
I was having the exact same problem in vs2008. All of my settings were correct in Tools -> Options -> Text Editor -> All languages -> Statement Completion as well.
After much searching, I decided to try to close out of every open source file, close the solution and re-open it. Then re-open the affected source file. This fixed the issue for me and intellisense/Go To Definition returned to full functionality. Unfortunately I can't back this up with hard science/any logic whatsoever, but it did the trick for me. Sorry for the anecdotal answer but thought I would share.
This article may also help: http://msdn.microsoft.com/en-us/library/ks1ka3t6(v=vs.71).aspx

Is it possible to copy code from Visual Studio and paste formatted code to OneNote?

Is there a way to copy code from visual studio (C#) and paste it into OneNote, without losing the formatting?
I was able to do this, but only if I copy from VS, paste to Word, copy from Word, and then paste to OneNote.
This is an option that seems to be disabled by default.
To enable (in VS 2019):
Go to Tools -> Options
type copy in the search box
Under Text Editor -> Advanced...
Check Copy rich text on copy/cut
Top copy as formatted
Once the feature is enabled, depending on the target, this may be a two-step process. If, after copying and pasting code, it still appears as unformatted (e.g. if pasting into a web browser), use the approach suggested by marcus, by first pasting into wordpad.exe (start -> run -> type wordpad), then copying the text from within Wordpad again, and pasting into the target application/browser.
There is fortunately a solution for Visual Studio 2010! Install the Visual Studio 2010 Pro Power Tools extension and copy/paste to OneNote retains syntax highlighting.
You have hit the nail on the head on the process. The application that you are pasting to must be able to accept the code with the formatting properly. MS Word is one of the few that handles this properly, therefore, going from VS -> Word -> OneNote will work. But VS -> OneNote doesn't work.
For Visual Studio 2008 ---- http://blogs.msdn.com/b/johnguin/archive/2010/11/29/an-addin-to-help-visual-studio-users-with-moving-code-to-onenote.aspx
There is an add-in for Microsoft Visual Studio that allows you to copy source code, syntax highlighting, and line numbers as HTML.
With this add-in, you can copy from VS and paste HTML directly to your target.
Check it out here:
CopySourceAsHtml
NoteHighlight will do the trick. I found it through the following blog post, codefoster.
Try this elegant solution directly from Microsoft: Productivity Power Tools 2015
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ProductivityPowerTools2015
The HTML copy-paste works nicely with OneNote.
Well , sorry for replying late, I know it's very old post. But , it might help to one who is trying to find it out solution for above said question. I found none to work for me even OneNote 2016, but here it is very easy way to do.
Just copy your code and paste it to wordpad.exe it suppose to paste with formatting and colors. Save *.rtf file and open it in Ms Word , from there you can copy/paste any document in word, it worked for me.
The GEM OneNote addon has a syntax highlighting feature -> http://www.onenotegem.com/blog/onenote-insert-highlight-syntax-source-code
Notehighlight supports syntax highlighting for :
C#, SQL, CSS, JS, HTML, XML, JAVA, PHP,Perl, Python, Ruby, C++
They have release a port has been release compatible with OneNote 2013 (Also happens to work with OneNote2016)
The best way of keeping the format of your code completely is constituted from two steps:
In the first step right click the code and click "copy" then paste it in "wordPad"
In the second step copy from "WordPad" to word.
I just figured out a workaround to do this without any plugins.
Insert a table to OneNote with only one cell
Change the shading color of this table to vscode background color, you can use the color picker to pick the bg color of vscode
Choose the code block you want to copy and convert the indent to tab(otherwise the indent will be lost when pasting)
reference: https://github.com/Microsoft/vscode/issues/35954
Copy the selected code and paste it into the cell
Change back the code indent of source code to space.
PS: I have tried in macOS it works fine
I just view the code on the website of my repository of choice and copy from there.
Then paste to OneNote with keep source formatting.

Categories

Resources