Visual Studio Code Visual Basic



Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform.

While the short and sweet answer to this problem is to use a breakpoint, the longer answer is that Visual Studio actually provides multiple kinds of breakpoints and methods that let you pause your code depending on the context! Based on the different scenarios you may experience while debugging, here are some of the various ways to pause your. Basic Editing Visual Studio Code is an editor first and foremost, and includes the features you need for highly productive source code editing. This topic takes you through the basics of the editor and helps you get moving with your code.

-->

This article introduces the features of the Visual Studio debugger in a step-by-step walkthrough. If you want a higher-level view of the debugger features, see First look at the debugger. When you debug your app, it usually means that you are running your application with the debugger attached. When you do this, the debugger provides many ways to see what your code is doing while it runs. You can step through your code and look at the values stored in variables, you can set watches on variables to see when values change, you can examine the execution path of your code, see whether a branch of code is running, and so on. If this is the first time that you've tried to debug code, you may want to read Debugging for absolute beginners before going through this article.

Although the demo app is Visual Basic, most of the features are applicable to C#, C++, F#, Python, JavaScript, and other languages supported by Visual Studio (F# does not support Edit-and-continue. F# and JavaScript do not support the Autos window). The screenshots are in Visual Basic.

In this tutorial, you will:

  • Start the debugger and hit breakpoints.
  • Learn commands to step through code in the debugger
  • Inspect variables in data tips and debugger windows
  • Examine the call stack

Prerequisites

Visual Studio Code Visual Basic

You must have Visual Studio 2019 installed and the .NET Core cross-platform development workload.

You must have Visual Studio 2017 installed and the .NET Core cross-platform development workload.

If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

If you need to install the workload but already have Visual Studio, go to Tools > Get Tools and Features.., which opens the Visual Studio Installer. The Visual Studio Installer launches. Choose the .NET Core cross-platform development workload, then choose Modify.

Create a project

First, you'll create a .NET Core console application project. The project type comes with all the template files you'll need, before you've even added anything!

  1. Open Visual Studio 2017.

  2. From the top menu bar, choose File > New > Project.

  3. In the New Project dialog box in the left pane, expand Visual Basic, and then choose .NET Core. In the middle pane, choose Console App (.NET Core). Then name the project get-started-debugging.

    If you don't see the Console App (.NET Core) project template, choose the Open Visual Studio Installer link in the left pane of the New Project dialog box.

    The Visual Studio Installer launches. Choose the .NET Core cross-platform development workload, and then choose Modify.

  1. Open Visual Studio 2019.

    If the start window is not open, choose File > Start Window.

  2. On the start window, choose Create a new project.

  3. On the Create a new project window, enter or type console in the search box. Next, choose Visual Basic from the Language list, and then choose Windows from the Platform list.

    After you apply the language and platform filters, choose the Console App template for .NET Core, and then choose Next.

    Note

    If you do not see the Console App template, you can install it from the Create a new project window. In the Not finding what you're looking for? message, choose the Install more tools and features link. Then, in the Visual Studio Installer, choose the .NET Core cross-platform development workload.

  4. In the Configure your new project window, type or enter get-started-debugging in the Project name box. Then, choose Next.

  5. Choose either the recommended target framework (.NET Core 3.1) or .NET 5, and then choose Create.

    Visual Studio opens your new project.

Create the application

  1. In Program.vb, replace all of the default code with the following code instead:

Visual

Start the debugger!

  1. Press F5 (Debug > Start Debugging) or the Start Debugging button in the Debug Toolbar.

    F5 starts the app with the debugger attached to the app process, but right now we haven't done anything special to examine the code. So the app just loads and you see the console output.

    In this tutorial, we'll take a closer look at this app using the debugger and get a look at the debugger features.

  2. Stop the debugger by pressing the red stop button (Shift + F5).

  3. In the console window, press a key to close the console window.

Set a breakpoint and start the debugger

  1. In the For loop of the Main function, set a breakpoint by clicking the left margin of the following line of code:

    name += letters(i)

    A red circle appears where you set the breakpoint.

    Breakpoints are one of the most basic and essential features of reliable debugging. A breakpoint indicates where Visual Studio should suspend your running code so you can take a look at the values of variables, or the behavior of memory, or whether or not a branch of code is getting run.

  2. Press F5 or the Start Debugging button , the app starts, and the debugger runs to the line of code where you set the breakpoint.

    The yellow arrow represents the statement on which the debugger paused, which also suspends app execution at the same point (this statement has not yet executed).

    If the app is not yet running, F5 starts the debugger and stops at the first breakpoint. Otherwise, F5 continues running the app to the next breakpoint.

    Breakpoints are a useful feature when you know the line of code or the section of code that you want to examine in detail. For information on the different types of breakpoints you can set, such as conditional breakpoints, see Using breakpoints.

Navigate code in the debugger using step commands

Mostly, we use the keyboard shortcuts here, because it's a good way to get fast at executing your app in the debugger (equivalent commands such as menu commands are shown in parentheses).

  1. While paused in the For loop in the Main method, press F11 (or choose Debug > Step Into) twice to to advance to the SendMessage method call.

    After pressing F11 twice, you should be at this line of code:

    SendMessage(name, a(i))

  2. Press F11 one more time to step into the SendMessage method.

    The yellow pointer advances into the SendMessage method.

    F11 is the Step Into command and advances the app execution one statement at a time. F11 is a good way to examine the execution flow in the most detail. (To move faster through code, we show you some other options also.) By default, the debugger skips over non-user code (if you want more details, see Just My Code).

    Let's say that you are done examining the SendMessage method, and you want to get out of the method but stay in the debugger. You can do this using the Step Out command.

  3. Press Shift + F11 (or Debug > Step Out).

    This command resumes app execution (and advances the debugger) until the current method or function returns.

    You should be back in the For loop in the Main method, paused at the SendMessage method call.

  4. Press F11 several times until you get back to the SendMessage method call again.

  5. While paused at the method call, press F10 (or choose Debug > Step Over) once.

    Notice this time that the debugger does not step into the SendMessage method. F10 advances the debugger without stepping into functions or methods in your app code (the code still executes). By pressing F10 on the SendMessage method call (instead of F11), we skipped over the implementation code for SendMessage (which maybe we're not interested in right now). For more information on different ways to move through your code, see Navigate code in the debugger.

Navigate code using Run to Click

  1. Press F5 to advance to the breakpoint again.

  2. In the code editor, scroll down and hover over the Console.WriteLine method in the SendMessage method until the green Run to Click button appears on the left. The tooltip for the button shows 'Run execution to here'.

    Note

    The Run to Click button is new in Visual Studio 2017. (If you don't see the green arrow button, use F11 in this example instead to advance the debugger to the right place.)

  3. Click the Run to Click button .

    The debugger advances to the Console.WriteLine method.

    Using this button is similar to setting a temporary breakpoint. Run to Click is handy for getting around quickly within a visible region of app code (you can click in any open file).

Restart your app quickly

Click the Restart button in the Debug Toolbar (Ctrl + Shift + F5).

When you press Restart, it saves time versus stopping the app and restarting the debugger. The debugger pauses at the first breakpoint that is hit by executing code.

The debugger stops again at the breakpoint you previously set inside the For loop.

Inspect variables with data tips

Features that allow you to inspect variables are one of the most useful features of the debugger, and there are different ways to do it. Often, when you try to debug an issue, you are attempting to find out whether variables are storing the values that you expect them to have at a particular time.

  1. While paused on the name += letters[i] statement, hover over the letters variable and you see it's default value, the value of the first element in the array, 'f'c.

  2. Next, hover over the name variable, and you see its current value, an empty string.

  3. Press F5 (or Debug > Continue) a few times to iterate several times through the For loop, pausing again at the breakpoint, and hovering over the name variable each time to check its value.

    The value of the variable changes with each iteration of the For loop, showing values of f, then fr, then fre, and so on.

    Often, when debugging, you want a quick way to check property values on variables, to see whether they are storing the values that you expect them to store, and the data tips are a good way to do it.

Inspect variables with the Autos and Locals windows

  1. Look at the Autos window at the bottom of the code editor.

    If it is closed, open it while paused in the debugger by choosing Debug > Windows > Autos.

    In the Autos window, you see variables and their current value. The Autos window shows all variables used on the current line or the preceding line (Check documentation for language-specific behavior).

  2. Next, look at the Locals window, in a tab next to the Autos window.

  3. Expand the letters variable to show the elements that it contains.

    The Locals window shows you the variables that are in the current scope, that is, the current execution context.

Set a watch

  1. In the main code editor window, right-click the name variable and choose Add Watch.

    The Watch window opens at the bottom of the code editor. You can use a Watch window to specify a variable (or an expression) that you want to keep an eye on.

    Now, you have a watch set on the name variable, and you can see its value change as you move through the debugger. Unlike the other variable windows, the Watch window always shows the variables that you are watching (they're grayed out when out of scope).

Examine the call stack

  1. While paused in the For loop, click the Call Stack window, which is by default open in the lower right pane.

    If it is closed, open it while paused in the debugger by choosing Debug > Windows > Call Stack.

  2. Click F11 a few times until you see the debugger pause in the SendMessage method. Look at the Call Stack window.

    The Call Stack window shows the order in which methods and functions are getting called. The top line shows the current function (the SendMessage method in this app). The second line shows that SendMessage was called from the Main method, and so on.

    Note

    The Call Stack window is similar to the Debug perspective in some IDEs like Eclipse.

    The call stack is a good way to examine and understand the execution flow of an app.

    You can double-click a line of code to go look at that source code and that also changes the current scope being inspected by the debugger. This action does not advance the debugger.

    You can also use right-click menus from the Call Stack window to do other things. For example, you can insert breakpoints into specified functions, advance the debugger using Run to Cursor, and go examine source code. For more information, see How to: Examine the Call Stack.

Change the execution flow

  1. Press F11 twice to run the Console.WriteLine method.

  2. With the debugger paused in the SendMessage method call, use the mouse to grab the yellow arrow (the execution pointer) on the left and move the yellow arrow up one line, back to Console.WriteLine.

  3. Press F11.

    The debugger reruns the Console.WriteLine method (you see this in the console window output).

    By changing the execution flow, you can do things like test different code execution paths or rerun code without restarting the debugger.

    Warning

    Often you need to be careful with this feature, and you see a warning in the tooltip. You may see other warnings, too. Moving the pointer cannot revert your application to an earlier app state.

  4. Press F5 to continue running the app.

    Congratulations on completing this tutorial!

Next steps

In this tutorial, you've learned how to start the debugger, step through code, and inspect variables. You may want to get a high-level look at debugger features along with links to more information.

Visual Studio Code is an editor first and foremost, and includes the features you need for highly productive source code editing. This topic takes you through the basics of the editor and helps you get moving with your code.

Keyboard shortcuts

Being able to keep your hands on the keyboard when writing code is crucial for high productivity. VS Code has a rich set of default keyboard shortcuts as well as allowing you to customize them.

  • Keyboard Shortcuts Reference - Learn the most commonly used and popular keyboard shortcuts by downloading the reference sheet.
  • Install a Keymap extension - Use the keyboard shortcuts of your old editor (such as Sublime Text, Atom, and Vim) in VS Code by installing a Keymap extension.
  • Customize Keyboard Shortcuts - Change the default keyboard shortcuts to fit your style.

Multiple selections (multi-cursor)

VS Code supports multiple cursors for fast simultaneous edits. You can add secondary cursors (rendered thinner) with Alt+Click. Each cursor operates independently based on the context it sits in. A common way to add more cursors is with ⌥⌘↓ (Windows Ctrl+Alt+Down, Linux Shift+Alt+Down) or ⌥⌘↑ (Windows Ctrl+Alt+Up, Linux Shift+Alt+Up) that insert cursors below or above.

Note: Your graphics card driver (for example NVIDIA) might overwrite these default shortcuts.

⌘D (Windows, Linux Ctrl+D) selects the word at the cursor, or the next occurrence of the current selection.

Tip: You can also add more cursors with ⇧⌘L (Windows, Linux Ctrl+Shift+L), which will add a selection at each occurrence of the current selected text.

Multi-cursor modifier

If you'd like to change the modifier key for applying multiple cursors to Cmd+Click on macOS and Ctrl+Click on Windows and Linux, you can do so with the editor.multiCursorModifiersetting. This lets users coming from other editors such as Sublime Text or Atom continue to use the keyboard modifier they are familiar with.

Visual

The setting can be set to:

  • ctrlCmd - Maps to Ctrl on Windows and Cmd on macOS.
  • alt - The existing default Alt.

There's also a menu item Use Ctrl+Click for Multi-Cursor in the Selection menu to quickly toggle this setting.

The Go To Definition and Open Link gestures will also respect this setting and adapt such that they do not conflict. For example, when the setting is ctrlCmd, multiple cursors can be added with Ctrl/Cmd+Click, and opening links or going to definition can be invoked with Alt+Click.

Shrink/expand selection

Quickly shrink or expand the current selection. Trigger it with ⌃⇧⌘← (Windows, Linux Shift+Alt+Left) and ⌃⇧⌘→ (Windows, Linux Shift+Alt+Right).

Here's an example of expanding the selection with ⌃⇧⌘→ (Windows, Linux Shift+Alt+Right):

Column (box) selection

Place the cursor in one corner and then hold Shift+Alt while dragging to the opposite corner:

Note: This changes to Shift+Ctrl/Cmd when using Ctrl/Cmd as multi-cursor modifier.

There are also default key bindings for column selection on macOS and Windows, but not on Linux.

KeyCommandCommand ID
⇧⌥⌘↓ (Windows Ctrl+Shift+Alt+Down, Linux )Column Select DowncursorColumnSelectDown
⇧⌥⌘↑ (Windows Ctrl+Shift+Alt+Up, Linux )Column Select UpcursorColumnSelectUp
⇧⌥⌘← (Windows Ctrl+Shift+Alt+Left, Linux )Column Select LeftcursorColumnSelectLeft
⇧⌥⌘→ (Windows Ctrl+Shift+Alt+Right, Linux )Column Select RightcursorColumnSelectRight
⇧⌥⌘PageDown (Windows Ctrl+Shift+Alt+PageDown, Linux )Column Select Page DowncursorColumnSelectPageDown
⇧⌥⌘PageUp (Windows Ctrl+Shift+Alt+PageUp, Linux )Column Select Page UpcursorColumnSelectPageUp

You can edit your keybindings.json to bind them to something more familiar if you wish.

Column Selection mode

The user setting Editor: Column Selection controls this feature. Once this mode is entered, as indicated in the Status bar, the mouse gestures and the arrow keys will create a column selection by default. This global toggle is also accessible via the Selection > Column Selection Mode menu item. In addition, one can also disable Column Selection mode from the Status bar.

Save / Auto Save

By default, VS Code requires an explicit action to save your changes to disk, ⌘S (Windows, Linux Ctrl+S).

However, it's easy to turn on Auto Save, which will save your changes after a configured delay or when focus leaves the editor. With this option turned on, there is no need to explicitly save the file. The easiest way to turn on Auto Save is with the File > Auto Save toggle that turns on and off save after a delay.

For more control over Auto Save, open User or Workspace settings and find the associated settings:

  • files.autoSave: Can have the values:
    • off - to disable auto save.
    • afterDelay - to save files after a configured delay (default 1000 ms).
    • onFocusChange - to save files when focus moves out of the editor of the dirty file.
    • onWindowChange - to save files when the focus moves out of the VS Code window.
  • files.autoSaveDelay: Configures the delay in milliseconds when files.autoSave is configured to afterDelay. The default is 1000 ms.

Hot Exit

VS Code will remember unsaved changes to files when you exit by default. Hot exit is triggered when the application is closed via File > Exit (Code > Quit on macOS) or when the last window is closed.

You can configure hot exit by setting files.hotExit to the following values:

  • 'off': Disable hot exit.
  • 'onExit': Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when the workbench.action.quit command is triggered (from the Command Palette, keyboard shortcut or menu). All windows without folders opened will be restored upon next launch.
  • 'onExitAndWindowClose': Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when the workbench.action.quit command is triggered (from the Command Palette, keyboard shortcut or menu), and also for any window with a folder opened regardless of whether it is the last window. All windows without folders opened will be restored upon next launch. To restore folder windows as they were before shutdown, set window.restoreWindows to all.

If something happens to go wrong with hot exit, all backups are stored in the following folders for standard install locations:

  • Windows%APPDATA%CodeBackups
  • macOS$HOME/Library/Application Support/Code/Backups
  • Linux$HOME/.config/Code/Backups

Find and Replace

VS Code allows you to quickly find text and replace in the currently opened file. Press ⌘F (Windows, Linux Ctrl+F) to open the Find Widget in the editor, search results will be highlighted in the editor, overview ruler and minimap.

If there are more than one matched result in the current opened file, you can press Enter and ⇧Enter (Windows, Linux Shift+Enter) to navigate to next or previous result when the find input box is focused.

Seed Search String From Selection

When the Find Widget is opened, it will automatically populate the selected text in the editor into the find input box. If the selection is empty, the word under the cursor will be inserted into the input box instead.

This feature can be turned off by setting editor.find.seedSearchStringFromSelection to false.

Find In Selection

By default, the find operations are run on the entire file in the editor. It can also be run on selected text. You can turn this feature on by clicking the hamburger icon on the Find Widget.

If you want it to be the default behavior of the Find Widget, you can set editor.find.autoFindInSelection to always, or to multiline, if you want it to be run on selected text only when multiple lines of content are selected.

Advanced find and replace options

BasicBasic

In addition to find and replace with plain text, the Find Widget also has three advanced search options:

  • Match Case
  • Match Whole Word
  • Regular Expression

The replace input box support case preserving, you can turn it on by clicking the Preserve Case (AB) button.

Multiline support and Find Widget resizing

You can search multiple line text by pasting the text into the Find input box and Replace input box. Pressing Ctrl+Enter inserts a new line in the input box.

While searching long text, the default size of Find Widget might be too small. You can drag the left sash to enlarge the Find Widget or double click the left sash to maximize it or shrink it to its default size.

Search across files

VS Code allows you to quickly search over all files in the currently opened folder. Press ⇧⌘F (Windows, Linux Ctrl+Shift+F) and enter your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location. Expand a file to see a preview of all of the hits within that file. Then single-click on one of the hits to view it in the editor.

Tip: We support regular expression searching in the search box, too.

You can configure advanced search options by clicking the ellipsis (Toggle Search Details) below the search box on the right (or press ⇧⌘J (Windows, Linux Ctrl+Shift+J)). This will show additional fields to configure the search.

Advanced search options

In the two input boxes below the search box, you can enter patterns to include or exclude from the search. If you enter example, that will match every folder and file named example in the workspace. If you enter ./example, that will match the folder example/ at the top level of your workspace. Use , to separate multiple patterns. Paths must use forward slashes. You can also use glob syntax:

  • * to match one or more characters in a path segment
  • ? to match on one character in a path segment
  • ** to match any number of path segments, including none
  • {} to group conditions (for example {**/*.html,**/*.txt} matches all HTML and text files)
  • [] to declare a range of characters to match (example.[0-9] to match on example.0, example.1, …)

VS Code excludes some folders by default to reduce the number of search results that you are not interested in (for example: node_modules). Open settings to change these rules under the files.exclude and search.exclude section.

Note that glob patterns in the search view work differently than in settings such as files.exclude and search.exclude. In the settings, you must use **/example to match a folder named example in subfolder folder1/example in your workspace. In the search view, the ** prefix is assumed.

Also note the Use Exclude Settings and Ignore Files toggle button in the files to exclude box. The toggle determines whether to exclude files that are ignored by your .gitignore files and/or matched by your files.exclude and search.exclude settings.

Tip: From the Explorer, you can right-click on a folder and select Find in Folder to search inside a folder only.

Search and replace

You can also Search and Replace across files. Expand the Search widget to display the Replace text box.

When you type text into the Replace text box, you will see a diff display of the pending changes. You can replace across all files from the Replace text box, replace all in one file or replace a single change.

Tip: You can quickly reuse a previous search term by using (Windows, Linux Down) and (Windows, Linux Up) to navigate through your search term history.

IntelliSense

Visual Studio Code Tutorial

We'll always offer word completion, but for the rich languages, such as JavaScript, JSON, HTML, CSS, SCSS, Less, C# and TypeScript, we offer a true IntelliSense experience. If a language service knows possible completions, the IntelliSense suggestions will pop up as you type. You can always manually trigger it with ⌃Space (Windows, Linux Ctrl+Space). By default, Tab or Enter are the accept keyboard triggers but you can also customize these key bindings.

Tip: The suggestions filtering supports CamelCase so you can type the letters which are upper cased in a method name to limit the suggestions. For example, 'cra' will quickly bring up 'createApplication'.

Tip: IntelliSense suggestions can be configured via the editor.quickSuggestions and editor.suggestOnTriggerCharacterssettings.

Isotopes of the same element have identical. JavaScript and TypeScript developers can take advantage of the npmjs type declaration (typings) file repository to get IntelliSense for common JavaScript libraries (Node.js, React, Angular). You can find a good explanation on using type declaration files in the JavaScript language topic and the Node.js tutorial.

Learn more in the IntelliSense document.

Formatting

VS Code has great support for source code formatting. The editor has two explicit format actions:

  • Format Document (⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I)) - Format the entire active file.
  • Format Selection (⌘K ⌘F (Windows, Linux Ctrl+K Ctrl+F)) - Format the selected text.

You can invoke these from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) or the editor context menu.

VS Code has default formatters for JavaScript, TypeScript, JSON, and HTML. Each language has specific formatting options (for example, html.format.indentInnerHtml) which you can tune to your preference in your user or workspace settings. You can also disable the default language formatter if you have another extension installed that provides formatting for the same language.

Along with manually invoking code formatting, you can also trigger formatting based on user gestures such as typing, saving or pasting. These are off by default but you can enable these behaviors through the following settings:

  • editor.formatOnType - Format the line after typing.
  • editor.formatOnSave - Format a file on save.
  • editor.formatOnPaste - Format the pasted content.

Note: Not all formatters support format on paste as to do so they must support formatting a selection or range of text.

In addition to the default formatters, you can find extensions on the Marketplace to support other languages or formatting tools. There is a Formatters category so you can easily search and find formatting extensions. In the Extensions view search box, type 'formatters' or 'category:formatters' to see a filtered list of extensions within VS Code.

Folding

You can fold regions of source code using the folding icons on the gutter between line numbers and line start. Move the mouse over the gutter and click to fold and unfold regions. Use Shift + Click on the folding icon to fold or unfold the region and all regions inside.

You can also use the following actions:

  • Fold (⌥⌘[ (Windows, Linux Ctrl+Shift+[)) folds the innermost uncollapsed region at the cursor.
  • Unfold (⌥⌘] (Windows, Linux Ctrl+Shift+])) unfolds the collapsed region at the cursor.
  • Toggle Fold (⌘K ⌘L (Windows, Linux Ctrl+K Ctrl+L)) folds or unfolds the region at the cursor.
  • Fold Recursively (⌘K ⌘[ (Windows, Linux Ctrl+K Ctrl+[)) folds the innermost uncollapsed region at the cursor and all regions inside that region.
  • Unfold Recursively (⌘K ⌘] (Windows, Linux Ctrl+K Ctrl+])) unfolds the region at the cursor and all regions inside that region.
  • Fold All (⌘K ⌘0 (Windows, Linux Ctrl+K Ctrl+0)) folds all regions in the editor.
  • Unfold All (⌘K ⌘J (Windows, Linux Ctrl+K Ctrl+J)) unfolds all regions in the editor.
  • Fold Level X (⌘K ⌘2 (Windows, Linux Ctrl+K Ctrl+2) for level 2) folds all regions of level X, except the region at the current cursor position.
  • Fold All Block Comments (⌘K ⌘/ (Windows, Linux Ctrl+K Ctrl+/)) folds all regions that start with a block comment token.

Folding regions are by default evaluated based on the indentation of lines. A folding region starts when a line has a smaller indent than one or more following lines, and ends when there is a line with the same or smaller indent.

Since the 1.22 release, folding regions can also be computed based on syntax tokens of the editor's configured language. The following languages already provide syntax aware folding: Markdown, HTML, CSS, LESS, SCSS, and JSON.

If you prefer to switch back to indentation-based folding for one (or all) of the languages above, use:

Regions can also be defined by markers defined by each language. The following languages currently have markers defined:

LanguageStart regionEnd region
Bat::#region or REM #region::#endregion or REM #endregion
C##region#endregion
C/C++#pragma region#pragma endregion
CSS/Less/SCSS/*#region*//*#endregion*/
Coffeescript#region#endregion
F#//#region or (#_region)//#endregion or (#_endregion)
Java//#region or //<editor-fold>// #endregion or //</editor-fold>
Markdown<!-- #region --><!-- #endregion -->
Perl5#region or =pod#endregion or =cut
PHP#region#endregion
PowerShell#region#endregion
Python#region or # region#endregion or # endregion
TypeScript/JavaScript//#region//#endregion
Visual Basic#Region#End Region

To fold and unfold only the regions defined by markers use:

  • Fold Marker Regions (⌘K ⌘8 (Windows, Linux Ctrl+K Ctrl+8)) folds all marker regions.
  • Unfold Marker Regions (⌘K ⌘9 (Windows, Linux Ctrl+K Ctrl+9)) unfolds all marker regions.

Indentation

VS Code lets you control text indentation and whether you'd like to use spaces or tab stops. By default, VS Code inserts spaces and uses 4 spaces per Tab key. If you'd like to use another default, you can modify the editor.insertSpaces and editor.tabSizesettings.

Auto-detection

VS Code analyzes your open file and determines the indentation used in the document. The auto-detected indentation overrides your default indentation settings. The detected setting is displayed on the right side of the Status Bar:

You can click on the Status Bar indentation display to bring up a dropdown with indentation commands allowing you to change the default settings for the open file or convert between tab stops and spaces.

Note: VS Code auto-detection checks for indentations of 2, 4, 6 or 8 spaces. If your file uses a different number of spaces, the indentation may not be correctly detected. For example, if your convention is to indent with 3 spaces, you may want to turn off editor.detectIndentation and explicitly set the tab size to 3.

File encoding support

Set the file encoding globally or per workspace by using the files.encoding setting in User Settings or Workspace Settings.

You can view the file encoding in the status bar.

Click on the encoding button in the status bar to reopen or save the active file with a different encoding.

Visual Studio Code Visual Basic In Excel

Then choose an encoding.

Next steps

Visual Studio Code Visual Basic Debugger

You've covered the basic user interface - there is a lot more to VS Code. Read on to find out about:

  • Intro Video - Setup and Basics - Watch a tutorial on the basics of VS Code.
  • User/Workspace Settings - Learn how to configure VS Code to your preferences through user and workspace settings.
  • Code Navigation - Peek and Goto Definition, and more.
  • Integrated Terminal - Learn about the integrated terminal for quickly performing command-line tasks from within VS Code.
  • IntelliSense - VS Code brings smart code completions.
  • Debugging - This is where VS Code really shines.

Common questions

Is it possible to globally search and replace?

Yes, expand the Search view text box to include a replace text field. You can search and replace across all the files in your workspace. Note that if you did not open VS Code on a folder, the search will only run on the currently open files.

How do I turn on word wrap?

You can control word wrap through the editor.wordWrapsetting. By default, editor.wordWrap is off but if you set to it to on, text will wrap on the editor's viewport width.

You can toggle word wrap for the VS Code session with ⌥Z (Windows, Linux Alt+Z).

Visual Studio Code Visual Basic Tutorial

You can also add vertical column rulers to the editor with the editor.rulers setting, which takes an array of column character positions where you'd like vertical rulers.