You may ignore this article if you are already an expert in vim as this is a quick note for those who are new to vim editor. As we know, Ansible is used by engineers from all platforms including Linux/Unix, Windows, Networking, DBA side, Developers, Middleware etc. And we know, that Ansible controlnode is available only for unix-based platforms so far. So handling playbooks is a headache as even a single white space in your playbook can spoil your entire day.
You have so many ways to edit a playbook – you can use any visual editor like atom, VSCode, Sublime etc or can sync with git or directly use GUI in Linux environment. And most of them have plugins for ansible as you can easily highlight syntax and understand the indentation.
But as a Linux user, my favourite editor is vim as I can make small changes and test the playbook instantly from CLI itself. See below, for how did I tune my vim variables to get an easy-to-understand look when I edit ansible playbooks.
Learn about vim parameters and variables for easy editing of the yaml or any file format where indentation is very important. See some of the examples shown below.
set et ts=2 ai sw=2 nu
set nu - show line number
set tabstop=4
set et
See some of the definitions below.
ts
: tabstop – eg: tabstop=2et
: expandtabsw
: shiftwidth – eg: shiftwidth=4sts
: softtabstop – eg: softtabstop=4nu
: show line numbercuc
: cursorcolumnEnable syntax
This is on by default in most of the cases but make sure.
syntax on
Choose your colorscheme
You can see the installed colorschemes
by typing :colorscheme
and then a space and press TAB in vim editor.
:colorscheme desert
Show Line Numbers
You must enable the line number visibility
set number
Make your cursor more visible
It would be great if you enable this as your current cursor position will be more visible.
set cursorline
Enable Indent Visibility
There are so many free plugins/codes to enable this and see I have used IndentLine by Yggdroot.
To set all items as permanent
Edit your ~/.vimrc file and add the below lines
autocmd FileType yaml setlocal et ts=2 ai sw=2 nu sts=0
set cursorline
Finally, see the vim editor with autoindent
, cursorline
, indentlines
, etc
You may refer this gist or this article for more details on vim customization.
Do you want to learn more about Ansible practical use cases? Check the latest book from the author as follows. Available on Packt and Amazon.
Disclaimer:
The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.
Tags: Ansible · Ansible Doc · customize vim · vim · vim editor
Gineesh Madapparambath
Gineesh Madapparambath is the founder of techbeatly and he is the co-author of The Kubernetes Bible, Second Edition. and the author of 𝗔𝗻𝘀𝗶𝗯𝗹𝗲 𝗳𝗼𝗿 𝗥𝗲𝗮𝗹-𝗟𝗶𝗳𝗲 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻.
He has worked as a Systems Engineer, Automation Specialist, and content author. His primary focus is on Ansible Automation, Containerisation (OpenShift & Kubernetes), and Infrastructure as Code (Terraform).
(aka Gini Gangadharan - iamgini.com)
This site uses Akismet to reduce spam. Learn how your comment data is processed.7 Responses
Leave a Reply Cancel reply
Hey , thanks !!!! very useful
[…] Read More : How to Setup Vim Editor […]
set cursorlin –> set cursorline
Thank you so much.
Corrected in article
if you dont use cuc then set cursorline doesn’t work
Yes, you are right!
Thank you for pointing that out. I will update the doc.
Hey Gineesh, thanks for the tips! Peace and blessings. 🤓👍