Can you make Visual Studio use tabs instead of spaces for new template files? - visual-studio

I've modified my copy of Visual Studio to keep tabs (instead of spaces) in all my files via Tools => Options => Text Editor => All Languages => Tabs. However, when I create a new project or file, any boilerplate code that Visual Studio includes is always padded with spaces, not tabs (and in cases like web.config, not the specified number of spaces either).
Is there a way to force these all to use tabs automatically when created?
Note: I'm using Visual Studio 2015 Pro, but I suspect other people would be interested in this for other versions as well.

I don't think you can without modifying the template contents, but if you invoke Format Document (Edit => Advanced => Format Document or the keybinding it shows in the menu) after creating the file it should replace them all according to your settings.

I'm using the Productivity Power Tools 2017 with "Fixed Mixed Tabs". As soon as I add some own code with a tab indent and save the file I get a warning about "mixed tabs". I then can replace the spaces with a click on the "Tabify" button.
Not perfect, but pretty close.

Related

Visual Studio Editor Tab settings

i am trying to set the tab size to 2 characters in Tools, Options, Text Editor, All languages, Tabs. When i do this, I can see that the tab settings in all other languages change. Also going back into code and forth in to settings i can see that the settings are applied (or didn't desapear).
Now, with the Keys STRG-K, STRG-F all the settings are gone!
What is overriding/overwriting my settings?
Note: I already removed the check of Text Editor, Advanced, Use adaptive formatting. Also i didn't find any .editorconfig file in my project overriding my settings.
Thanks in advance!
Visual Studio 2022

How to stop Visual Studio from putting extra newline at the end of a file on save

I'm using Visual Studio 2019, and when I save a file (a cs file for example) VS will put an extra newline at the of the file.
I need to stop this behavior, but what I have searched on the internet so far, was about visual studio code or editors other than Visual Studio.
What is the philosophy of putting an extra newline at the end of file?
According to this link, I need to make Advanced Save Options menu visible, and then click it and change line endings dropdown value from Current Settings to Windows (CR LF).

Replace tabs with spaces in Visual Studio project files (sln & vcproj)

I'm trying to have a strict no-tab policy at my company by adding blockers on commits which introduce tabs.
Problem is visual studio uses tabs for their .sln & .vcproj files even when your settings are set to use spaces instead of tabs in the VS editor.
Anyone know how I can change that or am I stuck making another microsoft exception?
For your information, spaces are supported in vcxproj but not in sln files. Replacing tabs by spaces in .sln will make it load incorrectly (not generate exceptions or anything).
There are no settings in visual studio itself to change that though.
There are scripts that can do it before submitting in a source control but keep in mind that .sln files must keep the tabs to work correctly.
This is fixed in Visual Studio 2019.

How to include special characters when selecting text in the Visual Studio editor

I've recently started following the recommendation to use $ as the first character in the name of all jQuery variables, so it's easy to differentiate them from normal JavaScript variables.
Unfortunately the JS editor in Visual Studio 2010 doesn't pick up the $ when I double-click to select a word, or when searching for "whole word".
I know some text editors (Textpad, for example) allow you to tweak which characters are included in words. Is there any way to control this in Visual Studio?
This doesn't really answer the question, but the problem has gone away as the $ symbol is included automatically in VS 2012 and beyond.

Can Visual Studio 2010 do ".inc" file syntax highlighting?

Can Visual Studio 2010 be configured to do syntax highlighting on ".inc" files? We have numerous large projects with tons of these ".inc" files (asp files) and so changing the file extension to ".asp" is not an option. All I want Visual Studio 2010 to do is treat these ".inc" files just like ".asp" files when it comes to syntax highlighting.
I've tried "Open With..." and selected the HTML Editor, which is the ".asp" default, but that did not work. I tried about every other editor in the list and none of them worked.
I know Notepad++ (among others) can do this, but I would prefer this be done in Visual Studio 2010 - using another IDE or text editor is not the answer I'm looking for here.
In Visual Studio...go to Options -> Text Editor -> File Extension. Type in 'inc' as extension and editor as 'Web Form Editor'. You may need to close then re-open your currently open .Inc pages...Hope this helps
I found both the 'Web Form Editor' and 'HTML Editor' to be less than ideal for me. Both of them appeared to highlight the syntax of the HTML ok, but the VBScript keywords were left in standard black text along with everything else.
While not ideal, I followed the instructions from the other answers, but substitude Visual Basic as the editor type and that worked much more to my liking (as they were include files, there is little HTML in them).
Options -> Text Editor -> File
Extension. Type in 'inc' as extension and set editor as 'Visual Basic'.
Close and re-open any '.inc' files and highlighting should be visible.
Antonio's solution worked for me. I did have to close and reopen files, but after I re-opened them the highlighting was visible. Thanks!
Options -> Text Editor -> File Extension.
Type in 'inc' as extension and set editor as 'Web Form Editor'.
Close and re-open any '.inc' files and highlighting should be visible.
Incidentally, this also works in Visual Studio 2005.
Use the File Extension, Text Editor, Options Dialog Box.
http://msdn.microsoft.com/en-us/library/4k7w5e5s.aspx
-update-
I see the same behavior :-( Will let you know if I find anything.
As a workaround, could you rename all your .inc files to .asp?
This has the added advantage that if a request is made for the inc file directly (highly unlikely but possible; and assuming you have the incs in the web directory), your code will be exposed unlike .asp where it is processed and rendered.
I really wanted to add a comment, because this is not a direct answer, but apparently you need 50 reputation for that.
I've found that in Visual Studio 2005 (again, in Tools -> Options -> Text Editor -> File Extension), both "Web Form Editor" and "User Control Editor" highlight both the HTML and the VBScript.
Amadiere mentioned that "Web Form Editor" doesn't highlight the VBScript in 2010, but maybe it's worth trying "User Control Editor", if that's an option in 2010.
In Visual Studio 2010 and 2012 Express it best works for me when I use "Microsoft Visual Basic" with my .inc files. Nevertheless, it's still not the same as with .asp files as there's no Autocomplete nor IntelliSense (Ctrl+Space, Ctrl+Shift+Space etc.) with the .inc files.
It should be made possible defining that .inc files are to be treated just as .asp files.
I agree with Purple Coder:
You should not name the files containing ASP code as .inc. It is a security risk. Anyone who knows/can guess the filename can open it in a browser and view the actual code inside the file.
But, first of all in my case this is an intranet page and therefore not very risky, as most people there would somehow find the files on the server anyway. I'm also not sure where this naming convention came from. It was there before I started. This was started on Visual Studio 6.
But, to avoid this risk there's a simple solution: add .inc in the Application Mapping of the IIS in the same manner as .asp.
You should not name the files containing ASP code as .inc. It is a security risk. Anyone who knows/can guess the filename can open it in a browser and view the actual code inside the file.

Resources