vscode: Can no longer edit SVG

Type: Bug

Since updating to 1.97.0 I can no longer edit SVG. I can only view them. Ideally it would be nice to be able to quickly toggle between looking at SVG markup and looking at the SVG as an image. If I am only able to do one of those things, I would certainly choose the old behaviour of being able to edit the SVG code.

Most frontend devs will need to edit SVG code at some point. It’s no longer clear how to do that. Is it even possible anymore, or has it been completely broken with this release?

VS Code version: Code 1.97.0 (Universal) (33fc5a94a3f99ebe7087e8fe79fbe1d37a251016, 2025-02-04T22:41:26.688Z) OS version: Darwin arm64 24.3.0 Modes:

System Info
Item Value
CPUs Apple M2 Pro (10 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 1, 1, 2
Memory (System) 16.00GB (0.47GB free)
Process Argv –crash-reporter-id 440b0248-fa26-429c-ac2f-55ed0571e43a
Screen Reader no
VM 0%
Extensions (15)
Extension Author (truncated) Version
astro-vscode ast 2.15.4
es6-string-css bas 0.1.0
lit-html bie 1.11.1
vscode-tailwindcss bra 0.14.3
vscode-markdownlint Dav 0.58.2
vscode-eslint dba 3.0.10
EditorConfig Edi 0.16.7
prettier-vscode esb 11.0.0
rainbow-csv mec 3.16.0
live-server ms- 0.4.15
language-liquid nei 0.1.1
vscode-thunder-client ran 2.34.0
lit-plugin run 1.4.3
code-spell-checker str 4.0.34
vscode-mdx uni 1.8.13
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
nativerepl1:31139838
pythonrstrctxt:31112756
nativeloc2:31192216
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
dwoutputs:31217127
9064b325:31222308
copilot_t_ci:31222730

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 133
  • Comments: 28 (4 by maintainers)

Most upvoted comments

  • Right click on the file in the explorer to open the context menu
  • Open with...
  • Select Text Editor

Image

Hope that helps.

Yes, can we re-open this issue? I couldn’t figure this out until I found this thread.

I agree with @jantimon, the default behavior should show the source code and have the “Open Preview to the Side” button visible like it does in Markdown files.

Could this feature work like the markdown preview?

Reopen editor with works for switching a single editor. If you want svgs to open as text by default:

  1. Run reopen editor with the svg open
  2. Select configure default editor for *.svg
  3. Select text editor

Now any future svg files will open using the default text editor

Yep, this definitely needs to be fixed.

This is a code editor, not a photo library, and right now, it is not at all obvious how to edit the code, which is often needed. I’d argue the behavior of this should be identical to that of Markdown files, as both are, in the context of an editor, primarily code. I don’t see any valid arguments for having any difference in behavior between those two file types.

The experience for both file types could be improved though - for example, it might make sense to replace the preview icon with a toggle that switches between editor, preview, and split view, with the most recent view being remembered, when selecting another file of the same type.

There’s a solution to bring back default setting to what it was since this feature (No one requested) was added in this latest version. Add this to your settings.json

"workbench.editorAssociations": { "*.svg": "default" }

This change needs to be rolled back immediately - it’s not just an annoyance, it’s actually broken.

In the Source control panel, how are we supposed to Open changes for an SVG file now? It shows the previews side by side, but I can’t find any way to view the code changes.

Should this default to a split editor, code on the left, preview on the right ?

Why vsCode gets worse and worse instead of getting better? Is it too much to ask not to break things and not make the UX worse?

It was hard for me to find the right click option, just paste this to your vsCode config.

{
    "workbench.editorAssociations": {
        "*.svg": "default"
    }
}

The current behavior doesn’t make any sense for a tool like vsCode.

Yeah, this is a bug, there’s no two ways about it. Visual should only be optional for a code editor, not the exclusive default(!!). Obviously. Especially since you can’t even edit the visual with visual tools. … You literally just made VS Code worse for editing SVG code than Inkscape, a grafics tool. 🤣 And that is funny, in a weird way.

Anyway, please fix this. It’s quite very strange to install a seperate editor, just to edit SVG code. Not that there’s a lack of editors out there, but still.

Other than that, keep up with the good work, I really like this project and VS code is my go-to editor for little stuff on the side, like cleaning up SVGs and such 😉. Thanks to the team for all the awesomeness. … I think this is the very first bug report I’m writing and I’m a professional day one user. That’s pretty darn impressive.

I’ve noticed that in new version there is toggle button that let you switch between preview and code.

Image

@KinastPR Clearly you did not read, you don’t need to install anything, just need to switch to the code editor. Also VS code never supported visual editing of SVG, and never will as VS Code is a code editor, not an image editor

@mrleblanc101 I don’t understand your fix. … What do you mean by “run reopen editor”, “configure default editor for *.svg” and “Select text editor”? … I sure hope you’re not assuming a specific OS as peoples VS Code environment without expressing that, no?


You’re user-end quickfix aside (thanks for trying to help btw.!), this is factually a bug. Opening an SVG in pure visual preview might be justifiable if usage statistics indicate that 95% percent of users just prefer to look at SVG visuals in VS Code - which, to be honest, would really surprise me and be a strange notion of how to use a code editor - … but completely omitting any accessible way to switch to code or dual-view is a flat-out bug that needs to be fixed.

A neat and sensible default with bells and whistles would be to open SVGs in code and visual preview side-by-side, just like those markdown extentions do / offer as option. This issue is a total no-brainer and shouldn’t take more that a few minor code updates and/or reverts for the maintainer of SVG handling.

As a workaround, if I follow the steps here to default to the Text Editor for SVG file, it allows the SVG Preview extension to work properly.

Reopen editor with works for switching a single editor. If you want svgs to open as text by default:

  1. Run reopen editor with the svg open
  2. Select configure default editor for *.svg
  3. Select text editor

Now any future svg files will open using the default text editor

It restore the previous behavior, which is to open a split editor with the code on the left and the preview on the right. But this is not supported natively as of yet, it would make for a nice enhancement.

Image

Ye, same problem here. My monkey brain can’t handle that I now need to reopen the editor to switch between editing and previewing. Please enable side-by-side editing and previewing again 🙏. I totally agree with the title of #239844

Thank you for pointing out the toggle button but I think the option should be in the context menu as well.

Just got caught by this feature and the tiny button in the top right corner was not obvious. My resolution is 2K and my opened tab was on the left side of the screen so the button was not really even in my field of vision. Additionally, I was expecting VS Code to open the file as code or at least some way to exit preview mode when viewing the image. Copy is the only option in the context menu and “Reopen Editor With…” is not something I would associate with trying to exit preview mode for SVGs. I already have the svg open, I don’t need to open it as something else.

  1. Find an SVG file and right-click it
  2. In the drop-down menu select open with
  3. Image
  4. According to the displaced small menu at the top of vs code, you can look at the end of the list " Configure default editor for *.svg…" and click it.
  5. The option will disappear.
  6. Image
  7. Then choose from the remaining 2 options. What should your preferred display option be for SVG?

There’s a solution to bring back default setting to what it was since this feature (No one requested) was added in this latest version. Add this to your settings.json

"workbench.editorAssociations": { "*.svg": "default" }

Thanks @Warface! This was the solution that worked for me.

  • Can’t open svgs as text from the search tab.
  • Compare active file with .../Saved/Clipboard is also broken even when the svg is opened as text.

@remcohaszing

I’ve already gave this solution.

This works great: https://github.com/microsoft/vscode/issues/239834#issuecomment-2642160152

But for those who prefer copy-pasting, it just adds the following to your settings.json:

{
  "workbench.editorAssociations": {
    "*.svg": "default"
  }
}

+1

Should this default to a split editor, code on the left, preview on the right ?

This could actually be quite cool, I’d love to be able to edit SVG code in real time.

But yes, please undo this change.

my solution:

  "svgPreview.autoOpen": true,
  "svgPreview.style": {
    "html": {
      "background-position": "0 0, 13px 13px",
      "background-size": "26px 26px",
      "background-image": "linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff), linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff)",
      "background-color": "#ccc"
    },
  },

https://marketplace.visualstudio.com/items?itemName=SimonSiefke.svg-preview&ssr=false#review-details

@KinastPR Clearly you did not read, you don’t need to install anything, just need to switch to the code editor. Also VS code never supported visual editing of SVG, and never will as VS Code is a code editor, not an image editor

@stephen-ullom It indeed is not possible currently, but that wasn’t a necessity before because all the previewable file type were blob (jpg, png, video, etc), not code. I guess you could argue some people might want to open those blob in the HEX editor, but that was a small edge case. It’s not an edge case anymore with SVG, manually editing the code of an SVG is a very common use case.

I do agree @mrleblanc101. I personally edit SVG files often. I’m just stating that it would require more work. It would also be nice to have more options than zoom in or zoom out like a 100% or fit option. I’m not sure how much should be implemented natively vs being provided in an extension though. I suppose that’s up to the official maintainers.

@stephen-ullom It indeed is not possible currently, but that wasn’t a necessity before because all the previewable file type were blob (jpg, png, video, etc), not code. I guess you could argue some people might want to open those blob in the HEX editor, but that was a small edge case. It’s not an edge case anymore with SVG, manually editing the code of an SVG is a very common use case.