How do I make Git use the editor of my choice for commits?

后端 未结 27 2087
庸人自扰
庸人自扰 2020-11-22 01:33

I would prefer to write my commit messages in Vim, but it is opening them in Emacs.

How do I configure Git to always use Vim? Note that I want to do this globally,

相关标签:
27条回答
  • 2020-11-22 02:10

    Windows: setting notepad as the default commit message editor

    git config --global core.editor notepad.exe
    

    Hit Ctrl+S to save your commit message. To discard, just close the notepad window without saving.

    In case you hit the shortcut for save, then decide to abort, go to File->Save as, and in the dialog that opens, change "Save as type" to "All files (*.*)". You will see a file named "COMMIT_EDITMSG". Delete it, and close notepad window.

    Edit: Alternatively, and more easily, delete all the contents from the open notepad window and hit save. (thanks mwfearnley for the comment!)

    I think for small write-ups such as commit messages notepad serves best, because it is simple, is there with windows, opens up in no time. Even your sublime may take a second or two to get fired up when you have a load of plugins and stuff.

    0 讨论(0)
  • 2020-11-22 02:11

    Copy paste this:

    git config --global core.editor "vim"
    

    In case you'd like to know what you're doing. 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).

    0 讨论(0)
  • 2020-11-22 02:11

    This provides an answer for people who arrive at this Question that may want to link an editor other than vim.

    The linked resource, by Github,is likely to be kept up to date, when editors are updated, even if answers on SO (including this one) are not.

    Associating Text Editors with git

    Github's post shows exactly what to type in to your command line for various editors, including the options/flags specific to each editor for it to work best with git.

    Notepad++:
    git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

    Sublime Text:
    git config --global core.editor "'c:/Program Files/sublime text 3/subl.exe' -w"

    Atom:
    git config --global core.editor "atom --wait"

    The commands above assume your editor has been installed in the default directory for a windows machine.

    The commands basically add the text between double-quotes to .gitconfig in your home directory.
    On a windows machine home is likely to be C:\Users\your-user-name, where your-user-name is your login name.
    From the command line, you can reach this directory by typing in cd ~.

    for example, a command above would be add the following line under the [core] section like so:
    [core] editor = 'C:/Program Files/sublime text 3/subl.exe' -w

    If you have a different editor, just replace with the path to your editor, using either method above. (and hope no flags are needed for optimal usage.)

    0 讨论(0)
  • 2020-11-22 02:14

    Mvim as your git editor

    Like all the other GUI applications, you have to launch mvim with the wait flag.

    git config --global core.editor "mvim --remote-wait"
    
    0 讨论(0)
  • 2020-11-22 02:14

    For Windows, Neovim:

    # .gitconfig
    
    [core]
        editor='C:/tools/neovim/Neovim/bin/nvim-qt.exe'
    
    0 讨论(0)
  • 2020-11-22 02:17

    And if you are working with designers using the command line then Pico, and dont know short cuts ;)

    git config --global core.editor "pico"
    

    Or

    export VISUAL=pico
    export EDITOR=pico
    
    0 讨论(0)
提交回复
热议问题