Visual Studio Ctrl K + D (code formatting) not working
Asked Answered
H

5

28

Ctrl K + D in a Visual Studio 2010 Sharepoint project is not working in some files as they contain paths to some resources (masterpageurl/images/js/css classnames) that get generated at runtime.

How do I make VS to "ignore" checking if these resources exist or not?

Heater answered 14/3, 2012 at 17:24 Comment(1)
Check here by Oddmar Dam - it helped me: #30521264Lixivium
E
22

Code formatting doesn't work in multi-line arrays :

        int[] ok={ 1   ,   2, 3   };
        int[] ko={
                      1   ,
                         2,
                      3    
                 };

use Ctrl K + D

        int[] ok = { 1, 2, 3 }; // nice formatting
        int[] ko ={
                      1   ,
                         2,
                      3    
                 }; // nothing changed :(
Elwandaelwee answered 16/11, 2015 at 13:46 Comment(0)
L
11

Check for other errors in the same file. If there are errors, it will not format the document until they are fixed. In order to help you during design time, you can create dummy resources, point to those, then change the references at runtime to the dynamically generated content.

Lectionary answered 14/3, 2012 at 17:27 Comment(4)
There are no errors. I get three warnings when I compile the solution though - Validation (CSS 2.1): 'border-radius' is not a known CSS property name. and that is a CSS file, not the file I'm currently working on.Heater
The very first line of this file has something like this -- ...MasterPageFile="~masterurl/default.master"%>. Not sure if I can create dummy reference for that.Heater
Yes -- only three warnings mentioned above.Heater
you dynamically create your master page?Lectionary
P
0

Well mine was Shift+Alt+F and I was also upset

Here how to change it

Update your Keyboard shortcuts to reflect this. Currently it is assigned to "Move last selection to next find match", but you can easily assign it for formatting code.

File > Preferences > Keyboard shortcuts (or CTRL + K, CTRL, + S Search for "Format Document", or "editor.action.formatDocument" and re assign the keyboard shortcut to CTRL + K, CTRL + D

Pirtle answered 30/10, 2022 at 23:35 Comment(1)
this is for vscodePh
B
-4

You can choose from the following menus:

Tools -> Options -> Text Editor -> <Pick your language> 

or use

"All Languages" -> Tabs -> Indenting -> Smart

Also, my own preference is to change the tab section to "Insert Spaces". this way, when you open the visual studio files in a different editor, such as notepad, the formatting will be the same.

Beaston answered 16/12, 2013 at 13:52 Comment(0)
P
-7

CTRL-K-D will always format. I left out a semicolon and because of an error as specified in the above posts the formatting didn't work. Make sure that there are no errors and the formatting will always work. An easy way to spot an error is to look on the right hand sidebar for any red dots.

Penile answered 6/5, 2017 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.