O'Reilly logo

Learning CFEngine 3 by Diego Zamboni

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix B. Editing CFEngine 3 Configurations in Vim

Neil H. Watson

Not to be outdone by Emacs, Vim can be equally productive in editing CFEngine files. Here I’ll show you how to set up and get started with the vim_cf3 plugin.

Setting Up

The vim_cf3 plugin can be found at https://github.com/neilhwatson/vim_cf3. Copy the relevant parts into your $HOME/.vim/ directory:

  • The file type plugin for file editing: $HOME/.vim/ftplugin/cf3.vim.

  • The syntax highlighting file: $HOME/.vim/syntax/cf3.vim.

  • The help file: $HOME/.vim/doc/cf3.txt.

  • The help directory and its contents: $HOME/.vim/snippets.

Here is a minimum .vimrc to make the plugin work and associate it with filenames ending in .cf:

      set smartindent
      set autoindent
      syntax on
      filetype plugin indent on

      :helptags ~/.vim/doc/
      au BufRead,BufNewFile *.cf set ft=cf3
      " enable vim_cf3 plugin abbreviations
      let g:EnableCFE3KeywordAbbreviations=1

      fun! Getchar()
        let c = getchar()
        if c != 0
          let c = nr2char(c)
        endif
        return c
      endfun

      fun! Eatchar(pat)
         let c = Getchar()
         return (c =~ a:pat) ? '' : c
      endfun

Getting Help

There is a Vim help file that comes with vim_cf3. In command mode, :help cf3 will call the help. You can also be more specific (for example, :help cf3abb) to call help about abbreviations.

Using the Plugin

Once the plugin is installed you can begin using it. Edit any exiting or new CFEngine file. The filename must end in .cf in order for the plugin to recognize it (you can also activate the plugin by hand on any file by executing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required