---
title: A multi-purpose EDITOR variable
date: 2013-03-30 12:49
slug: a-multi-purpose-editor-variable
categories:
- Code
tags:
- quicktip
- scripting
- terminal
---

Here's a quick trick I've been using to load different editors from the command line based on the type of file. It can be extended to whatever file types you want to handle and use whichever editor you prefer.

I use Vim to edit git messages, MultiMarkdown Composer (via the `mmdc` command [available from the website](http://multimarkdown.com/download/)) for text and Markdown files, and Sublime Text 2 for just about everything else.

First, I created an `editor.sh` file in my scripts folder:



```shell
#!/bin/bash

case "$1" in
	*_EDITMSG|*MERGE_MSG|*_TAGMSG )
		/usr/local/bin/vim "$1"
		;;
	*.md )
		/usr/local/bin/mmdc "$1"
		;;
	*.txt )
		/usr/local/bin/mmdc "$1"
		;;
	* )
		/usr/local/bin/subl -w "$1"
		;;
esac
```

[View the code on GitHub](https://gist.github.com/5277629)



Then I just make it executable (`chmod a+x ~/scripts/editor.sh`) and point my EDITOR variable to it in my `.bash_profile`:

    export EDITOR="$HOME/scripts/editor.sh"

Now if I run a git merge and need to enter a message, it pops up Vim right in the terminal I'm working in. If I edit a Markdown file, it automatically opens it in MultiMarkdown composer. Anything else gets sent to Sublime Text 2. Like I said, it's easy to customize with more file types and editors, but I thought I'd share the idea for anyone who'd find it helpful.

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
