# Mix format on save VSCode

**URL:** <https://forum.elixirforum.com/t/mix-format-on-save-vscode/20006>\
**Category:** Questions\
**Tags:** mix\
**Created:** [February 8, 2019, 1:51am UTC](https://forum.elixirforum.com/t/mix-format-on-save-vscode/20006 "2019-02-08T01:51:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Codball](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/codball/32/12944_2.png) [@Codball](https://forum.elixirforum.com/u/Codball)\
**Post date:** [February 8, 2019, 1:51am UTC](https://forum.elixirforum.com/t/mix-format-on-save-vscode/20006/1 "2019-02-08T01:51:24Z")

</div>

Mix format works fine if run from the cmd. I’ve followed [this](https://stories.abletech.nz/how-to-configure-vs-code-to-format-elixir-code-a39e89cdbc59) to facilitate the implementation into VSC which involves downloading an extension called vscode-elixir-formatter. When I save however:

 ![Code_2019-02-07_20-38-29](https://forum.elixirforum.com/uploads/default/original/2X/5/5ecddfadecf4fbd590427ecd5d4174baa0cb23b5.png)

I have a `.formatter.exs` in my project directory which looks like:

```
[
  import_deps: [:ecto, :phoenix],
  inputs: ["mix.exs", "*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
  subdirectories: ["priv/*/migrations"]
]

```

and I’ve checked all the boxes in the VSC user formatter settings. Do I need to tell vscode somehow where my `.formatter.exs` file is?

---

<div class="post-metadata">

**Author:** ![blatyo](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/blatyo/32/4554_2.png) [@blatyo](https://forum.elixirforum.com/u/blatyo)\
**Post date:** [February 8, 2019, 2:13am UTC](https://forum.elixirforum.com/t/mix-format-on-save-vscode/20006/2 "2019-02-08T02:13:11Z")

</div>

**EDIT: This extension is recommended for vscode now:** [ElixirLS Fork: DEPRECATED (use original extension) - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=elixir-lsp.elixir-ls)

I’d recommend this extension instead: [ElixirLS: Elixir support and debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=JakeBecker.elixir-ls)

It’ll do formatting for you among other things. Also, should be able to detect your `.formatter.exs` without any config.

---

<div class="post-metadata">

**Author:** ![factoryd](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/f/8c91f0/32.png) [@factoryd](https://forum.elixirforum.com/u/factoryd)\
**Post date:** [February 8, 2019, 2:25am UTC](https://forum.elixirforum.com/t/mix-format-on-save-vscode/20006/3 "2019-02-08T02:25:09Z")

</div>

I also recommend ElixirLS. But that alone will not format on save; in my experience.

To get that, just add this line to your `settings.json`:

`"editor.formatOnSave": true`

---

<div class="post-metadata">

**Author:** ![fklement](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fklement/32/24995_2.png) [@fklement](https://forum.elixirforum.com/u/fklement)\
**Post date:** [February 8, 2019, 7:48am UTC](https://forum.elixirforum.com/t/mix-format-on-save-vscode/20006/4 "2019-02-08T07:48:39Z")

</div>

You could also use the extension `emeraldwalk/vscode-runonsave` [GitHub - emeraldwalk/vscode-runonsave: Visual Studio Code extension to run commands whenever a file is saved. · GitHub](https://github.com/emeraldwalk/vscode-runonsave)  
And then put the following in your `settings.json`:

```
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.exs?$",
        "isAsync": false,
        "cmd": "cd ${workspaceRoot} && mix format ${file}"
      }
    ]
  },

```

This could also be useful for other commands which you want to run automatically on save.

---

<div class="post-metadata">

**Author:** ![belaustegui](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/belaustegui/32/36580_2.png) [@belaustegui](https://forum.elixirforum.com/u/belaustegui)\
**Post date:** [February 8, 2019, 9:18am UTC](https://forum.elixirforum.com/t/mix-format-on-save-vscode/20006/5 "2019-02-08T09:18:45Z")

</div>

Thank you very much for your comment! Although I am currently using ElixirLS, this looks like a fantastic extension and it seems very useful for lots of things 🙇‍♂️
