How to use this setup

Suppose you want to edit a file (a.jl say) in neovim and run Julia at the same time.

  1. Start a tmux session (if not already started).

  2. Type J a.jl to split the tmux window vertically, launching neovim editing a.jl in the top window and running Julia in the bottom window.

  3. In the neovim window, type C-c C-c to send the code in present paragraph to Julia, or type <space>j to send just the current line. (By ‘paragraph’, I mean a block of code ended with a blank line or with the end of file.)

  4. Move from paragraph to paragraph, running each. Or, just don’t use paragraphs, in which case use either C-c C-c or <space>j, as you wish.


This requires editing some dot files. I am not going to explain the details of how this works, and I cannot claim that this will work on all systems.

Step 1: edit ~/.zshrc (or similar) file

If you use the Z shell, edit your ~/.zshrc file, adding the following (see e.g. References 1 and 2). (If you use another shell, edit the appropriate file in a similar way.)

function J() {
    tmux send-keys "vim $1" Enter \; \
    split-window -v \; \
    rename-window julia \; \
    send-keys "julia" Enter \; \
    select-pane -t 0 \;

Step 2: edit ~/.vimrc (or similar) file

Edit your ~/.vimrc file, adding the following to your Plug setup. I got much of this from references 1 and 2. The remapping of <Space>j is something I made up, corresponding to <Space>r in R mode.

" Slime
let g:slime_target = "tmux"
let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"}
let g:slime_dont_ask_default = 1
" Julia: make <Space>j run current line. Note that <C-c><C-c> runs paragraph.
autocmd Filetype julia xnoremap <Space>j :SlimeSendCurrentLine<cr>
autocmd Filetype julia nnoremap <Space>j :SlimeSendCurrentLine<cr>

References and resources


  2. starting at 15:52

  3. Jekyll source code for this blog entry: 2022-02-16-vim-jullia

This website is written in Jekyll, and the source is available on GitHub.