Julia syntax highlighting in julia-vim

前端 未结 3 1576
一生所求
一生所求 2021-02-19 16:01

I use gvim with julia-vim for editing julia code. I am using julia 0.5 on a mac and installed julia-vim with vundle.

My problem is that files with the .jl

相关标签:
3条回答
  • 2021-02-19 16:32

    .jl files are sometimes recognized as lisp files by default, (blame Sawfish) so that's probably the syntax highlighting you're getting. (type defun and progn and etc and see if the pretty colors pop up)

    You were close when you said the correct solution was :set syntax=julia, what you need is to set filetype plus some autocmd magicks to make that happen every time you open a .jl file.

    Put something like this in some file (e.g. jl.vim) in your ftdetect directory:

    autocmd BufRead,BufNewFile *.jl :set filetype=julia
    

    And that should do it.



    Addendum 1: Changing filetype instead of syntax may be required to trigger additional features like the LaTeX expansions depending on the root of your problem, so that's what I am using.


    Addendum 2: Note that this should've been handled by the julia-vim plugin, but conflicts with other scripts can mess with that. You can use :scriptnames to see what scripts have been loaded and in what order, and try to debug what could be causing the conflict, if you think that's worth the trouble.


    Addendum 3: Also related is that Vundle has some specific configurations that need to be made when it comes to filetypes, so that could also be causing this. However, I've seen this and similar problems happen outside Vundle for any number of reasons so I still believe that the solution at the top is the best one, and will possibly prevent some future headaches.

    0 讨论(0)
  • 2021-02-19 16:43

    After testing julia-vim I think the issue is likely with the color scheme you are using.

    Try using a different one.

    :colorscheme desert

    I tried it with the built-in desert and both if and for were highlighted (see below).

    0 讨论(0)
  • 2021-02-19 16:50

    I found that the instructions here worked a treat. Namely

    git clone git://github.com/JuliaEditorSupport/julia-vim.git
    mkdir -p ~/.vim
    cp -R julia-vim/* ~/.vim
    

    Note: I realise that the OP claims to have already installed Julia-Vim using Vundle, but I came to this question because Vim was automatically using LISP syntax highlighting for me, and the above was enough for me. So I am sharing in case anyone comes from the same boat as me (i.e. the problem is not Vundle related) :)

    0 讨论(0)
提交回复
热议问题