Julia-Vim tutorial for newbies

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.

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

I have julia v1.4.0 and LanguageServer v2.0.0 and this in my coc-settings.json (open in vim with :CocConfig)

{
"languageserver": {
  "julia": {
      "command": "julia",
           "args" : ["--startup-file=no", "--history-file=no", "-e",
                     "import Pkg; envpath = dirname(Pkg.Types.Context().env.project_file); const DEPOT_DIR_NAME = \".julia\"; depotpath = Sys.iswindows() ? joinpath(ENV[\"USERPROFILE\"], DEPOT_DIR_NAME) : joinpath(ENV[\"HOME\"], DEPOT_DIR_NAME); using LanguageServer; server = LanguageServerInstance(stdin, stdout, false, envpath, depotpath); run(server)"],
      "filetypes": ["julia"]
  }
}
}
3 Likes

Wow @jbrea this is very nice!

@FirstnameLastname Can you share your config to make it send cells to repl?

You can use this plugin made by @mroavi. It’s easier and cleaner than my setup.

6 Likes

@FirstnameLastname, I love how your setup looks. Are you able to share your config/dotfiles?

1 Like

Hi, what do you mean from within vim ‘kitty @ --to unix:/tmp/mykitty send-text “blah”’??

I have a jl file open, open a h-split and with Neoterm open a terminal. I want to use kitty-navigator (plug-in similar to Tmux-navigator, which is also a great plugin for those of you who wish to use Tmux) to move between screens but for whatever reason when I type your “blah” containing command into the new terminal I just get an error.

If everything is within the same kitty window I don’t think you need @ --to.
For some context where @ --to may be useful, see this issue.

Can’t you just use the :T command of neoterm for your setup?

I could, and do, but launching Julia from within a terminal within Nvim is actually slower than opening a new kitty window/pane within the kitty os window and launching a Julia repo from that. My MacBook is a good 8 years old at this point & I want to be as efficient as I can. (Hence the learned use of Neovim, Lua, and the terminal in general rather than relying on bloated VSCode… though I do use it from time to time when work just needs to be done). Side note: Figured increasing my cmd line fu would make me an overall better programmer/data sci dilettante than just learning one editor.

1 Like

In relation to many of these setups: I have been using the Vim \rightarrow vim-slime \rightarrow Julia REPL setup and it works great, especially with the Vim :term option as you can also then pass REPL lines back to Vim.

One non-criticial issue that persists is that sending lines that begin with tab characters (i.e. a lot of lines!) can freak out the REPL somewhat and cause it to dump all Base exports before executing a line. This becomes particularly overwhelming and gluggy when you try and send a big chunk or even the whole script file.

Has anyone else experienced this or come up with a nice way around it? I note that there are two related issues open on the Julia GitHub here and here. It seems to be tied to the fact that <tab> <tab> in an empty REPL “autocompletes” everything . I’ve tried playing around with tabs as spaces etc. but that makes it much harder to write readable code.

You can set

set tabstop=4
set shiftwidth=4
set expandtab

This way your code look exactly as if you use tab, but no actual tabs will be inserted.

2 Likes