Tag Archives: ide

Vim for Julia — Another Look

By: DSB

Re-posted from: https://medium.com/coffee-in-a-klein-bottle/vim-for-julia-another-look-1dc4265bb49b?source=rss-8bd6ec95ab58------2

Vim for Julia — Another Look

LunarVim as a Julia IDE

In the past, I wrote on how to use Vim for Julia. Recently, I’ve changed my setup and I’ve been using the new and amazing LunarVim. Here is a brief tutorial on how to setup Vim (actually Neovim) as your Julia IDE.

Introducing LunarVim

The first question to be answered is, what is LunarVim? Presto!

LunarVim is an opinionated, extensible, and fast IDE layer for Neovim >= 0.5.0. LunarVim takes advantage of the latest Neovim features such as Treesitter and Language Server Protocol support.

In simpler words, it’s a series of default configurations for Neovim that makes it even more amazing. The first requirement to use LunarVim is to install Neovim with version at least 0.5. Unfortunately, the sudo apt install neovim will not work (at the time I’m writing this), because the version installed will be lower than the required one.

An easy way to install a proper version is to add the PPA for the unstable version and install it. Here are the easy steps:

sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt update
sudo apt install neovim

To install LunarVim, just run:

bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh)

By running the command lvim in your terminal, LunarVim should start! You can always add alias vim = "lvim" to your .bashrc , to run LunarVim instead of vim.

Setting up Julia

Now that you’ve got LunarVim working, let’s setup the Julia language. This is actually surprisingly simple. In your terminal, run the following:

julia --project=~/.julia/environments/nvim-lspconfig -e 'using Pkg; Pkg.add("LanguageServer")'

This installs the Language Server Protocol (LSP) for Julia, i.e. the auto-completion functionally for Julia. Now, every time you open a “.jl” file, just wait a bit and the LSP will start.

Next, let’s install the Julia-Vim package that will enable us using Unicode, thus, by writing something like \alpha and pressing tab, we’ll get the alpha Unicode, which is allowed in Julia. To do this, go to your LunarVim configurations file, which can be accessed by running lvim in the terminal and selecting the Configuration option. Another way is to open the configuration file directly, which is ~/.config/lvim/config.lua .

Inside the configuration, there is a place where you can easily install any plugin you want. Just navigate to where the “- – Additional Plugins” is. Originally, everything should be commented. Just uncomment the necessary lines, and write {"JuliaEditorSupport/julia-vim"} and save. This will prompt the installation of the plugging. Take a look at the figure below.

This is what your configuration should look like to install Julia-Vim. Note that you can add any other plugins you like.

Word of Caution!

Since Vim is inside your terminal, you need your terminal to have a font with Unicode enabled. I suggest you install JuliaMono, a beautiful font created for Julia :D. Once the font is installed, just go into your terminal configuration and change to it.

Even with Unicode font enabled, in my notebook, the Julia-Vim was still freezing after pressing Tab without any text. To solve this issue, I wrote the following two commands in my LunarVim configuration:

vim.cmd("let g:latex_to_unicode_tab = 'off'")
vim.cmd("let g:latex_to_unicode_keymap = 1")
Screenshot of my own configuration file.

Now everything should be working beautifully! Your new LunarVim IDE for Julia is ready to be used.

Fast Course on LunarVim + Julia

You can now read the documentation on LunarVim to better understand some of the default settings. But, I’ll give some tips on how LunarVim works, and how to use it with Julia to run your code. Here is a (very) fast course on some of the main commands for LunarVim:

  • In LunarVim, your <leader> is the space , hence, many short cuts will be composed of pressing “space” followed by something else. Here is where LunarVim comes shining. If you just press “space” and wait a bit. A menu will pop-up from below, showing possible commands.
  • LunarVim comes with “NerdCommenter” plugin, which allows you to navigate with a menu. Just press <space>+e .
  • Once you open another file, a buffer is created and shown in the top of the screen . You can click on the tab to change buffers, or you can press shift+h or shift+l to change buffers.
  • Press ctrl+w to see the commands related to splitting screen and moving between screens. You can press ctrl+ h,l,j,k to move between windows.
  • As in regular Vim, you can press / to start searching and then space+h clears the highlighted terms in the search.
  • When you open a Julia file, you just need to wait a bit for the LSP to start working. Once the LSP is loaded, auto-completion will be working, and many other helpful features, such as visualizing the docstring of a function. For that, press g and a window will pop-up with many shortcuts related to the LSP. For example, you can press g + p to take a peek at the docstring and g + d to actually open the function definition in another buffer. Look the figures below.
  • Lastly, you can press ctrl+t to open and minimize a floating terminal. Once this is done, you can run the Julia REPL and copy/paste every line of code you want to run.

There are many other helpful commands. Check-out the documentation on LunarVim or try them out by yourself to learn more. Hope this was helpful.

Check out my Github for the complete configuration file.


Vim for Julia — Another Look was originally published in Coffee in a Klein Bottle on Medium, where people are continuing the conversation by highlighting and responding to this story.

Vim for Julia

By: DSB

Re-posted from: https://medium.com/coffee-in-a-klein-bottle/vim-for-julia-18eba071c654?source=rss-8bd6ec95ab58------2

An easy setup for Vim as Julia IDE (on Ubuntu)

As someone who has been a Vim user for years, I can confidently say that Vim is highly addictive. Once you get used to it’s shortcuts, editing code without it becomes unbearable. Although many tutorials exist on how to setup a Vim IDE for Python and other languages, no tutorial seems to be available for using Vim with Julia. So this might be a first.

By no means this article is comprehensive, I intend to present a very neat and fast way of using Vim with Julia. Note that there are many alternatives to using “pure Vim”, one can code using Juno and install the vim-mode package in Atom. The method I propose is using “pure Vim”, but with the very cool SpaceVim.

If you are new to Vim, and is trying to learn it, you probably realized that Vim has thousands of plugins available, and setting up your “IDEish” Vim may be quite complicated. One has to learn how to install plugins, choose color highlighting themes, and much more. Here is where SpaceVim comes in.

SpaceVim is a Vim distribution that works pretty much like an IDE, with some of the most popular plugins already installed. It also comes with some preset shortcuts, allowing for a more efficient file navigation. And most importantly, it looks beautiful.

Installing Vim and SpaceVim

The first thing to do is to install Vim… Well, actually, NeoVim. If you are not familiar with NeoVim, it is pretty much an updated Vim. So why use it? The only reason is that in my experience, it just works better with SpaceVim and Julia, and also, I like the cursor better. But feel free to go with Vim if you prefer it. The commands below install NeoVim and then SpaceVim.

sudo apt install neovim
curl -sLf https://spacevim.org/install.sh | bash

To access NeoVim from the terminal, you just need to write

nvim “example.txt”

If like me, you prefer to use the common “vim” command, then you can create an alias.

If you are using bash (the standard shel), open the file ~/.bashrc and write alias vim="nvim $argv".

If you are using fish, then on the terminal write

function vim
nvim $argv
end

This will create a function called “vim” in the fish shell. Then run the command funcsave vim , to save the function so it becomes permanant.

When you run Vim for the first time after installing SpaceVim, you will note that some plugins will be installed. By the end of the installation, you might get an error message about “vimproc”. To fix this, go into the command line of Vim by typing : , then write VimProcInstall .

Example on running VimProcInstall to fix possible error messages.

Setting up Julia

To set up Julia now is incredibly simple. If a plugin is already available in the SpaceVim “ecosystem”, you just need to add that plugin to your init.toml file, which is located in your home directory inside the folder .SpaceVim.d , and SpaceVim will install it for you.

Hence, to install the packages for dealing with Julia, just open ~/.SpaceVim.d/init.toml and write the following in the end of the file

[[layer]]
name= "lang#julia"

You might also want to add

[[layer]]
name= "colorscheme"

The code above will enable different colorschemes, which can be chosen by altering the attribute colorscheme.

This is it. You now have a Vim IDE for Julia!

Example of file ~/.SpaceVim.d/init.toml — Note that the ‘autocomplete’ layer is disabled. This is due to some incompatibility between the Julia packages and the autocomplete package. At the end of this article I present a fix for this problem.

Tips on using SpaceVim

There are tons of tutorials on how to use Vim, so I will not go into that. But there is not as much information on using SpaceVim. So I’ll give you some tips on how to get started.

  • Installing Plugins: I’ve already talked about how to install different plugins. You just have to pretty much add a layer to your init.toml file. Here is a list of the available plugins for SpaceVim;
  • Navigating file: the NerdTree plugin is already shipped with SpaceVim, so one just needs to press F3 to open the navigation menu. You can press l to go inside a folder, or h to go out of the folder;
  • <Leader> and SPC: If you read the documentation of SpaceVim, you will likely encounter shortcuts such as SPC <Tab> . The SPC stands for “space bar”. The <Leader> default key is \ ;
  • Commenting line: To comment a line, just do SPC c l (space bar + c +l), and SPC c l ;
  • Copy to system clipboad: A common difficulty to people starting with Vim is the fact that you cannot easily copy text from Vim to a another file not opened on the same Vim window (e.g your Browser). SpaceVim solves this to you, just use <Leader> y to copy to your system clipboard, and <Leader> p ;
  • Moving from Buffers (tabs): If you are working on a file, then press F3 and open another file, a new buffer will become active. You can then press SPC <Tab> to change buffers, therefore, easily going from one file to another. Amazingly, the buffers will be shown on the top of Vim, and you can actually just click on them if you want (but if you are using Vim, you probably don’t want to be using your mouse).
Image showing the different buffers of files opened.

If you like this article or has suggestions on how it could be improved, consider “Clapping” or leaving a comment, so I can get some feedback.

UPDATE: When using SpaceVim with Julia autocompletion, you might experience some freezing when pressing the Tab . This is due some incompatibility between the julia-vim package and the other autocompletion packages present on SpaceVim. To solve this issue, you may disable the Latex unicode tab command in the julia-vim package. To do this, open the file ~./SpaceVim/autoload/SpaceVim/layers/lang/julia.vim . And disable the following command.

let g:latex_to_unicode_tab = 0


Vim for Julia was originally published in Coffee in a Klein Bottle on Medium, where people are continuing the conversation by highlighting and responding to this story.

Vim as IDE for Julia

By: serhatcevikel

Re-posted from: http://www.serhatcevikel.com/?p=56

Despite being introduced recently (in 2012), Julia is growing in popularity as a general programming language and especially as a powerful tool in data analytics. Julia combines the productivity of interpreted languages such as R and Python and the efficiency of compiled languages such as C, C++ and Fortran and hence overcomes the “two language problem”.  Benhcmarks show that Julia performance is quite near that of C with the help of its powerful JIT compiler. The package base is quickly keeping up pace with the large bases of more established languages. The compiled assembly code of Julia code can be easily viewed from within its interactive shell (and its low level efficiency can be witnessed).

There are several ways to edit and run Julia code. The Jupyter notebook “IJulia” is the easiest one to deploy:

julia> Pkg.add("IJulia")
julia> using IJulia
julia> notebook(detached=true)

These commands will start a Julia kernel inside the default browser, and will persist even if Julia shell is exited. The notebook is good for prototyping short code snippets and executing them as block “cells”. However for larger and more complex coding tasks, an integrated development environment (IDE) is preferred.  “Getting Started with Julia”,  a comprehensive beginner’s resource for the language  by Ivo Balbaert, mentions the IDE options available for Julia as Julia Studio, Sublime-IJulia and Juno.

GUI based IDE’s usually absorb a large portion of the valuable CPU cycles and RAM that would otherwise be available for resource hungry data analytics tasks. For those coders who devote scarce computer resources to data tasks, lightweight solutions are preferred. Vim is among the most popular lightweight text editors and is highly versatile in a variety of languages due to its large base of plugins/extensions. For a coder who gets used to the practical key bindings, Vim acts as a natural extension of the body.

Although there are some extensions to be installed for Julia, for those who are used to work with Vim editor, there is not yet an integrated extension such as Nvim-R that combines Vim and R in a seamless manner. However several open-source extensions and applications can be combined to create a working environment for Julia through which you can edit Julia code with syntax highlighting and execute selected portions of the code inside the interactive shell.

As also mentioned in “Getting Started with Julia”, julia-vim plugin is a good starting point, but we have to combine it with some other resources to create an efficient environment.  The prerequisites for the recipe are:

Most of the prerequsites are available in repositories of mainstream Linux distributions or can be downloaded and installed from the source code repositories following the links.

We need the terminal multiplexer so that, both the code editor and interactive shell can be viewed at the same time ,  julia-vim plugin for Julia syntax highlighting in Vim and vim-slime plugin to send the Julia code from the Vim editor to interactive shell to be interpreted/compiled (not only for Julia, but any language with a REPL shell).

The default terminal multiplexer for vim-slime is GNU Screen and the below scripts will utilize it.  However the option can be changed to Tmux easily by:

let g:slime_target = "tmux"

command from the Vim editor or appending to .vimrc file.

After the installations, we first create the steps that GNU screen will follow when invoked from a shell script:

layout new
split -s
screen 0
exec vim
focus next
screen 1
exec julia
focus next
layout save default

We will save these steps into a file (named “screenjulia” in my example) that will be invoked by the -c argument of screen command in order to override the default configuration and create a new layout for the session. The file creates a new layout, splits the screen session horizontally, names the upper region as “0” and executes vim inside (the julia filename will be appended by the script), names the lower region as “1” and executes Julia inside.

Due to difficulties to pass arguments to the custom configuration file, the optional filename argument will be inserted by the script, if provided:

#!/bin/bash
# vim-julia-slime binder
sed -i "s/^exec vim.*$/exec vim $1/" /path/to/screenjulia
screen -S 1 -c /path/to/screenjulia

The sed command inserts the Julia filename if provided by the optional $1 argument to the end of “exec vim” line in the configuration file “screenjulia” (replace “/path/to/screenjulia” with your actual path). The default session name for screen is “1”.

In order to enable the Julia syntax highlighting feature, the filename must have a .jl extension. To enable these features, it is useful to add the following lines into the .vimrc file:

filetype plugin indent on
syntax on

Also enabling line numbers will simplify the line selection in visual mode, so it should also be added to the .vimrc file:

set nu

To use this script as a custom command, it should be made executable and a symlink pointing to the file should be created inside a location that is declared in the $PATH environment variable of your .bashrc or /etc/environment (such as /usr/bin) (replace /path/to/script with your actual path to the script file):

$ chmod +x /path/to/juliascriptname
$ sudo ln -s /path/to/juliascriptname /usr/bin/juliascriptname

Now, invoking the scriptname (replace it with any name you’d like for your command) command from anywhere will initiate the following layout:

$ juliascriptname juliafilename.jl

The code lines are selected in visual mode in Vim and sent by C-c, C-c command (insert mode should be exited) – simply holding CTRL and double tapping c. In each session, the first time this sequence is entered, Vim will prompt for screen session and window name. The default values as defined in our script are 1 and 1. Anytime you can change these values with C-c, v or :SlimeConfig.

The visual mode works by v for character-wise and V for line-wise selections. Without any selection, C-c, C-c binding will send the current block. vip command also selects the current block or paragraph. To be more precise in the line range of code, you should enter VXgg where X is the number of last line to be selected (set nu option in .vimrc file is important in this sense)
With a small code sample for demonstration purposes, selecting first 3 lines with V3gg from Vim and sending to Julia window by C-c, C-c result in:

The switch between panes you should use C-a [tab] and the complete layout can be exited through screen by C-a \ binding.

With an Nvim-R like plugin, vim + Julia can be integrated better with autocompletion and an object browser.