2020-03-21-setting-git-default-editor

栏目: IT技术 · 发布时间: 6年前

内容简介:By default, when git needs to fire up an editor to do something such as write a commmit message, it uses whatever is configured as the default editor for the user. (Configuring the user's default editor is an entirely differnt topic.)There are a couple of
category keywords

tools

git, editor, emacs

Setting git's default editor

By default, when git needs to fire up an editor to do something such as write a commmit message, it uses whatever is configured as the default editor for the user. (Configuring the user's default editor is an entirely differnt topic.)

There are a couple of ways to change this for git :

  1. setting one or two environment variables
  2. modifying the global git configuration

Of these, I long used the first way, since the environment variables are also recognized by other command line tools (although not all).

Recently I was made aware of method two, modifying the global git configuration.

Settingh environment variables

Git will use two common environment variables, EDITOR and VISUAL , to determine what editor it should run. Some tools make a distinction between when these are used:

EDITOR
VISUAL

Git doesn't really care, you can set one or the other. In the course of my career, I settled on the expediency of setting them both to the same thing and calling it a day.

Modifying git global config

Head over to https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration to see the official documentation on modifying the config.

The specific part to set the editor is described here:

core.editor

By default, Git uses whatever you’ve set as your default text editor via one of the shell environment variables VISUAL or EDITOR, or else falls back to the vi editor to create and edit your commit and tag messages. To change that default to something else, you can use the core.editor setting:

$ git config --global core.editor emacs

Now, no matter what is set as your default shell editor, Git will fire up Emacs to edit messages.

They are already speaking my kind of language. But I want to go just a bit further and use emacsclient so as to not call up another instance of the full emacs editor if I can help it. Instead, I set the core.editor value to:

emacsclient -a emacs

which will run emacsclient to use the currently running instance of emacs, and , if there is no currently running instance, start one up.

A caveat

I initially used the command line arguments I normally run emacsclient with: -c -n , which say to open a new frame and not to wait for the editing session to finish. Bad move. If the git command is not forced to wait while I modify the commit message, it assumes it wasn't changed and aborts the commit. I also didn't want to have it be spawning new frames since that just gets messy if I forget to close them, which I most often do.

I hear you, you don't use emacs

You aren't a dinosaur like I am, I got you.

You can run VSCode from the command line, or Atom, etc., etc., etc.. I'm not going to teach you how to set that up, but you should learn how if you don't because it will speed up your work.

Here are some of the alternative:

git config -global core.editor code
git config --global core.editor atom
git config --global core.editor vim

Git-mode in Editors

Most modern-day editors have a means of running git commands from inside the editor. This is often a far richer environment, closer to a GUI tool, really, than the command line offers. I use magit in emacs all the time, but I also use the command line all the time; some operations are better for one than the other. (By the way, magit has seriously the very best implementation for doing an interactive rebase, i.e., squashing your commits.)


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Effective C++中文版

Effective C++中文版

[美] Scott Meyers / 侯捷 / 华中科技大学出版社 / 2001-9 / 49.80元

Effective C++是世界顶级C++大师Scott Meyers的成名之作,初版于1991年。在国际上,这本书所引起的反响之大,波及整个计算机技术出版领域,余音至今未绝。几乎在所有C++书籍的推荐名单上,这部专著都会位于前三名。作者高超的技术把握力,独特的视角、诙谐轻松的写作风格、独具匠心的内容组织,都受到极大的推崇和仿效。 书中的50条准则,每一条都扼要说明了一个可让你写出更好的C+......一起来看看 《Effective C++中文版》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具