我继承了几个使用以下语法从一个字符串读入数组的bash脚本:
read -a arr <<<$line
Run Code Online (Sandbox Code Playgroud)
但是,这会导致vim中的颜色格式化.有人可以建议快速修复吗?
更新:
忽略脚本的内容,但请注意'<<<'字符后的颜色变化(即echo语句为紫色):
如果#!/bin/bash缺少shebang线,就会发生这种情况.Vim将脚本解释为plain sh而不是bash.<<<是一种打击主义.
来自sh.syntax:
" trying to answer the question: which shell is /bin/sh, really?
" If the user has not specified any of g:is_kornshell, g:is_bash, g:is_posix, g:is_sh, then guess.
if !exists("g:is_kornshell") && !exists("g:is_bash") && !exists("g:is_posix") && !exists("g:is_sh")
let s:shell = ""
if executable("/bin/sh")
let s:shell = resolve("/bin/sh")
elseif executable("/usr/bin/sh")
let s:shell = resolve("/usr/bin/sh")
endif
if s:shell =~ 'bash$'
let g:is_bash= 1
elseif s:shell =~ 'ksh$'
let g:is_kornshell = 1
elseif s:shell =~ 'dash$'
let g:is_posix = 1
endif
unlet s:shell
endif
Run Code Online (Sandbox Code Playgroud)
和
" Here Strings: {{{1
" =============
" available for: bash; ksh (really should be ksh93 only) but not if its a posix
if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("g:is_posix"))
syn match shRedir "<<<" skipwhite nextgroup=shCmdParenRegion
endif
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
298 次 |
| 最近记录: |