macos 更改在终端中打开的文件的默认编辑器?(例如将其设置为 TextEdit/Coda/Textmate)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3539594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:10:34  来源:igfitidea点击:

Change the default editor for files opened in the terminal? (e.g. set it to TextEdit/Coda/Textmate)

macosterminaltext-editor

提问by Diogenes

Is there a way to make files opened for editing in the terminal open in Textedit instead?

有没有办法让在终端中打开进行编辑的文件在 Textedit 中打开?

For example, where a command might open a file for editing (like git commit), instead of opening that file in vim or emacs, it would open in Textedit (or perhaps another text editing application of your choosing, such as Coda or Sublime).

例如,命令可能会打开一个文件进行编辑(如git commit),而不是在 vim 或 emacs 中打开该文件,它会在 Textedit(或者您选择的另一个文本编辑应用程序,例如 Coda 或 Sublime)中打开。

And as a bonus question, is there any way to specifically configure git to automatically open the file created after running git commitin an editor from the applications directory?

作为一个额外的问题,有什么方法可以专门配置 git 以自动打开git commit在应用程序目录中的编辑器中运行后创建的文件?

回答by alternative

Most programs will check the $EDITORenvironment variable, so you can set that to the path of TextEdit in your bashrc. Git will use this as well.

大多数程序会检查$EDITOR环境变量,因此您可以将其设置为 bashrc 中 TextEdit 的路径。Git 也会使用它。

How to do this:

这个怎么做:

  • Add the following to your ~/.bashrcfile:
    export EDITOR="/Applications/TextEdit.app/Contents/MacOS/TextEdit"
  • or just type the following command into your Terminal:
    echo "export EDITOR=\"/Applications/TextEdit.app/Contents/MacOS/TextEdit\"" >> ~/.bashrc
  • 将以下内容添加到您的~/.bashrc文件中:
    export EDITOR="/Applications/TextEdit.app/Contents/MacOS/TextEdit"
  • 或者只需在终端中输入以下命令:
    echo "export EDITOR=\"/Applications/TextEdit.app/Contents/MacOS/TextEdit\"" >> ~/.bashrc

If you are using zsh, use ~/.zshrcinstead of ~/.bashrc.

如果您使用的是 zsh,请使用~/.zshrc代替~/.bashrc

回答by Ionu? G. Stan

Use git config --global core.editor mate -wor git config --global core.editor openas @dmckee suggests in the comments.

使用git config --global core.editor mate -wgit config --global core.editor open作为@dmckee 在评论中的建议。

Reference: http://git-scm.com/docs/git-config

参考:http: //git-scm.com/docs/git-config

回答by Kirk Strobeck

For OS X and Sublime Text

对于 OS X 和 Sublime Text

Make sublavailable.

使subl可用。

Put this in ~/.bash_profile

把这个放进去 ~/.bash_profile

[[ -s ~/.bashrc ]] && source ~/.bashrc

Put this in ~/.bashrc

把这个放进去 ~/.bashrc

export EDITOR=subl

回答by Alexander

For anyone coming here in 2018:

对于 2018 年来到这里的任何人:

  • go to iTerm -> Preferences -> Profiles -> Advanced -> Semantic History
  • from the dropdown, choose Open with Editor and from the right dropdown choose your editor of choice
  • 转到 iTerm -> 首选项 -> 配置文件 -> 高级 -> 语义历史
  • 从下拉菜单中选择使用编辑器打开,然后从右侧下拉菜单中选择您选择的编辑器

回答by Pablo Santa Cruz

Set your editor to point to this program:

将您的编辑器设置为指向此程序:

/Applications/TextEdit.app/Contents/MacOS/TextEdit

With SVN, you should set SVN_EDITORenvironment variable to:

使用 SVN,您应该将SVN_EDITOR环境变量设置为:

$ export SVN_EDITOR=/Applications/TextEdit.app/Contents/MacOS/TextEdit

And then, when you try committing something, TextEdit will launch.

然后,当您尝试提交某些内容时,TextEdit 将启动。

回答by KFunk

For Sublime Text 3:

对于崇高文本 3:

defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'

See Set TextMate as the default text editor on Mac OS Xfor details.

有关详细信息,请参阅将 TextMate 设置为 Mac OS X 上的默认文本编辑器

回答by mrapacz

If you want the editor to work with git operations, setting the $EDITORenvironment variable may not be enough, at least not in the case of Sublime - e.g. if you want to rebase, it will just say that the rebase was successful, but you won't have a chance to edit the file in any way, git will just close it straight away:

如果你想让编辑器使用 git 操作,设置$EDITOR环境变量可能还不够,至少在 Sublime 的情况下不是——例如,如果你想 rebase,它只会说 rebase 成功,但你不会没有机会以任何方式编辑文件,git 会立即关闭它:

git rebase -i HEAD~
Successfully rebased and updated refs/heads/master.

If you want Sublime to work correctly with git, you should configure it using:

如果您希望 Sublime 与 git 一起正常工作,您应该使用以下命令对其进行配置:

git config --global core.editor "sublime -n -w"

I came here looking for this and found the solution in this gist on github.

我来这里寻找这个并在 github 上的这个要点中找到了解决方案。