CFEngine vim hilighting

Get the highlighting code from https://github.com/neilhwatson/vim_cf3, and set it up in a location that will be loaded by default.  I’m partial to making  directory under /usr/local/share, and then linking the files in.

sudo git clone git://github.com/neilhwatson/vim_cf3.git /usr/local/share/vim_cf3
for D in /usr/local/share/vim_cf3/*; \
 do [[ -d $D ]] || continue; \
 sudo ln -s $D/* /usr/share/vim/vim72/$(basename $D)/; \
 done

Add these lines to /etc/vimrc:

" set CFEngine file type
autocmd BufRead,BufNewFile *.cf set ft=cf3
" Default to unfolding all folds on open
autocmd BufRead,BufNewFile * normal zR

I hate having keyword expansion turned on by default.  There’s a parameter provided that you can add to vimrc to turn that off, but just on the principle of the thing, I’d rather have it default to “off” when installed as a global file, and allow individual users to turn it on if they really want to have their editor change things on them.  Here’s a patch against ftplugin/cf3.vim.  It’ll break if the file is updated in git at some point, but my hope is that, one day, I can get Neil convinced that this should be off by default. :)

(update: it was merged in.  The following is no longer needed)

You can run this with copy-paste by running “cat – | patch -p0 cf3.vim” and pasting this in, then hitting +D.

@@ -23,7 +23,7 @@
 
 " =============== Keyword Abbreviations  ===============
 " disable keyword abbreviations with by adding 
-" "let g:DisableCFE3KeywordAbbreviations=0" to your vimrc
+" "let g:EnableCFE3KeywordAbbreviations=0" to your vimrc
 " Conveniance function ToggleCFE3KeywordAbbreviations
 " mapped to ,i by default to toggle abbreviations off or on
 "
@@ -76,18 +76,18 @@
 endfunction
 
 " Default abbreviations on
-" to disable let g:DisableCFE3KeywordAbbreviations=1 in ~/.vimrc
-if !exists('g:DisableCFE3KeywordAbbreviations')
-    let b:DisableCFE3KeywordAbbreviations=1
+" to disable let g:EnableCFE3KeywordAbbreviations=1 in ~/.vimrc
+if exists('g:EnableCFE3KeywordAbbreviations')
+    let b:EnableCFE3KeywordAbbreviations=1
     call EnableCFE3KeywordAbbreviations()
 endif
 
 function! ToggleCFE3KeywordAbbreviations()
-    if !exists('b:DisableCFE3KeywordAbbreviations')
-        let b:DisableCFE3KeywordAbbreviations=1
+    if exists('b:EnableCFE3KeywordAbbreviations')
+        let b:EnableCFE3KeywordAbbreviations=1
         call EnableCFE3KeywordAbbreviations()
     else
-        unlet b:DisableCFE3KeywordAbbreviations
+        unlet b:EnableCFE3KeywordAbbreviations
         call DisableCFE3KeywordAbbreviations()
     endif
 endfunction

  1. Danny says:

    There’s an updated version of the policy with the “change stuff silently” code (the abbreviation expansion and permission setting) disabled by default in my github fork at https://github.com/dannysauer/vim_cf3, which would be
    “git clone git://github.com/dannysauer/vim_cf3.git”
    and then ignore the last couple of paragraphs.

Leave a Reply