Bare minimum vim setup for YAML

I am spending my days with Ansible and Kubernetes. This means I am writing YAML files all day long. I invariably spend a significant portion of my working hours fixing indentations in the YAML files. I am sure this is the case with many DevOps engineers these days.

I found the following plugins vim-plug and indentLine. vim-plug is a minimalist Vim plugin manager. And indentLine is used for displaying thin vertical lines at each indentation level for code indented with spaces. I did set up both the plugins in the following way:

Edit the .vimrc file

Add the following lines to the .vimrc file to make sure that I use 2 spaces indentation from YAML file.

filetype plugin indent on
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab

Add the plugins .vimrc file to add both the plugins

call plug#begin()
Plug 'Yggdroot/indentLine'
call plug#end()

Final output:

Now when I was trying to edit a YAML file in vim, it is all indented (visually).

 12 ---
 11 - name: Apt update
 10   ansible.builtin.apt:
  9   ¦ update_cache: yes
  7 - name: Get list of updates
  6   ansible.builtin.command:
  5   ¦ cmd: apt list --upgradable
  4   register: update_list
  2 - name: Print the update_list
  1   ansible.builtin.debug:
13    ¦ msg: "{{ update_list.stdout_lines }}"

I hope this super minimal vim setup will be helpful to others.

Show Comments