如何讓puppet代碼支援vim高亮顯示

來源:互聯網
上載者:User

puppet的pp設定檔還沒有被vim支援,編輯時候黑底白字,不容易排錯,看起來也不好分辨,須做進一步修改才能完美顯示

須在使用者根目錄下的.vim裡面添加2個檔案,具體如下:

1 vim目錄下建立syntax/puppet.vim:

#mkdir ~/.vim

#cd ~/.vim

#mkdir syntax

#vim syntax/puppet.vim

添加以下內容:

========================================================================

" puppet syntax file
" Filename: puppet.vim
" Language: puppet configuration file
" Maintainer: Dongwm<ciici1234@hotmail.com>
" URL:
" Last Change:
" Version:
"

" Copied from the cfengine, ruby, and perl syntax files
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

syn region puppetDefine start="^\s*\(class\|define\|site\|node\)" end="{"
contains=puppetDefType,puppetDefName,puppetDefArguments
syn keyword puppetDefType class define site node inherits contained
syn keyword puppetInherits inherits contained
syn region puppetDefArguments start="(" end=")" contains=puppetArgument
syn match puppetArgument "\w\+" contained
syn match puppetArgument "\$\w\+" contained
syn match puppetArgument "'[^']+'" contained
syn match puppetArgument '"[^"]+"' contained
syn match puppetDefName "\w\+" contained

syn match puppetInstance "\w\+\s*{" contains=puppetTypeBrace,puppetTypeName,puppetTypeDefault
syn match puppetTypeBrace "{" contained
syn match puppetTypeName "[a-z]\w*" contained
syn match puppetTypeDefault "[A-Z]\w*" contained

syn match puppetParam "\w\+\s*=>" contains=puppetTypeRArrow,puppetParamName
syn match puppetParamRArrow "=>" contained
syn match puppetParamName "\w\+" contained
syn match puppetVariable "$\w\+"
syn match puppetVariable "${\w\+}"
syn match puppetParen "("
syn match puppetParen ")"
syn match puppetBrace "{"
syn match puppetBrace "}"

syn region puppetString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable

syn keyword puppetBoolean true false
syn keyword puppetKeyword import inherits include
syn keyword puppetControl case default

" comments last overriding everything else
syn match puppetComment "\s*#.*$" contains=puppetTodo
syn keyword puppetTodo TODO NOTE FIXME XXX contained

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_puppet_syn_inits")
if version < 508
let did_puppet_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif

HiLink puppetVariable Identifier
HiLink puppetBoolean Boolean
HiLink puppetType Identifier
HiLink puppetDefault Identifier
HiLink puppetKeyword Define
HiLink puppetTypeDefs Define
HiLink puppetComment Comment
HiLink puppetString String
HiLink puppetTodo Todo
" HiLink puppetBrace Delimiter
" HiLink puppetTypeBrace Delimiter
" HiLink puppetParen Delimiter
HiLink puppetDelimiter Delimiter
HiLink puppetControl Statement
HiLink puppetDefType Define
HiLink puppetDefName Type
HiLink puppetTypeName Statement
HiLink puppetTypeDefault Type
HiLink puppetParamName Identifier
HiLink puppetArgument Identifier

delcommand HiLink
endif

let b:current_syntax = "puppet"

更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/soft/tools/

========================================================================

2. vim目錄下建立ftdetect/puppet.vim

#mkdir ftdetect

vim ftdetect/puppet.vim

添加以下內容:

========================================================================

au BufRead,BufNewFile *.pp setfiletype puppet

========================================================================

效果示範:

[root@viong]# vim /etc/puppet/manifests/site.pp

參考文檔:http://www.dongwm.com/archives/rangpuppetdaimazhichivimgaoliangxianshi/

本文出自 “技術在於折騰” 部落格,請務必保留此出處http://viong.blog.51cto.com/844766/894381

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.