问题
Is there a way to make files opened for editing in the terminal open in Textedit instead?
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).
And as a bonus question, is there any way to specifically configure git to automatically open the file created after running git commit in an editor from the applications directory?
回答1:
Most programs will check the $EDITOR environment variable, so you can set that to the path of TextEdit in your bashrc. Git will use this as well.
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
If you are using zsh, use ~/.zshrc instead of ~/.bashrc.
回答2:
Use git config --global core.editor mate -w or git config --global core.editor open as @dmckee suggests in the comments.
Reference: http://git-scm.com/docs/git-config
回答3:
For OS X and Sublime Text
Make subl available.
Put this in ~/.bash_profile
[[ -s ~/.bashrc ]] && source ~/.bashrc
Put this in ~/.bashrc
export EDITOR=subl
回答4:
For anyone coming here in 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
回答5:
Set your editor to point to this program:
/Applications/TextEdit.app/Contents/MacOS/TextEdit
With SVN, you should set SVN_EDITOR environment variable to:
$ export SVN_EDITOR=/Applications/TextEdit.app/Contents/MacOS/TextEdit
And then, when you try committing something, TextEdit will launch.
回答6:
For Sublime Text 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 X for details.
来源:https://stackoverflow.com/questions/3539594/change-the-default-editor-for-files-opened-in-the-terminal-e-g-set-it-to-text