Markdown and Visual Studio Code
Working with Markdown files in Visual Studio Code is simple, straightforward, and fun. Besides VS Code's basic editing, there are a several Markdown-specific features that help you be more productive.
Note: To help get you started with editing Markdown files, you can use the Doc Writer profile template to install useful extensions (spell checker, Markdown linter) and configure appropriate setting values.
Editing Markdown
Document outline
The Outline view is a separate section in the bottom of the File Explorer. When expanded, it shows the symbol tree of the currently active editor. For Markdown files, the symbol tree is the Markdown file's header hierarchy.
The Outline view is a great way to review your document's header structure and outline.
Snippets for Markdown
VS Code includes some useful snippets that can speed up writing Markdown. This includes snippets for code blocks, images, and more. Press Ctrl+Space
(Trigger Suggest) while editing to see a list of suggested Markdown snippets. You can also use the dedicated snippet picker by selecting Insert Snippet in the Command Palette.
Tip: You can add in your own User Defined Snippets for Markdown. Take a look at User Defined Snippets to find out how.
Go to header in file
Use kb(workbench.action.gotoSymbol)
to quickly jump to a header in the current file.
You can browse through all headers in the file or start typing a header name to find just the one you are after. Once you've found the header you what, press Enter
to move your cursor to it. Press Esc
to cancel jumping to the header.
Go to header in workspace
Use kb(workbench.action.showAllSymbols)
to search through headers across all Markdown files in the current workspace.
Start typing a header name to filter down the list and find the header you are after.
Path completions
Path completions help with create links to files and images. These paths are shown automatically by IntelliSense as you type the path of an image or link, and can also be manually requested by using Ctrl+Space
.
Paths starting with /
are resolved relative to the current workspace root, while paths staring with ./
or without any prefix are resolved relative to the current file. Path suggestions are automatically shown when you type /
or can be manually invoked by using Ctrl+Space
.
Path IntelliSense can also help you link to headers within the current file or within another Markdown file. Start the path with #
to see completions for all the headers in the file (depending on your settings, you might need to use Ctrl+Space
to see these):
You can disable path IntelliSense with "markdown.suggest.paths.enabled": false
.
Creating links to a header in another file
Need to link to a header in another Markdown document but don't remember or want to type out the full file path? Try using workspace header completions! To start, just type ##
in a Markdown link to see a list of all Markdown headers from the current workspace:
Accept one of these completions to insert the full link to that header, even if it's in another file:
You can configure if/when workspace header completions show with the markdown.suggest.paths.includeWorkspaceHeaderCompletions
setting. Valid setting values are:
onDoubleHash
(the default)—Show workspace header completions only after you type##
.onSingleOrDoubleHash
—Show workspace header completions after you type#
or##
.never
—Never show workspace header completions.
Keep in mind that finding all headers in the current workspace can be expensive, so there might be a slight delay the first time they are requested, especially for workspaces with lots of Markdown files.
Inserting images and links to files
In addition to path completion, VS Code also supports a few other ways to insert images and file links into your Markdown documents:
You can Drag and drop a file from VS Code's Explorer or from your operating system into a Markdown editor. Start by dragging a file from VS Code's Explorer over your Markdown code and then hold down Shift
to start dropping it into the file. The preview cursor shows where it will be inserted when you drop it.
If you prefer using the keyboard, you can also Copy and paste a file or image data into a Markdown editor. When you paste a file, a link to a file, or a URL, you can choose to insert a Markdown link or to include the link as plain text.
Or you can use the Markdown: Insert Image from Workspace command to insert images and Markdown: Insert Link to File in Workspace to insert file links.
Inserted images use Markdown image syntax 
. Links insert a normal Markdown link [](path/to/file.md)
.
By default VS Code automatically copies dropped or pasted images outside of the workspace into your workspace. The markdown.copyFiles.destination
setting controls where the new image file should be created. This setting maps globs that match on the current Markdown document to image destinations. The image destinations can also use some simple variables. See the markdown.copyFiles.destination
setting description for information about the available variables.
For example, if you want every Markdown file under /docs
in your workspace to put new media files into an images
directory specific to the current file, you can write:
"markdown.copyFiles.destination": {
"/docs/**/*": "images/${documentBaseName}/"
}
Now when a new file is pasted in /docs/api/readme.md
, the image file is created at /docs/api/images/readme/image.png
.
You can even use simple regular expressions to transform variables in a similar way to snippets. For example, this transform uses only the first letter of the document file name when creating the media file:
"markdown.copyFiles.destination": {
"/docs/**/*": "images/${documentBaseName/(.).*/$1/}/"
}
When a new file is pasted into /docs/api/readme.md
, the image is now created under /docs/api/images/r/image.png
.