如何设置 Microsoft Visual Studio:代码作为默认编辑器?

Rya*_*yan 12 command-line microsoft

Microsoft Visual Studio Code 是一个非常好的编辑器,我想将它设为我默认的普通(非终端)文本编辑器,而不是 Gedit、Emacs 或 Vim。(我知道,我太邪恶了。)

我无法通过 GUI 选项添加它,我查看了一些在线建议,但所有这些建议都已经过时或无用。

你们有什么建议吗?我将采用终端解决方案,但如果你们有一个 GUI 解决方案,那也行。

小智 13

来自 Microsoft VSCode 的文档

将 VS Code 设置为默认文本编辑器

xdg-open
Run Code Online (Sandbox Code Playgroud)

您可以使用以下命令为 xdg-open 使用的文本文件(text/plain)设置默认文本编辑器:

xdg-mime default code.desktop text/plain
Run Code Online (Sandbox Code Playgroud)

Debian 替代系统

基于 Debian 的发行版允许使用替代系统设置默认编辑器,而无需考虑 mime 类型。您可以通过运行以下命令并选择代码来设置它。

sudo update-alternatives --set editor /usr/bin/code
Run Code Online (Sandbox Code Playgroud)

此外,还有以下提到的问题

Some need you to set the default for a mime type like:

~/.local/share/applications/defaults.list

[Default Applications]
text/plain=code-insiders.desktop
Which adds Open With Visual Studio Code - Insiders (Ctrl+O) to the nautilus context menu.
Run Code Online (Sandbox Code Playgroud)


小智 6

这两个对我有用:

  1. 使用 xdg-utils:
xdg-mime default code.desktop text/plain
Run Code Online (Sandbox Code Playgroud)
  1. 在这个文件中:
/usr/share/applications/defaults.list
Run Code Online (Sandbox Code Playgroud)

替换这一行:

text/plain=gedit.desktop
Run Code Online (Sandbox Code Playgroud)

和:

text/plain=code.desktop
Run Code Online (Sandbox Code Playgroud)

注意:update-alternatives仅影响非图形环境(终端)