# Julia-Vim tutorial for newbies

**URL:** <https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636>\
**Category:** Tooling\
**Tags:** question, vim\
**Created:** [March 28, 2020, 1:38pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636 "2020-03-28T13:38:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 1:38pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/1 "2020-03-28T13:38:39Z")

</div>

Does anyone know about a simple introduction to `Julia-Vim`? I read the plugin `help` but I couldn’t find any reference to first steps.  
My idea is:  
a) a simple setup for running `Julia` files;  
b) how to run them.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 28, 2020, 1:48pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/2 "2020-03-28T13:48:56Z")

</div>

Vim is an editor, it doesn’t run julia files. Julia-vim provides syntax highlighting. You’ll have to open a REPL or another terminal to run julia code.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 1:53pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/3 "2020-03-28T13:53:24Z")

</div>

I think that I can use Vim to edit a `Julia` file and then from `Vim`I can use a command like `:! julia file.jl`that opens the REPL and gives the result. At least I could try this using `julia-vim`plugin. That is similar to what happens using `emacs`.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 28, 2020, 2:01pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/4 "2020-03-28T14:01:44Z")

</div>

What I do is launch a Julia REPL and then I launch my vim editor from the Julia REPL using shell command. So when I’m done editing I can exit vim and land in the Julia REPL again. I’m using a tiling window manager, so usually have multiple terminals open, some for editing, some for evaluating code or pasting code.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 2:20pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/5 "2020-03-28T14:20:14Z")

</div>

I tried to follow your method. I opened a `file.jl` with `Vim` from the REPL using shell. I then run the file in `Vim` using `! %`. `Vim` goes to the terminal `iTerm2` and shows the answer. But I have “lost” the REPL.

---

<div class="post-metadata">

**Author:** ![FirstnameLastname](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firstnamelastname/32/6648_2.png) [@FirstnameLastname](https://discourse.julialang.org/u/FirstnameLastname)\
**Post date:** [March 28, 2020, 2:37pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/6 "2020-03-28T14:37:34Z")

</div>

I’m using `vim` + `tmux` like this

 ![2020-03-28_21-33](https://global.discourse-cdn.com/julialang/original/3X/8/3/83f9f5a6d320958dfb92898effe00de1ba327454.png)

On the left hand side is the `REPL`, right hand side is `vim`.  
Cells (similar to `matlab` cells) in the `.jl` file are separated by `##`. Each time I send `<Leader> c`, the code in the current cell is sent to the `REPL`.

To get this feature, you need the following plugins (using `vim-plug` to install):

```plaintext
Plug 'jpalardy/vim-slime', { 'for': ['python', 'julia']}
Plug 'hanschen/vim-ipython-cell', { 'for': ['python', 'julia'] }
Plug 'JuliaEditorSupport/julia-vim'

```

You also need to modify the `vim-ipython-cell` plugin a bit to make it recognize julia. Let me know if you struggle there, I will upload my config files.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 3:15pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/7 "2020-03-28T15:15:44Z")

</div>

I have installed the three plugins but I am no using `tmux`. I am using simply `iTerm` on Mac.  
I tried the command `:SlimeSendCurrentLine` on a `Julia` file and `:SlimeConfig` without any success. And also `C-c, C-c` does not work. Any suggestion?

---

<div class="post-metadata">

**Author:** ![FirstnameLastname](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firstnamelastname/32/6648_2.png) [@FirstnameLastname](https://discourse.julialang.org/u/FirstnameLastname)\
**Post date:** [March 28, 2020, 4:09pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/8 "2020-03-28T16:09:18Z")

</div>

My best suggestion is that you should use `tmux` 🤣. It’s just a CLI app like `vim` which makes `vim` much more powerful. In case you don’t want, you can try this:

- In command mode, run `:vsplit term://zsh` (or `:vsplit term://bash` depending on the shell you’re using).
- Open julia REPL in the opened pane.

You need to config `vim-slime` so that it will send the code to `vim terminal` pane. The config detail can be found in the github repo of `vim-slime`, find this section:

 ![2020-03-28_21-33](https://global.discourse-cdn.com/julialang/original/3X/2/2/22c7778c12077c9f7de027fcfd421a62d3f2656c.png)

Maybe just run `:SlimeConfig` and follow the setup is enough. I’m not using `vim terminal` so I’m not sure.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 4:38pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/9 "2020-03-28T16:38:18Z")

</div>

Sorry for my ignorance 🙂 I am learning `tmux` but I am not still there.  
I tried `:vsplit term://zsh`on `iTerm` with success. But I don’t know how to open Julia REPL in the opened pane, since it is a `vim` editor pane.  
I also configured `.vimrc` to send code to `vim terminal`.  
But still I can’t run `:SlimeConfig` since `Vim` gives me a `not an editor command` error.

---

<div class="post-metadata">

**Author:** ![FirstnameLastname](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firstnamelastname/32/6648_2.png) [@FirstnameLastname](https://discourse.julialang.org/u/FirstnameLastname)\
**Post date:** [March 28, 2020, 5:33pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/10 "2020-03-28T17:33:44Z")

</div>

I don’t know if the new pane you opened look like this:

 ![2020-03-29_00-31](https://global.discourse-cdn.com/julialang/original/3X/f/2/f2c20d2d8cbc7d0e806954e6a82755fd2827c3b9.png)

If so, you have to send `i` or `a` key inside that pane, to enter insert mode. Then you can use the shell to open julia REPL as usual.

Can you post a screenshot of the error when you run `:SlimeConfig`?

---

<div class="post-metadata">

**Author:** ![davide](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide/32/52136_2.png) [@davide](https://discourse.julialang.org/u/davide)\
**Post date:** [March 28, 2020, 5:51pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/11 "2020-03-28T17:51:54Z")

</div>

I am also using vim (actually nvim-qt) and tmux, running in two different windows, which maybe is simpler to set up and, for me, has a more flexible layout.

In one window I have nvim (nvim-qt);  
In a terminal I execute tmux and then julia.  
It doesn’t matter which one (vim or tmux+julia) you run first. Once you have both vim and julia running, you can execute julia code from vim with `ctrl-c-c`, which pass to julia REPL the block of commands delimited between empty lines, or the highlighted code.  
On first execution you are asked to choose “tmux socket name”: you can accept the default, and also the “tmux target pane”: just press enter.

To sum up, run vim/nvim in a terminal (or gvim or nvim-qt) and tmxu+julia in another terminal, which is accomplished with the following commands:

```julia
tmux
julia

```

Then, from vim, `ctrl-c-c`

That’s all.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 7:08pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/12 "2020-03-28T19:08:27Z")

</div>

OK. Now I’m using `tmux` on `iTerm2`. What follows is a screenshot of my terminal after trying to run `:SlimeConfig`.

 ![Screenshot 2020-03-28 19.04.15](https://global.discourse-cdn.com/julialang/original/3X/4/5/45e67e0701c32623aab12881f9aae6aa46200c34.png)

---

<div class="post-metadata">

**Author:** ![Xnartharax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xnartharax/32/13227_2.png) [@Xnartharax](https://discourse.julialang.org/u/Xnartharax)\
**Post date:** [March 28, 2020, 7:42pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/13 "2020-03-28T19:42:28Z")

</div>

I am trying to set it up along and you havent succesfully installed vim-slime. I had problems using vim plug so I switched to pathogen. Also I am not using ipython-cells (just slime). I do have a problem configuring slime to send to the second tmux pane though.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 8:00pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/14 "2020-03-28T20:00:26Z")

</div>

You’re right. I didn’t install `pathogen.vim `. I read something about it and I think that it is a lot difficult to install.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 28, 2020, 8:00pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/15 "2020-03-28T20:00:42Z")

</div>

Is there something similar for tiling window managers instead of iterm or tmux?

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 8:04pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/16 "2020-03-28T20:04:03Z")

</div>

Yes that was what I did. See [https://coderwall.com/p/el3fbg/split-window-with-iterm-2](https://coderwall.com/p/el3fbg/split-window-with-iterm-2)

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [March 28, 2020, 8:15pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/17 "2020-03-28T20:15:43Z")

</div>

> [@chakravala](#):
>
> Is there something similar for tiling window managers instead of iterm or tmux?

I use vim with [vim-slime](https://github.com/jpalardy/vim-slime) and [kitty](https://github.com/kovidgoyal/kitty) in [i3wm](https://i3wm.org) (and [coc](https://github.com/neoclide/coc.nvim) to have some nice [LanguageServer.jl](https://github.com/julia-vscode/LanguageServer.jl) features).

Edit: I just looked again into the options of vim-slime and found [dtach](https://github.com/jpalardy/vim-slime#dtach) to also work nicely with a tiling window manager.  
Edit2: The current implementation of vim-slime for kitty uses [remote control within windows](https://sw.kovidgoyal.net/kitty/remote-control.html), but alternatively it would be interesting to use it via something like `kitty -o allow_remote_control=yes --listen-on unix:/tmp/mykitty` and then from within vim `kitty @ --to unix:/tmp/mykitty send-text "bla"`.

---

<div class="post-metadata">

**Author:** ![Xnartharax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xnartharax/32/13227_2.png) [@Xnartharax](https://discourse.julialang.org/u/Xnartharax)\
**Post date:** [March 28, 2020, 8:25pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/18 "2020-03-28T20:25:42Z")

</div>

I got my setup working by now:

1. Install pathogen ([https://github.com/tpope/vim-pathogen](https://github.com/tpope/vim-pathogen)) and vim-slime ([https://github.com/jpalardy/vim-slime](https://github.com/jpalardy/vim-slime))
2. open tmux and make a second pane (Ctrl-b + %) and open a julia REPL in it (switch back to the first after that)
3. Configure vim-slime to send to the second pane of the first window (ID: 0.1) according to [https://github.com/jpalardy/vim-slime#tmux](https://github.com/jpalardy/vim-slime#tmux)
4. Send your code to julia with ( 2x Ctrl + c)

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [March 28, 2020, 11:25pm UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/19 "2020-03-28T23:25:46Z")

</div>

I have installed `pathogen` and `vim-slime`; I opened tmux using iTerm2 on Mac and made a second pane.  
I have inserted the following lines on my `.vimrc`.

```julia
let g:slime_target = "tmux"
let g:slime_default_config = {"socket_name": "default", "target_pane": "{right-of}"}

```

and now it works finally.

---

<div class="post-metadata">

**Author:** ![jessebett](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jessebett/32/2006_2.png) [@jessebett](https://discourse.julialang.org/u/jessebett)\
**Post date:** [April 13, 2020, 4:26am UTC](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636/20 "2020-04-13T04:26:55Z")

</div>

@jbrea could you point to some resources for setting up `coc` with `LanguageServer.jl`?

Would be really nice if it was as easy as the other [coc extensions](https://github.com/neoclide/coc.nvim/wiki/Using-coc-extensions#implemented-coc-extensions).

[Next page](https://discourse.julialang.org/t/julia-vim-tutorial-for-newbies/36636.md?page=2)
