Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we’ll learn how to have Visual Studio automatically edit our files for us and save/load our personal preferences.
Further Reading
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Visual Studio has the ability to
edit code for you in many ways.
0:00
In this video, I'm going to show you
how to move your code around and
0:04
clean it up automatically.
0:07
It is not unusual for
an interviewer to ask you to write code
0:09
during the interview process, and
using these editing shortcuts,
0:12
can help you differentiate
yourself from other candidates.
0:16
Let's get started.
0:19
I've loaded up an HTML file with some
pretty severe formatting issues.
0:21
I could fix them myself but
that would be time consuming.
0:25
So let's have Visual Studio
do the work for us.
0:28
Go to Edit format document or
press control K D.
0:31
That looks much better but how does
Visual Studio know that I prefer, for
0:36
example, four spaces for
my tag and indentation.
0:40
It's based on the options
that you set up for
0:44
each of the text editor types
that Visual Studio provides.
0:46
To change your settings for
HTML documents go to Tools, Options.
0:50
Text Editor, HTML, Tabs,
let's change the indent size to 8,
0:57
then reformat the document.
1:02
As you can see, Visual Studio
picked up on my new settings,
1:06
and the indentation is
now set to 8 spaces.
1:09
Format selection works nearly
identically to format document.
1:12
The difference is that is scoped down
to the text you currently selected with
1:16
your cursor.
1:19
Here I've got a large file, and
I'm only working on a small section of it.
1:20
I don't necessarily want to
format the entire document, but
1:24
I do have some pretty gross code that I
want Visual Studio to clean up for me.
1:27
Highlight the selection you want to
format, and go to edit format section or,
1:32
press control K F.
1:36
Since we just changed an option.
1:39
I want to show you a fast way to
find options menu items and windows.
1:40
This search box is called Quick Launch,
to use it I can type control Q,
1:45
and then input Tabs and
1:49
it will quickly launch me to that option
where I can edit my tab preferences.
1:52
This is useful because it's usually faster
than navigating to the options window
1:56
manually but it also allows
you to find nested menus and
2:00
options without knowing whether
nested via free text search.
2:03
Let's say I actually got rid
of my properties window and
2:06
I want to find it again.
2:09
We can just press CtrlQ and
type properties to easily find it and
2:12
get it back.
2:15
Next, I want to show you how to
have Visual Studio comment and
2:17
uncomment your code in markup for you.
2:20
Highlight the section of code you want
to comment out and press Ctrl K C.
2:22
To uncomment your code highlight
the commented lines and press control K U.
2:27
While this feature is extremely useful for
testing and
2:31
debugging, I should note that it's not
considered the best practice to have
2:34
commented out code hanging out
in your application long term.
2:37
If you no longer need a block of code or
markup just delete it.
2:41
Indentation is important for readability.
2:45
Visual Studio allows you to change
the indentation on a line or
2:47
selection of lines using tab and
shift tab.
2:50
To indent, highlight the lines
you want to indent and press tab.
2:54
To unindent do the same but
press shift tab.
2:59
You can also move lines of code up and
down with the ALT key.
3:03
Highlight the lines of code you want
to move, hold ALT then press the up or
3:07
down arrow depending on the direction
you want to move your code.
3:11
Now that you might have
customized a few settings,
3:17
it's a good time to show you how to
import and export your settings.
3:18
Visual Studio automatically synchronizes
your settings across machines if you're
3:21
signed in, but you might find importing
and exporting settings useful if you have
3:25
different settings for
different projects in environments.
3:29
Go to Tools, Settings, Import and
Export Settings, to export,
3:32
select Export selected environment
settings and click Next.
3:37
Choose the settings you want to export,
and click Next again.
3:41
Specify a name and location if you want it
to differ from defaults, and click Finish.
3:44
You can later import these settings by
selecting Import selected environment
3:49
settings.
3:53
Now you know how to automatically format
your code, comment and un-comment your
3:54
code, manage indentation, move your
code around, and export your settings.
3:58
In the next video, I'm gonna show you
some refactoring tools that will empower
4:03
you to become a better developer.
4:07
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up