2

Git includes Vi in its Git Bash shell on Windows through MinGW64. I'm not a Vi user, so Git really screws things up for me when it launches Vi. It usually ends in me forcefully closing the terminal, deleting the clone, and then re-cloning (because it wastes so much time trying to fix the mess).

I'd like to use Vi in Emacs mode if there is such a thing. Other editors, like Notepad++ and Visual Studio have similar modes (or plugins to provide them), so I'm guessing Vi probably has it too.

Does Vi have an Emacs mode of operation? If so, how do I tell Vi to behave like Emacs? Or, how do I tell Git to provide me with an Emacs-like editor?

  • 3
    Are you thinking about the editor that is launched to edit the commit messages? – Kusalananda May 26 '17 at 11:51
  • @Kusalananda - I believe the answer is yes. I can post MinGW64's `/usr/bin` if desired. But its slim picking's as far as programs go; and I don't see Emacs or one of its knock-offs. There's not much there (I guess that explains why Git insists on using Vi). –  May 26 '17 at 11:54
  • @Kusalananda - Also, I have no idea how this fellow has Emacs: [Git Bash in emacs on Windows](https://emacs.stackexchange.com/q/22049). We seem to have nearly the same configuration, but I get an error when trying to launch Emacs: `bash: emacs: command not found`. –  May 26 '17 at 12:02
  • I can't resist to add a remark: While your wish to use the editor of your choice is perfectly understandable, the way you talk about `vi` reminds me of what I did say long time ago. It was weird, it was annoying, I got rid of it until circumstances forced me to use it. And I learned I was wrong. Today, I have bought a lot of software, including expensive DTP solutions, but the program I paid most for is `vim`. I didn't need to, of course, but it saved me so much time, that I was glad to spend it. Maybe you could love it, too, if you give it a chance on a better day and start `vimtutor` – Philippos May 26 '17 at 12:12
  • 2
    @Philippos - Yeah, editors are like religion. I try to avoid the Emacs/Vi debates. Some of the history (for me): when I was in college our CompSci instructor introduced us to both Emacs and Vi. I remember trying them both, and I was perplexed I had to do something special to edit text in a text editor when using Vi. I wrote-off Vi as poorly engineered, and I've been using Emacs ever since (25 years or so). –  May 26 '17 at 12:26
  • [Cygwin](https://www.cygwin.com/) has git, bash, vim, emacs, and much, much more. – David Conrad May 26 '17 at 20:39
  • 3
    Forcefully closing a terminal, deleting and re-cloning is a ridiculously heavy handed approach. You don't need to learn Vi to write commit messages. All you need to know is i (for insert mode), esc (exit insert mode) and :wq (write and quit). Once you're in insert mode, you can ignore all of Vi's other features and use it like a normal editor if you so wish. You can type like normal, and use arrow keys to navigate. As an aside, calling Vi "poorly engineered" isn't a great way to avoid Emacs/Vi debates. "I personally don't like it" would probably be considered more neutral! – JBentley May 27 '17 at 12:52
  • Thanks @JBentley. Git makes nearly every simple task difficult to impossible. A tool that's suppose to check-in, check-out and manage diffs, it does none of them well. A simple task of "sync my local with upstream" requires 5 steps, a `git pull` and often leads to a merge even when there's absolutely no difference in the remote and local file. Then I attempt to close the editor with X-C and it locks up. I forcefully close the terminal and then I have a broken merge that I did not want in the first place. At this point, I can spend hours trying to unscrew it, or I can delete it and start over. –  May 27 '17 at 13:04
  • @jww I'd recommend you get familiar with the `git reset` command. No sense in losing your local commits mate. – RubberDuck May 27 '17 at 16:24
  • 1
    Thanks @RubberDuck. I'm very familiar with many Git commands. Like millions of others, we all have problem with simple tasks. For example, here is 4 million people having trouble with the simple task of updating a fork: [How do I update a GitHub forked repository?](https://stackoverflow.com/q/7244321/608639) And here's 50000 people who had trouble with a simple task of reset: [Clean up a fork and restart it from the upstream](https://stackoverflow.com/q/9646167/608639). When problems affect millions of users, the problem is with the tool, not the users. –  May 28 '17 at 00:15

2 Answers2

31

You can't do it that way. vi is vi and emacs is emacs. If you are not happy with the default editor, do

git config --global core.editor path-to-emacs.exe-on-your-machine

You can install emacs separately, it doesn't need to be part of your git bash.

Philippos
  • 13,237
  • 2
  • 37
  • 76
  • Thanks @Philippos. I probably should have stated in the question.... [GNU Emacs | Download & installation](https://www.gnu.org/software/emacs/download.html) tells me to `pacman -S mingw-w64-x86_64-emacs`. But it appears Git Bash's package manager is broken out of the box: *`bash: pacman: command not found`*. I can post the contents of `/usr/bin` if you would like to see it. –  May 26 '17 at 12:19
  • 3
    I think you're looking at the directions for msys2. The paragraph right above it gives mirrors to exe installers. – jmathew May 26 '17 at 14:05
7

To build upon @Philippos' answer, it doesn't make sense to try to configure vim to work like emacs, you should set git to use your preferred editor instead. I see from the comments that you don't have emacs installed, do you have another text editor installed that you could use for this?

For example, if you use Notepad++ you can use:

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

You should be able to do something similar with any text editor, though finding the correct command to use might take some searching.

  • 1
    I'd say from the way he worded the question that he specifically wants Emacs, or something with an Emacs mode. – JBentley May 27 '17 at 12:57