vscode://file/full/path/to/directory/ vscode://file/full/path/to/file vscode://file/full/path/to/directory/?windowId=_blank vscode://file/full/path/to/file?windowId=_blank
vscode
URLsYou can launch
Visual Studio Code
with
a
vscode://
URL
like
any
of
the following:
vscode://file/full/path/to/directory/ vscode://file/full/path/to/file vscode://file/full/path/to/directory/?windowId=_blank vscode://file/full/path/to/file?windowId=_blank
To learn about
vscode://
URLs, see
code.visualstudio.com’s
Opening VS Code with URLs.
To learn about
the
query parameter
?windowId=_blank
,
see
github.com/microsoft/vscode/issues/141548.
💡 | The string
before the colon,
|
Inspired by the March-2023 discourse.gohugo.io discussion titled Open content files via link in vscode from server-mode preview, I created the following Hugo partial that I use when I’m developing the Infinite Ink website.
{{- /*
* CREATED: 2023-May
* PATH: layouts/partials/open-with/vscode.html
* USAGE: {{ partial "open-with/vscode" . }}
*/ -}}
{{- with .File -}}
{{- $filepath := .Filename -}}
{{- $dirpath := print hugo.WorkingDir "/content/" .Dir -}}
{{- $sectionpath := print hugo.WorkingDir "/content/" .Section -}}
<pre>
<small>
<a href="vscode://file/{{- $filepath -}}?windowId=_blank">Edit File</a>
<b><a href="vscode://file/{{- $dirpath -}}?windowId=_blank">Edit Dir</a></b>
<a href="vscode://file/{{- $sectionpath -}}?windowId=_blank">Edit Section</a>
</small>
</pre>
{{- end -}} <!-- END with .File -->
When I’m running
Hugo
in server mode
(via hugo server
),[2]
this partial displays the following
three
links
on each
Infinite Ink
web
page.
Edit File Edit Dir Edit Section
💡 |
|
Because I do not want
these Edit
links
displayed
when I publish
the
Infinite Ink website,
I call this partial
in
my
Hugo
base template
with the following
Go template code.[4]
{{- if not hugo.IsProduction -}}
{{- partial "open-with/vscode" . -}}
{{- end -}}
💡 | Alternatives to the above condition are: {{- if eq hugo.Environment "development" -}} {{- if hugo.IsDevelopment -}} To learn about
|
To make it easy to edit the partial itself, I include the following near the bottom of the partial.
{{- $thispartialdir := path.Join hugo.WorkingDir "layouts/partials/open-with/" -}} <a href="vscode://file/{{- $thispartialdir -}}?windowId=_blank">Edit this open-with partial</a>
With this, the partial displays the following four links on each Infinite Ink page.
Edit File Edit Dir Edit Section Edit this open-with partial
To learn about the path.Join
function
that’s used in this section,
see gohugo.io/functions/path.join/.
To learn more about all this, see the following links.
discourse.gohugo.io/t/open-content-files-via-link-in-vscode-from-server-mode-preview/43669
gohugo.io/variables/files/
(discusses
.File.Filename
and
.File.Dir
)
gohugo.io/functions/hugo/
(discusses
hugo.Environment
,
hugo.IsDevelopment
,
hugo.IsProduction
,
and
hugo.WorkingDir
)
For more about Hugo, see Infinite Ink’s…
Variable and Parameter Names in Hugo (featuring camelCase🐫 and snake_case🐍)
Compare Hugo’s Markup Languages (featuring a renderas
shortcode)⚖️
Transforming Text with Hugo (featuring plainify
, htmlUnescape
, and more)
🔗 Linkified Section Headings in Hugo-Generated Web Pages (featuring Markdown and AsciiDoc examples)
TGIH: Themeless & Gitless Introduction to the Hugo SSG (a Hugo tutorial👩🏫)
Hugo’s .RenderString
Method (featuring AsciiDoc admonitions in Markdown)
Calling a Hugo Partial from a Hugo Shortcode (featuring “Share on Mastodon” code)
?windowId=_blank
to the vscode://
URL. To learn about this query parameter, see github.com/microsoft/vscode/issues/141548.@nm@mathstodon.xyz
or
#InfiniteInk
in it.