วิธีง่ายๆในการเน้นไวยากรณ์สำหรับ Julia ใน Vim

Dec 29 2020

ฉันพยายามให้ Julia เน้นไวยากรณ์ใน Vim ขออภัยในขณะนี้ฉันไม่มีการเน้นไวยากรณ์ ( นี่คือตัวอย่างโค้ดของฉันเล็กน้อยเพื่อให้คุณสามารถดูได้ว่าปัจจุบันมีลักษณะอย่างไร ) ฉันลองติดตั้ง julia-vim แล้วใส่ลงในไฟล์. vimrc และติดตั้ง แต่มันไม่ได้เปลี่ยนการไฮไลต์ ด้านล่างนี้คือไฟล์. vimrc:

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

ฉันยังทราบวิธีแก้ไขหลังจากอ่านเอกสารของ julia-vimแล้ว ฉันทำอะไรไม่ถูกต้องหรือมีวิธีอื่นในการเพิ่มการเน้นไวยากรณ์ให้กับ Julia หรือไม่?

ฉันได้เห็นจากหนึ่งในคำตอบสำหรับคำถามนี้ที่ @Thomas ถามว่าอาจเป็นไปได้ว่าฉันตั้งค่าเทอร์มินัลของฉันอย่างไร แต่ฉันต้องการให้เทอร์มินัลมีโทนสีปัจจุบันถ้าเป็นไปได้ ดูที่นี่สำหรับการตั้งค่าปัจจุบันของฉัน

แก้ไข: ขอบคุณ @axwr ฉันสามารถเน้นไวยากรณ์ได้โดยการใส่

  syntax on

ที่ส่วนท้ายของไฟล์. vimrc จากนั้นเรียกใช้

   :so %

ขณะแก้ไขไฟล์. vimrc อย่างไรก็ตามดังที่คุณเห็นที่นี่การเข้ารหัสสีดูเหมือนจะน้อยกว่าที่เหมาะ เฉพาะบางแพ็คเกจเท่านั้นที่เป็นสีเหลืองส่วนใหญ่ยังคงเป็นสีเขียวและสิ่งที่สุ่ม (โดยปกติจะเป็นตัวเลข) จะปรากฏเป็นสีม่วง นี่เป็นสีของสิ่งที่ Julia-vim หรือฉันทำอะไรผิด?

คำตอบ

4 axwr Dec 29 2020 at 03:04

เอาล่ะ

มีสองขั้นตอนในการเน้นไวยากรณ์ในกลุ่ม; เปิดใช้งานได้จริงและมีความสามารถในการเน้นภาษาเฉพาะที่คุณต้องการใช้สำหรับกลุ่มภาษาส่วนใหญ่สามารถทำได้ตามค่าเริ่มต้นอย่างไรก็ตามบางภาษาเช่น Julia ต้องการความช่วยเหลือเล็กน้อย ในกรณีนี้คุณได้ทำขั้นตอนที่สองแล้วโดยใช้ vundle เพื่อติดตั้งปลั๊กอิน Julia

ในการบรรลุขั้นตอนที่หนึ่งคุณต้องมีบรรทัด: syntax onในไฟล์ vimrc ของคุณ ตัวอย่างขั้นต่ำสำหรับคุณอาจมีลักษณะดังนี้:

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

จากการตั้งค่าข้างต้นและเทอร์มินัลที่มี colorcheme "solarised" ไฟล์ julia จะมีลักษณะดังนี้:

นี่คือตัวอย่างเล็ก ๆ น้อย ๆ ของ fizzbuzz julia เพื่อให้คุณสามารถเปรียบเทียบกับไฮไลต์ของคุณ:

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

ทีละขั้นตอน:

  • เพิ่มsyntax onในไฟล์.vimrc
  • เพิ่มfiletype plugin indent onในไฟล์.vimrc
  • ติดตั้งปลั๊กอินที่เกี่ยวข้อง
  • หาแหล่งที่มาของคุณ.vimrcหรือปิดกลุ่ม
  • เปิดไฟล์ที่มีนามสกุลที่ถูกต้องเช่น: test.jl