VSCode Copy Relative Path with posix forward slashes
Asked Answered
S

2

46

VSC newbie here.

I'm trying to right-click on my projects' files and selecting Copy Relative Path, the thing is I get the path like this: node_modules\bootstrap\dist\css\bootstrap.min.css

when what I actually need is this: node_modules/bootstrap/dist/css/bootstrap.min.css

Where can I change these settings to avoid the manual editing, It's really time consuming.

Thanks for your help.

Stays answered 15/9, 2020 at 21:44 Comment(0)
I
68

As of vscode 1.59 you can enable using the / separator even on Windows for the Copy Relative Path command.

Explorer: Copy Relative Path Separator set to /.

explorer.copyRelativePathSeparator

  • auto (default): Uses operating system specific path separation character
  • /: Use slash as path separation character
  • \\: Use backslash as path separation character

See https://github.com/microsoft/vscode/issues/56279

enter image description here


For the same ability to designate the path separator for the copy full path (tab context menu: Copy Path) command, there is an issue with a PR awaiting resolution: Allow to configure the which slash is used when copying a path.

Iceskate answered 14/7, 2021 at 20:16 Comment(1)
Perfect, this made my day. Absolutely essential if you are using the (Git) Bash terminal on Windows VSCode. For instance if you want to do a git diff main -- my/foo/bar/relative/path whereas the default (auto) behavior will barf on git diff main -- my\foo\bar\relative\pathWeekender
M
1

I think it's because you used Windows, which uses \ instead of / in paths. I suggest using raw strings in the path. For example: r'node_modules\bootstrap\dist\css\bootstrap.min.css'.

Another way to change all the \ to / is by using the replace function in vscode!

Merrill answered 16/9, 2020 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.