Some of our projects call for default Visual Studio tab options (width 4; keep tabs); some call for width 3; use spaces. Don't ask.
Rather than set these globally, is there anyway in which I could set this on a per-solution or per-project or even (emacs-style) per-file?
Visual Studio 2005 and 2008.
Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately. If this doesn't happen (it's a little lag sometimes), just reload or restart your VS Code.
Underneath "Text Editor", expand the "All Languages" heading. Underneath "All Languages", select the "Tabs" item. In the textboxes on the right, fill in the tab size and indent size that you want to use. You can also determine whether to keep tabs or automatically replace them with spaces.
The most convenient solution I know is to create a set of Visual Studio macros to switch to the settings you want.
Go to Tools > Macros > Macros IDE
. There, in the tree on the left, right-click MyMacros
and choose Add > Add Module
. Give the module a name such as TabSize
. Within this module, create subs to change the settings you want. For instance:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module TabSize
Sub Tab3()
SetTabAndIndentation(3)
End Sub
Sub Tab4()
SetTabAndIndentation(4)
End Sub
Function SetTabAndIndentation(ByVal value As Integer)
DTE.Properties("TextEditor", "AllLanguages").Item("TabSize").Value = value
DTE.Properties("TextEditor", "AllLanguages").Item("IndentSize").Value = value
End Function
End Module
There is no useful documentation I know of for the string parameters. If you need to set other options, such as "Keep Tabs", the easiest approach is to make these changes manually (unter Tools > Options
). Then, using Tools > Import and Export Settings
, save these settings as a vssettings file. This creates an XML file whose structure is the same as that needed for the method calls.
Finally, you can link these macros to command buttons or keyboard shortcuts via Tools > Customize
. Giving each macro a keyboard shortcut allows you to quickly toggle between settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With