Julia-Vim tutorial for newbies

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.

4 Likes

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.

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

3 Likes

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.

4 Likes

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.

I’m using vim + tmux like this

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):

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.

22 Likes

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?

My best suggestion is that you should use tmux :rofl:. 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:

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

1 Like

Sorry for my ignorance :slight_smile: I am learning tmux but I am not still there.
I tried :vsplit term://zshon 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.

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

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?

3 Likes

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:

tmux
julia

Then, from vim, ctrl-c-c

That’s all.

3 Likes

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

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.

1 Like

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.

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

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

I use vim with vim-slime and kitty in i3wm (and coc to have some nice LanguageServer.jl features).

Edit: I just looked again into the options of vim-slime and found dtach to also work nicely with a tiling window manager.
Edit2: The current implementation of vim-slime for kitty uses remote control within windows, 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".

2 Likes

I got my setup working by now:

  1. Install pathogen (https://github.com/tpope/vim-pathogen) and 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
  4. Send your code to julia with ( 2x Ctrl + c)
4 Likes

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.

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

and now it works finally.

3 Likes

@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.