5

I'm learning to program. While following this mission, I typed git commit, which opened up vim. I don't know or want to know vim (no offense to vim lovers). I'd like to have:

  1. terminal open gedit ever time it try to do text editing from the terminal; and
  2. gedit release the terminal for further use.

How do I do that?

UPDATE:

Ok. I'm close, but I must be missing something.

Added /Applications/gedit.app/Contents/MacOS/ to /etc/paths

Because I wasn't root, I had to save it to my desktop. Then I had to move it to /etc, so, terminal handled that.

sudo mv paths /etc

Then I changed the editor.

git config --global core.editor "gedit"

after typing

git commit

I received.

error: cannot run gedit: No such file or directory
error: There was a problem with the editor 'gedit'.
Please supply the message using either -m or -F option.

UPDATED 2: Relaunching terminal fixed the problem.

Thanks everyone.

4
  • 3
    You really should learn vim well enough for basic text editing. It's an important skill for a programmer. GUI editors are nice and all, but sometimes a command line editor is the only choice and vim is a perfectly good one. I'm not saying you should use it for git messages, but you should know how it's done. "I don't know or want to know vim" is a stupid attitude. It should be "I prefer not to use vim, but I can when it's the best option". Mar 4, 2012 at 3:05
  • 3
    I was making the statement "I don't know or want to know vim" to avoid getting answers on how to use vim. It's the perfect attitude if you want to clearly state what you don't want. I have no problem with vim or learning vim in the future, but my ineptitude with non-GUI text editors was causing more problems than help. Since everything regarding programming is new for me, I have to pick my battles and a non-GUI text editor wasn't going to be one of them today.
    – Dorje
    Mar 4, 2012 at 3:22
  • 2
    In should only take you five minutes to learn enough about vim to type a git message. And learning vim is a lot easier than figuring out how to integrate a GUI text editor into the command line, and in many common situations it's impossible. Anyway, I just wanted to point out you should put vim on your to-do list as something to learn one day. Preferably soon. Mar 4, 2012 at 3:28
  • If you put the line export EDITOR=gedit in ~/.bash_profile, then EVERY command line program that wants you to edit something will open it in gedit. Also, you should try out nano, which is a very simple CLI text editor, and should also be present on most nixes. (It is included by default on Mac OS X.) It is much more like a *normal text editor, and all the commands are listed in two lines at the bottom of the window. (You will probably find it more convenient for git commits, for example, because you won't have to jump from window to window.)
    – daviewales
    Dec 6, 2013 at 13:14

4 Answers 4

0

In order to do this, type

open -a gedit path/to/file

to open and run the gedit application (using the -a switch issues a command to look for gedit in your /Applications directory).

Alternatively, add /Applications/gedit.app/Contents/MacOS/ to your $PATH, which should allow you to open gedit from the terminal as well by simply typing

gedit
3
  • Yes. Those help when I'm in control, but will it help with situations where I'm not in control - like with the git commit command? Also, where would I find the $PATH file?
    – Dorje
    Mar 4, 2012 at 1:05
  • $PATH is a variable usually set in your .bashrc file
    – MrDaniel
    Mar 4, 2012 at 1:14
  • @Dorje, if my answer solved your problem, please click "accept answer" on the left side of my answer. Glad this helped!
    – soxman
    Mar 7, 2012 at 21:26
4

You should edit your git configuration file regarding which editor to use.

As noted here How do I make git use the editor of my choice for commits?

From man git-commit:

ENVIRONMENT AND CONFIGURATION VARIABLES

The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).

4
  • setting EDITOR or VISUAL will allow you to use that editor from any command line program
    – mmmmmm
    Mar 4, 2012 at 1:05
  • Yes, you usually want to set EDITOR - this is used by many other VCS, such as CVS or SVN.
    – cm2
    Mar 4, 2012 at 1:27
  • @cm2 - not just VCS but other processes.
    – mmmmmm
    Mar 4, 2012 at 18:56
  • @Mark Ooops, I meant 'many other programs including VCS...'! Indeed, these are used by lots of programs.
    – cm2
    Mar 4, 2012 at 23:22
0

See this post http://eddieringle.com/how-to-properly-configure-git-to-use-gedit-as-its-default-editor/

and excerpt below

git config --global core.editor "gedit -w -s"
    -w: wait for Gedit to save the file and exit before continuing
    -s: runs that instance of Gedit in standalone mode to let gedit return after that window is closed.
2
  • 1
    Did you verify that this works on OS X?
    – nohillside
    Oct 21, 2012 at 9:10
  • I do not have OS X but verifying in Linux I though it might be helpful for others to know about it to give it a try.
    – gunalmel
    Jan 9, 2013 at 5:50
0

If your shell is bash or zsh, open your ${HOME}/.profile (not your .bashrc since you don't have to do this setting on any subshell you will run) with gedit or vim.

Insert the following line:

EDITOR=/Applications/gedit.app/Contents/MacOS/gedit
export EDITOR

( You don't have to change your PATH for this and moreover this might cause other side effects which might waste you a lot of time to analyze. )

Save and close (vim: ESC,:,w,q).

Open a new shell window to check your modification is safe, and load your ${HOME}/.profile:

. ~/.profile

and check that gedit is correctly called from git. If it's OK, then you might restart your session and this is now fixed forever.

NB.: With this modification, gedit will be used in any context where a command would need to call an editor for you.

1
  • 1
    better use .bash_profile or the correct zsh ditfile rather than .profile as if something else adds to the . files .profile would not be loaded
    – mmmmmm
    May 19, 2016 at 7:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .