Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy way to get syntax highlighting for Julia in Vim

I am trying to get Julia to have syntax highlighting in Vim. Unfortunately, at the moment, I there is no syntax highlighting (here is a small snippet of my code so you can see what it currently looks like). I tried installing julia-vim and putting it in the .vimrc file and installing it, but it doesn't actually change the highlighting. Below is the .vimrc file:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
  set rtp+=~/.vim/bundle/Vundle.vim
 call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
  Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
 Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
  Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own 
   plugin)
  Plugin 'file:///home/gmarik/path/to/plugin'
 " The sparkup vim script is in a subdirectory of this repo called vim.
 " Pass the path to set the runtimepath properly.
 Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
 " Install L9 and avoid a Naming conflict if you've already installed a
  " different version somewhere else.
 " Plugin 'ascenator/L9', {'name': 'newL9'}

 " All of your Plugins must be added before the following line
   call vundle#end()            " required
   filetype plugin indent on    " required
  " To ignore plugin indent changes, instead use:
  "filetype plugin on
  "
  " Brief help
  " :PluginList       - lists configured plugins
   " :PluginInstall    - installs plugins; append `!` to update or 
    just :PluginUpdate
   " :PluginSearch foo - searches for foo; append `!` to refresh local cache
   " :PluginClean      - confirms removal of unused plugins; append 
   `!` to auto-approve removal
   "

   Plugin 'JuliaEditorSupport/julia-vim'


  "
  "
  "
  " see :h vundle for more details or wiki for FAQ
  " Put your non-Plugin stuff after this line

I'm also note sure how to fix it after reading the julia-vim documentation. Am I doing anything incorrectly, or is there another way to add some syntax highlighting to Julia?

I have seen from one of the answers to this question asked by @Thomas that it might be how I have set up my terminal, but I'd prefer to keep the terminal with the present color scheme if possible. See here for my current settings.

EDIT: Thanks to @axwr, I was able to get some syntax highlighting by putting

  syntax on

at the end of the .vimrc file and then running

   :so %

while editing the .vimrc file. However, as you can see here, the color coding seems to be less than ideal. Only certain packages come up as yellow, the majority is still green, and random things (usually numbers) come up as purple. Is this how julia-vim colors things, or am I doing something wrong?

like image 353
Joshuah Heath Avatar asked Dec 28 '20 19:12

Joshuah Heath


People also ask

How do I turn on syntax highlighting in vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

Does vim support syntax highlighting?

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.

How do I highlight keywords in vim?

Press 1 to highlight the current visually selected text, or the current word (if nothing is selected). Highlight group hl1 is used. Press 2 for highlight hl2 , 3 for highlight hl3 , etc. Press 0 to remove all highlights from the current visually selected text, or the current word.


1 Answers

Okay, so.

There are two steps to syntax highlighting in Vim; actually turning it on, and, having the ability to highlight the specific language you want to work in. For most languages vim can do this by default, however some languages, like Julia, require a little help. In this case you have done step two by using vundle to install a Julia plugin.

To acheive step one, you just need the line: syntax on in your vimrc file. A minimal example vimrc for you, might look like:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'JuliaEditorSupport/julia-vim'
call vundle#end()

set nocompatible
set backspace=indent,eol,start
set number
set hidden

syntax on
filetype plugin indent on

Given the above settings, and a terminal that has the "solarised" colorscheme, a julia file looks like:

enter image description here

Here is the little fizzbuzz julia snippet so you can compare against your highlighting:

for i in 1:100
    if i % 15 == 0
        println("FizzBuzz")
    elseif i % 3 == 0
        println("Fizz")
    elseif i % 5 == 0
        println("Buzz")
    else
        println(i)
    end
end

So, Step by step:

  • Add syntax on to your .vimrc
  • Add filetype plugin indent on to your .vimrc
  • Install the relevant plugin
  • Source your .vimrc or close vim.
  • open a file with the correct extension, i.e: test.jl
like image 147
axwr Avatar answered Nov 15 '22 08:11

axwr