如何更改所有类型的基于文本的文件的默认文本编辑器,无论扩展名是什么?
How to change default text editor for all kind of text-based files, no matter what extension is?
我知道 Finder 具有更改默认应用程序的内置选项,但这仅适用于该扩展程序。我想为所有类型的文本文件提供我的编辑器 (MacVim)。比如.html, .xml, ....gitignore等等,甚至是未知的扩展名like.this.
我已经试过了duti,但看起来好像不能用了。
我也试过:
$ defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=org.vim.MacVim;}'
$ defaults read com.apple.LaunchServices
{
LSHandlers = (
{
LSHandlerContentType = "public.plain-text";
LSHandlerRoleAll = "org.vim.MacVim";
}
);
}
并且具有不同的 UTI,例如 public.text
、public.utf8-plain-text
。运气不好。
感谢任何帮助。我不想再看到 TextEdit...
好吧,this answer on Ask Different mentions your method to be outdated. It also points to another answer 这应该适用于较新的 macOS 版本(Mavericks 之后的版本)。
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=org.vim.MacVim;}'
请注意您的代码中的 com.apple.LaunchServices LSHandlers -array-add
与提供的解决方案中的 com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add
之间的区别。
编辑
我忘了提到 需要重新启动(虽然链接的答案确实提到了这一点)。
此外,请注意(请参阅此答案的评论)OP 显然需要使用 defaults read com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers > defualts.txt
导出所有默认设置,在重新导入之前通过文本编辑器将所有应用程序更改为 org.vim.MacVim
他们通过 defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers "$(cat defualts.txt)"
我知道 Finder 具有更改默认应用程序的内置选项,但这仅适用于该扩展程序。我想为所有类型的文本文件提供我的编辑器 (MacVim)。比如.html, .xml, ....gitignore等等,甚至是未知的扩展名like.this.
我已经试过了duti,但看起来好像不能用了。
我也试过:
$ defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=org.vim.MacVim;}'
$ defaults read com.apple.LaunchServices
{
LSHandlers = (
{
LSHandlerContentType = "public.plain-text";
LSHandlerRoleAll = "org.vim.MacVim";
}
);
}
并且具有不同的 UTI,例如 public.text
、public.utf8-plain-text
。运气不好。
感谢任何帮助。我不想再看到 TextEdit...
好吧,this answer on Ask Different mentions your method to be outdated. It also points to another answer 这应该适用于较新的 macOS 版本(Mavericks 之后的版本)。
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=org.vim.MacVim;}'
请注意您的代码中的 com.apple.LaunchServices LSHandlers -array-add
与提供的解决方案中的 com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add
之间的区别。
编辑
我忘了提到 需要重新启动(虽然链接的答案确实提到了这一点)。
此外,请注意(请参阅此答案的评论)OP 显然需要使用 defaults read com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers > defualts.txt
导出所有默认设置,在重新导入之前通过文本编辑器将所有应用程序更改为 org.vim.MacVim
他们通过 defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers "$(cat defualts.txt)"