Vim syntax highlighting for Dockerfiles

By default Vim offers on the Mac OS X no syntax highlighting for Dockerfiles. With a few steps you can change that. At the end of this tutorial you can also install additional PlugIns!

Prepare .vimrc

# create or modify .vimrc
$ vim ~/.vimrc
set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" add plugins here...
Plugin 'VundleVim/Vundle.vim'
Plugin 'docker/docker' , {'rtp': '/contrib/syntax/vim/'}

call vundle#end()
filetype plugin indent on

set ruler
syntax enable

Install and enable PlugIns

# start Vim
$ vim

# install and enable Vim PlugIns

# quit vim

# show installed Vim PlugIns (optional)
$ ls -la ~/.vim/bundle/

Create templates for Vim

Developers should follow not only the rules and processes of quality assurance. They must also have advantages for motivation from QA! As QA, you can already achieve more with less. Templates would be a possibility. This guide shows you how to deploy templates for Vim.


In order to provide templates, check if the personal vimrc file exists. Do not use the global vimrc! Whatever you configure in the personal vimrc file will overrule any setting in the global vimrc file.

# start vim
$ vim

# the global vimrc file can found by
:echo $VIM

# the home directory can found by
:echo $HOME

# the personal vimrc can found by
:echo $MYVIMRC

# exit vim

# if no personal vimrc exists
$ touch /home/<user>/.vimrc

# create folder for templates
$ mkdir /home/<user>/templates

Create some templates

Now place some files with in the templates directory.

<!DOCTYPE html>
<html lang="">
	<meta charset="UTF-8">
	<meta name="description" content="">
	<meta name="author" content="">
	<meta name="keywords" content="">
	<meta name="robots" content="noindex,follow" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="" type="text/css" rel="stylesheet" />
	<!-- Content goes here... -->
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Missing docstring"""

class Lorem(object):
    """Missing docstring"""
    def __init__(self):
        """Missing docstring"""

if __name__ == '__main__':

and so on… . Open the personal vimrc file and add the following auto-command.

# open personal vimrc
$ vim /home/<user>/.vimrc

# change into insert mode

# add command
autocmd BufNewFile * silent! 0r $HOME/templates/%:e.tpl

# exit insert mode

# store change and close

Whenever a Developer create now a new file, Vim looks for a template that matches the extension of the file. If there is no template for the file type, then Vim simply creates an empty file as usual.

My vimrc example

" Set color scheme
colorscheme peachpuff

"Show current position
set ruler

" Enable syntax highlighting
syntax enable

" Set standard encoding
set encoding=utf8

" Set standard file type
set ffs=unix,mac,dos

" Use spaces instead of tabs
set expandtab

" Use smart tabs
set smarttab

" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4

autocmd BufNewFile * silent! 0r $HOME/templates/%:e.tpl