# @edit on Windows

**URL:** <https://discourse.julialang.org/t/edit-on-windows/1695>\
**Category:** General Usage\
**Tags:** windows\
**Created:** [January 26, 2017, 6:49am UTC](https://discourse.julialang.org/t/edit-on-windows/1695 "2017-01-26T06:49:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [January 26, 2017, 6:49am UTC](https://discourse.julialang.org/t/edit-on-windows/1695/1 "2017-01-26T06:49:07Z")

</div>

I often use `@which` but would also like to use `@edit`.

On Windows `@edit` doesn’t seem to work for me by default, so I did some investigating and managed to get something that works.  
Sharing here in case it helps any other long-suffering Windows users.  
Also some questions below:

I managed to get `@edit` working with `Atom`, `Sublime Text` and `Notepad++`.

If you don’t want to read the long story below, just put one of these into your `.juliarc.jl` file.

`ENV["JULIA_EDITOR"] = "\"C:\\Users\\plowman\\AppData\\Local\\atom\\bin\\atom.cmd\""`  
`ENV["JULIA_EDITOR"] = "\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""`  
`ENV["JULIA_EDITOR"] = "\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\""`

Note the extra escaped quotes `\"`  
`Notepad++` requires some extra steps, read on.

Firstly it seems the default editor for Windows is `open` which results in `edit()` running the command:

```julia
`cmd /c start /b $path`

```

This doesn’t work for me.

So I tried setting JULIA\_EDITOR, but without “double”-quoting the path gets split.

```julia
julia> ENV["JULIA_EDITOR"] = "C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
"C:\\Program Files\\Sublime Text 3\\sublime_text.exe"

julia> Base.editor()
4-element Array{AbstractString,1}:
 "C:Program"
 "FilesSublime"
 "Text"
 "3sublime_text.exe"

```

`editor()` calls `shell_split()`.  
**1. Is this the expected behaviour of `shell_split()`?**

One way around this is to “double”-quote the path:

```julia
julia> ENV["JULIA_EDITOR"] = "\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""
"\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""

julia> Base.editor()
1-element Array{AbstractString,1}:
 "C:\\Program Files\\Sublime Text 3\\sublime_text.exe"

```

This it relatively easy (although unintuitive) when setting JULIA\_EDITOR from within Julia.  
However, I couldn’t find a way to make this work by setting the Windows environment variable JULIA\_EDITOR.  
**2. Does anyone know how to set JULIA\_EDITOR in Windows so path is preserved as single string?**

OK so this works for `Atom`, `Sublime Text` and `Notepad++`.

`ENV["JULIA_EDITOR"] = "\"C:\\Users\\plowman\\AppData\\Local\\atom\\bin\\atom.cmd\""`  
`ENV["JULIA_EDITOR"] = "\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""`  
`ENV["JULIA_EDITOR"] = "\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\""`

For `Atom` and `SublimeText`, existing code in `edit()` (in `interactiveutil.jl`) handles the command line options to open the file at the appropriate line number.

For `Notepad++` the following snippet needs to be inserted into `edit()`:

```julia
elseif startswith(name, "notepad++")
        cmd = line != 0 ? `$command $path -n$line` : `$command $path`

```

**3. Does anyone else use `Notepad++`? Is this worth adding to base?**

Hope this helps.  
Would also like to hear other Windows users experience with `@edit`

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 26, 2017, 3:47pm UTC](https://discourse.julialang.org/t/edit-on-windows/1695/2 "2017-01-26T15:47:17Z")

</div>

> [@greg\_plowman](#):
>
> Firstly it seems the default editor for Windows is open which results in edit() running the command:
> 
> `cmd /c start /b $path`
> 
> This doesn’t work for me.

Maybe you need to set a [default application](http://www.digitaltrends.com/computing/how-to-set-default-programs-and-file-types-in-windows-10/) for `.jl` files?

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [January 26, 2017, 10:25pm UTC](https://discourse.julialang.org/t/edit-on-windows/1695/3 "2017-01-26T22:25:36Z")

</div>

> [@stevengj](#):
>
> Maybe you need to set a default application for .jl files?

Yes that’s a good point.  
I checked this in `Control Panel -> Default Programs`, and I can also open `.jl` files by clicking in Windows Explorer, so I think this is OK.

After some further investigation, I think I have narrowed down the issue for me:

As an example `@edit cmp(1,2)` attempts to run the command:

```julia
cmd /c start /b 'C:\Program Files\Julia-0.5.0\bin\../share\julia\base\operators.jl'

```

I think there are two issues here:

1. The space in file path: `start` tries run `C:\Program`. I tried many variations of extra quoting with single and double quotes but couldn’t get it to work.
2. The forward slash in path (`../share`)

So my workaround is:

```julia
cmd = `cmd /c start /b /D $(realpath(dirname(path))) $(basename(path))`

```

which runs the command:

```julia
cmd /c start /b /D 'C:\Program Files\Julia-0.5.0\share\julia\base' operators.jl

```

For some reason space is OK in directory /D, `realpath` removes the forward slash.

However the default `open` still has the limitation of not supporting line number.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 27, 2017, 3:03pm UTC](https://discourse.julialang.org/t/edit-on-windows/1695/4 "2017-01-27T15:03:43Z")

</div>

> [@greg\_plowman](#):
>
> 1. The forward slash in path (…/share)

This path indeed comes from `base/build_h.jl` and is computed at compile time by the `contrib/relative_path.sh` script. I’m not sure what’s the best solution to fix this: either improve the script to detect Windows or fix the path later from Julia. Could you file an issue on GitHub to discuss the best approach?

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [February 1, 2017, 8:14am UTC](https://discourse.julialang.org/t/edit-on-windows/1695/5 "2017-02-01T08:14:41Z")

</div>

GitHub issues opened:

- `@edit` on Windows using default editor: [#20364](https://github.com/JuliaLang/julia/issues/20364)
- Setting JULIA\_EDITOR in Windows: [#20365](https://github.com/JuliaLang/julia/issues/20365)
- Adding Notepad++ support for `@edit`: [#20366](https://github.com/JuliaLang/julia/issues/20366)

---

<div class="post-metadata">

**Author:** ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)\
**Post date:** [February 3, 2017, 9:50pm UTC](https://discourse.julialang.org/t/edit-on-windows/1695/6 "2017-02-03T21:50:37Z")

</div>

Not sure if this is still useful, but to open a file with the default program on Windows (without spawning cmd), the command is `explorer filename.ext`.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [February 4, 2017, 6:06am UTC](https://discourse.julialang.org/t/edit-on-windows/1695/7 "2017-02-04T06:06:09Z")

</div>

> [@jebej](#):
>
> Not sure if this is still useful, but to open a file with the default program on Windows (without spawning cmd), the command is explorer filename.ext.

Yes this does work. Thanks.  
It seems to allow spaces in filename, but _not_ forward slashes. So maybe requires `realpath`:

```julia
cmd = `explorer $(realpath(path))`

```

Another suggestion was made over on GitHub [`@edit` on Windows using default editor · Issue #20364 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/20364#issuecomment-277393711)  
Indeed the following appears to overcome both the spaces and forward slash issues:

```julia
cmd = `cmd /c start /b "" $path`

```
