# Neovim terminal and @edit

**URL:** https://discourse.julialang.org/t/neovim-terminal-and-edit/99822
**Category:** General Usage
**Tags:** question
**Created:** [June 3, 2023, 9:06pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822 "2023-06-03T21:06:03Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [June 3, 2023, 9:06pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/1 "2023-06-03T21:06:03Z")

</div>

I often use julia inside the neovim terminal. One annoyance I have with this is that say `@edit sin(1)` will open that code in a new instance of neovim. Instead, I would prefer it to use the current instance. Is that possible?

---

<div class="post-metadata">

### Author: ![caleb-allen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/caleb-allen/32/14054_2.png) [@caleb-allen](https://discourse.julialang.org/u/caleb-allen)
#### Post date: [June 5, 2023, 10:50am UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/2 "2023-06-05T10:50:17Z")

</div>

I don’t believe there are any options to do this with the REPL as it is. But you may be able to define a new macro which essentially copies @edit, but instead of opening an editor it could use this library to connect to an existing neovim instance

> **[GitHub - bfredl/Neovim.jl: Neovim client for Julia](https://github.com/bfredl/Neovim.jl)**
>
> Neovim client for Julia. Contribute to bfredl/Neovim.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [June 5, 2023, 10:59am UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/3 "2023-06-05T10:59:11Z")

</div>

That is an interesting suggestion. I wonder how vscode handles this. If you do `@edit` in the repl there, it will open in the running vscode instance or not?

---

<div class="post-metadata">

### Author: ![djvanderlaan](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@djvanderlaan](https://discourse.julialang.org/u/djvanderlaan)
#### Post date: [June 5, 2023, 12:00pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/4 "2023-06-05T12:00:59Z")

</div>

Perhaps [clientserver - How can I use --servername and --remote in neovim? - Vi and Vim Stack Exchange](https://vi.stackexchange.com/questions/5348/how-can-i-use-servername-and-remote-in-neovim) might give a suggestion how to do this

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [June 5, 2023, 1:28pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/5 "2023-06-05T13:28:34Z")

</div>

I know @kdheepak is an expert in this area; see also (but not Julia-specific) [kdheepak - Vim, tmux and zsh — the productivity trio](https://kdheepak.com/blog/vim-tmux-zsh/)

---

<div class="post-metadata">

### Author: ![kdheepak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdheepak/32/10881_2.png) [@kdheepak](https://discourse.julialang.org/u/kdheepak)
#### Post date: [June 5, 2023, 1:44pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/6 "2023-06-05T13:44:27Z")

</div>

Thanks for pinging me @jd-foster!

@jw3126 it is mostly straightforward to do this:

1. Install [neovim-remote](https://github.com/mhinz/neovim-remote) (I use `pip install neovim-remote`).
2. Add the following to your `~/.bashrc`

```julia-auto
if [-n "$NVIM_LISTEN_ADDRESS"]; then
    export VISUAL="nvr -cc split --remote-wait +'set bufhidden=wipe'"
else
    export VISUAL="nvim"
fi

# Make neovim the default editor.
export EDITOR="$VISUAL"

```

Restart your terminal and you should be good to go!

### Explanation

`nvr` is a python package to access a powerful feature of neovim: remote neovim command. And you can do many fancy things with it. It basically lets you remotely control any neovim instance if you know the socket address.

When you are inside Neovim, the `NVIM_LISTEN_ADDRESS` environment variable is set. So if that variable is set, use `nvr` to open a split. This will open the file as a buffer in the current neovim instance.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [June 5, 2023, 2:53pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/7 "2023-06-05T14:53:09Z")

</div>

Thanks! I added

```shell
if [-n "$NVIM_LISTEN_ADDRESS"]; then
    export VISUAL="nvr -cc split --remote-wait +'set bufhidden=wipe'"
else
    echo "NVIM_LISTEN_ADDRESS not set"
    export VISUAL="lvim"
fi

```

to my `.zshrc`. However when I do `:terminal` in nvim I get:

```julia
NVIM_LISTEN_ADDRESS not set

```

---

<div class="post-metadata">

### Author: ![kdheepak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdheepak/32/10881_2.png) [@kdheepak](https://discourse.julialang.org/u/kdheepak)
#### Post date: [June 5, 2023, 4:28pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/8 "2023-06-05T16:28:58Z")

</div>

> [@jw3126](#):
>
> `NVIM_LISTEN_ADDRESS`

It appears `NVIM_LISTEN_ADDRESS` has been deprecated: [introduce $NVIM, unset $NVIM\_LISTEN\_ADDRESS by justinmk · Pull Request #11009 · neovim/neovim · GitHub](https://github.com/neovim/neovim/pull/11009)

You’ll need to use `NVIM` instead. If I change my `~/.bashrc` to this:

```julia
if [-n "$NVIM"]; then
    export VISUAL="nvr -cc split --remote-wait +'set bufhidden=wipe'"
else
    export VISUAL="vim"
fi

```

I’m able to use `@edit` to open in a horizontal split:

 ![](https://global.discourse-cdn.com/julialang/original/3X/5/d/5d5ad3e8c1b6aa098fb59b9fbc1446fac7726426.png)

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [June 5, 2023, 5:43pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/9 "2023-06-05T17:43:23Z")

</div>

Awesome thanks a lot! This does already what I asked for. It works fine with vanilla neovim. Now I actually use lunar vim, And there it does not quite work. It does not create a spit instead it does open the correct file in the current window, but the window freezes.

---

<div class="post-metadata">

### Author: ![kdheepak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdheepak/32/10881_2.png) [@kdheepak](https://discourse.julialang.org/u/kdheepak)
#### Post date: [June 5, 2023, 6:03pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/10 "2023-06-05T18:03:42Z")

</div>

That is strange. I can’t imagine why LunarVim would freeze. If it happens with vanilla LunarVim, you might want to open a issue on their repo. I do see a number of issues that have `nvr` or `neovim-remote` when I search on the issue tracker, but just quickly skimming through a few it didn’t seem like there were any problems that weren’t already solved.

If you share your configuration and it is reproducible on my machine, I might be able to help figure out what is going on.

Alternatively, you can try AstroNvim or LazyVim and see if the same problem exists there. I’m also happy to share my nvim configuration if you think that’ll be useful.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [June 5, 2023, 8:30pm UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/11 "2023-06-05T20:30:07Z")

</div>

Thanks a lot, that is a really kind offer! I will try what happens with vanilla lunar vim and post an issue or ask in their discord.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [June 6, 2023, 11:24am UTC](https://discourse.julialang.org/t/neovim-terminal-and-edit/99822/12 "2023-06-06T11:24:51Z")

</div>

Seems to be an issue with my specific configuration, on vanilla lunar vim it works.
