DEV Community

Pizofreude
Pizofreude

Posted on • Updated on

Efficient Way to Invoke All Editors in Git Bash on Windows

Just kidding, it works on all OS as well. Just configure the correct directory upon setting this method.

Vim comes as a package when installing Git even though you choose other text editor during installation.

You invoke vim as vi <filename> in Git Bash cli.

Short and sweet. What about the other editors?

  1. For GNU nano: nano <filename>

  2. For Notepad: notepad <filename>

  3. For Notepad++: start notepad++ <filename>

  4. For <your favourite editor>: start <your favourite editor> <filename>

Isn't very efficient it seems. You can however change the main editor via git config. But only one main editor is allowed at once.

Worry not, here's an efficient way around it to use all editors in Git Bash:

Add Permanent Alias in Git Bash

Run Git Bash as administrator.

Open aliases.sh

$ cd /etc/profile.d
$ vi aliases.sh
Enter fullscreen mode Exit fullscreen mode

Add alias in aliases.sh. For example, we add npp as an alias for Notepad++:

# --show-control-chars: help showing Korean or accented characters
alias ls='ls -F --color=auto --show-control-chars'
alias ll='ls -l'
alias npp='/c/Program\ Files/Notepad++/notepad++.exe'
Enter fullscreen mode Exit fullscreen mode

p/s: Use \ to escape spaces in the directory.

Add as many other editors as you like in the aliases.sh file. Just follow the format:

alias <YourAlias>='/YourProgramDirectory/YourEditor.exe'
Enter fullscreen mode Exit fullscreen mode

Save the settings, close Git Bash and reopen it to activate the new configuration. Voila!

If it does not activated by chances in the future, source it and it will be activated again:

$ cd /etc/profile.d
$ source aliases.sh
Enter fullscreen mode Exit fullscreen mode

As a bonus, this method also works to add any linux commands as alias too. For example, instead of clear, you can alias it as cls.

cls=`clear`
Enter fullscreen mode Exit fullscreen mode

That's it folks, happy days!

So what are your favourite editor? Comment down below.

Cheers!

Top comments (0)