Table of contents :

Visual Studio Code logo

2. VSCode, install and screen explanation.

First we will need to install Visual Studio Code itself. It is freely available. You can download it here: "Download Visual Studio Code."
Download Visual Studio Code.
Download Visual Studio Code. Your page might look slightly different, because of possible newer versions.
Installation instructions can be found on the doc page of their website.

Your first steps with Visual Studio Code (VSCode).


When you first open VSCode you get the "Getting Started" tab. Now your screen might look slightly different but you can find the following information:

Visual Studio Code Getting Started screen.
Visual Studio Code Getting Started screen. Yours might look slightly different.
At the top is the menu (yellow accented), below the menu is 1 "Getting started" tab. More tabs can be open. To the left of the green line is the leftbar, this contains the icons that represent some of the the installed plugins. More about that in chapter 5, VSCode, plugins. You might see less icons on your screen, depending of how much plugins your version of VSCode has installed.

Below "Start" are some of the most used commands. In lightred you can see how much of the getting started activities you have already finished.

In green you find your recent files, and near the bottom, under the blue line, you find the bottom bar.


Visual Studio Code bottom bar.
Visual Studio Code bottom bar.

The bottom gear icon, opens the settings. Sometimes the gear icon has a little figure in it, that means there is a newer version of VSCode you can download. The icons with the circle and the triangle, contain figures if there are errors in your source code somewhere.

Before we start editing a file, we go to the directory my-webdesign/course-material where we unzipped the downloaded course material zip-file.
Here we copy the file: Finished Projects/Project 0/helloworld.html, and put the copy in my-webdesign/experiments, it will look like this:

Visual Studio Code, file to use.
Visual Studio Code, file to use, helloworld.html

We will use the file helloworld.html for our first experiments.

Visual Studio Code, editing your first file.
Visual Studio Code, editing your first file.

Now navigate to this file, do a rightclick and choose Open with Code to open the file in Visual Studio Code.

Visual Studio Code, editing helloworld.html.
Visual Studio Code, editing helloworld.html
Let me first say that this is NOT a correct html file. It is an incomplete html file. You can see it contains errors by the little figure right behind the triangle in the bottom bar of the VSCode window. It is only used here to explain screen parts of the editing screen of VSCode.

You see the codelines of the html file in the editing window. But to the right, accented in yellow, you see the same lines in mini format. You can also scroll the editing window from that area. That is very helpfull for long files.
Codelines are automatically numbered for easy reference. Those numbers are omly present in the editor window, not in the code itself.

In the bottombar you can find the position of the cursor, here line 19 column 1. in the bottombar you can also see that tabspacing is set to 2 spaces.
HINT the cursor is on line 19, you can see that by the 2 thin lines around linenumber 19.

Now with the cursor at line 19, column 1, we will type 1 space character. After that the screen looks like this:
Visual Studio Code, editing helloworld.html.
Visual Studio Code, editing helloworld.html
Now there is a tiny black dot visible in the tabbar of this file in the editing window. It denotes there are unsaved changes in this file. If you have more tabs open in the VSCode editor, more of those tabs might have those tiny dots. So you can easily see if there are any unsaved files. After saving a file, the dot in its tab disappears.

You will also notice the position of the cursor has moved, in the file itself and in the bottom status bar.

Now go back to the directory my-webdesign/course-material where we unzipped the downloaded course material zip-file.
Here we copy the file: Finished Projects/Project 0/understanding-bodyhtmlhead.html, and put the copy in my-webdesign/experiments, it will look like this:

Visual Studio Code, second file to use.
Visual Studio Code, second file to use, bodyhtmlhead.html

Our experimenst directory now contains 2 files.

Visual Studio Code, editing bodyhtmlhead.html.
Visual Studio Code, editing bodyhtmlhead.html.

Now do a rightclick on bodyhtmlhead.html and open the file in VSCode. You will notice the closing style-tag is not positioned correctly, it should be aligned among the opening style-tag. We would like to format the code so each opening tag is positioned right above its closing tag. And to have a 2-character tab with. To fix that, select line 2 - 20 as shown in the figure, position your cursor near the green arrowpoint and do a right-click. You will get a popup menu.


Visual Studio Code, formatting code selections.
Visual Studio Code, formatting code selections.

Choose Format Selection and watch carefully what happens when the command is executed.

Visual Studio Code, after formatting the code selection.
Visual Studio Code, after formatting the code selection.
There is now a tiny dot in the file tab, because formatting also changes the file contents.

The selected area is now formatted with a tab of 2 spaces and all tagpairs are standing among eachother.



TIP:
If at any time there are a couple of lines you want to move some spaces to the right or to the left, you can also do the following:
First select the lines. Next press the TAB-key or press SPACE a couple of times if you want the code block to move to the right. If you want it to move to the left, press and hold the SHIFT key first, and press TAB or SPACE afterwards.

Why is it important to format the code for a webpage?


Well, first it is easier to see if you have not forgotten any of the html-elements pairing hooks. And because of the fixed tab length you can quickly find where things might be wrong.
Second, when you have to make changes, or more important, when someone else has to, it can be done easier and faster and with less change of making mistakes.

To help you focus on the code parts you want to change, VSCode has an extra option:
You can fold or unfold certain code parts.

Visual Studio Code, saved after formatting.
Visual Studio Code, saved after formatting.

To demonstrate we look at part of the code we just formatted and saved. This is how it looks.
When you hover your mouse in front of the tag: style you can see a tiny down arrow. Clicking on it will fold all codelines in between its start and end tag.


Visual Studio Code, folding and unfolding a tag.
Visual Studio Code, folding and unfolding a tag.

The folded lines are denoted by three (3) tiny dots. Clicking on it, unfolds the code lines inside this tag.

Visual Studio Code, spotting folded tags.
Visual Studio Code, spotting folded tags.

Even when nothing is selected in the VSCode window, you can spot the folded tags. they are denoted by a thin blue line, in the main editing window, as well as in the mini column on the rightside of the VSCode editor.

By folding parts of your code you get a better overview, and you can move around faster.