Formatting JavaScript code embedded in a cshtml file - visual-studio

Is it possible to format the JavaScript code embedded in a .cshtml file using the Visual Studio editor?
I tried the Ctrl+K, Ctrl+D keyboard shortcut, and also the "Format Selection" option in the context menu. However, neither of these seem to work on JavaScript code.

I just searched and found the PrettyJs plugin. I do understand that there might be other plugins that do the same thing, but this works perfectly well for me.
With this plugin, you can format your JavaScript code either as a document or by selection. Both can be done using the shortcut keys Ctrl+B, Ctrl+F and Ctrl+B, Ctrl+G, respectively.

Related

Auto-indent after pressing `Enter` between tags

Please see the GIF below:
I am using Visual Studio Code. By pressing Enter and Ctrl + Shift + Enter. I can make the auto indent in the next line.
So, I guess there is a more convenient way or package which can accomplish that by just pressing Enter.
In preference->editor search for autoIndent and make it full
I resolved this problem by switching Language Mode from Django HTML (for some reason it was auto detected) to HTML.
Press Ctrl+Shift+P (or directly press Ctrl+K, M => Select HTML)
Print 'Change language mode' and press Enter
Select HTML
I'm not sure if you are still having this problem, but I stumbled across this other post that seems to have a solution:
Visual Studio Code Auto close tag and indent XML as with HTML
Hopefully this is what you're looking for.
EDIT: I've just realised that this causes the language mode to be changed to HTML, which may lead to unexpected/unwanted behaviour. It suits my needs, however.
I have modified the Emmet preferences, I'm not sure if it's a good solution, but it works.
In the preferences, search emmet.includeLanguages
Click Edit in settings json
In the right column, click on User settings
Add "emmet.includeLanguages": {"php": "html"} on the last line

How to selectively suppress code formatting in Visual Studio

I work with large C# files. I use the Edit > Format Document feature of VS2010 (Keyboard shortcut=> Ctrl+k, Ctrl+d) to format the layout of the code. Sometimes however, I would like to align code in a specific way; for readability.Question: Is it possible to isolate a section of code which I want the VS formatter to ignore?
How about using
Ctrl+k, Ctrl+f
Which is Format Selection

some keys don't work in the tool window of VS 2010 extension

I created a vs 2010 extension with a tool window. I have a browser inside my tool window.
When i type text in the browser everything works fine but when i click on some keys like "enter" or "backspace" the action is being made on the source code editor of VS and not in the browser inside my tool window.
Any idea why ?!
My question was answered in msdn: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/57eebe60-59c0-471c-9540-7fbb13d0b4e7/
Just follow the example in the last post and it'll work fine.

Visual Studio 2005 quick file search

In Eclispe you can do Ctrl+Shift+R and a Window popup where you can write the name of the file (or just the beginning of it) and to press enter to go directly to the file.
What is the equivalence in Visual Studio 2005? (Ctrl+Shift+F is not what I would like).
From Top 11 VS 2005 IDE tips and tricks:
This is the Find dropdown that is on the Standard Toolbar, not the Find dialog. Use the shortcut CTRL+D to activate the Find dropdown in normal mode. Use CTRL+/ to activate the Find dropdown in command mode
To quickly go to a file, type CTRL+D, >open <start of file name>. Intellisense works here just like in the Command Window. "of" (short for "open file") can be used instead of open.
I am not sure if there is a built-in command but there are some addons like VS File Finder
Hit Ctrl+D (Find Combo - the one in the toolbar), write ">of " and the name of the file.
I am using ReSharper, so I am not sure if the shortcut is exactly this one in your case.
I don't know if there is an equivalence, but you can probably do it with the macro editor. It's pretty powerful and you can do pretty much what you want with it.
In plain VS.NET 2005, Go to the command window (Ctrl-D), type "openfile" (or just "of") and the file name.
If you have Resharper (and you should have it), you can type Ctrl-N and type in the class name, or Ctrl-Shift-N and type in the filename.
Gulzar proposed VS File Finder that was the greatest solution here.
But I installed SonicFilFinder because the GUI was better. It works like a charm and you can use the HotKey you want. Really fast and no need of of the mouse. It's free.
In VS 2010, you can use Edit > Navigate To... (Ctrl+comma).
Pro:
Also searches objects/methods
Con:
Doesn't support * wildcards
Window isn't dockable
See: MSDN Blog

How do I edit work items in the Visual Studio 2008 xml editor?

I'm trying to customize some TFS work items via the VS2008 xml editor, but every time I open a work item xml file it jumps to the graphical designer. All that gives me is a "View XML" button that doesn't let you edit the xml directly.
I don't have TFS but I know in regular VS there is an Open With... option in most items' contextual menu that even let you change the default editor. Very useful when you are tired of the Designer opening instead of the Code file on Windows forms.
Ah, looks like you have to go to File->Open and click the down arrow next to the Open button to "Open With" the xml editor. If someone wants to copy and paste this, free accepted answer :P
As per Coincoin's answer, this feature is also great for setting the default editor for ASPX. If you want to go to the Code Editor most often, then this is a default you'd want to change.
Reading this - I think perhaps you don't realize - that there is no need to edit the XML - in fact it is very difficult to do so. The graphical designer will actually let you change the Work Item type, adding new fields, changing workflow, rules etc.
The only reason to change the XML is if there's a bug in the Process Editor (the tool that gives the graphic designer). I have done extensive modifications of Work Item types and only had one instance where I had to change the XML.

Resources