Still using vi for Ansible? No problem!

Having grown up using vi as a main editor on UN*X systems, I still love it and often fire it up for quick demos etc. I can't think of any other software so long lived, loved and effective still!

I sometimes get asked for tips and tricks for using vi/vim for writing Ansible. I never got round to formally writing anything up, until now :)

Vi can be customised through a .vimrc config file.

I came across a cracking guide by Doug Black which covers all the bases and more. I recommend reading this to see if there's any other settings which could be useful for you.

Here's my config:

cat ~/.vimrc

" cracking guide at https://dougblack.io/words/a-good-vimrc.html
set tabstop=2                               " a tab = 2 spaces
set softtabstop=2                           " no. spaces on backspace
set expandtab                               " turn tabs into spaces
set autoindent                              " autoindent!
set wildmenu                                " autocomplete for filenames
set showmatch                               " parenthesis matching
syntax on                                   " syntax!
colorscheme default                         " add a little colour to our live
set incsearch                               " search as chars entered
set hlsearch                                " highlight matches
let mapleader=","                           " leader is a comma
nnoremap <leader><space> :nohlsearch<CR>    " leader,space disables search highlighting

Most of this should be self explanatory I hope. It is also available here

Enjoy.

I would also create a temporary directory for swap files (e.g. ~/.vim/tmp) and set the Working Directory for Vim to this directory in .vimrc : set directory^=$HOME/.vim/tmp/ This prevents vim's .swp files being created in the Git repo's you are working in.

Like
Reply

Still my primary editor! The vim plugins for graphical editors just aren’t the same.

Like
Reply

Nice one Phil Griffiths, I'll give some of these a try.

Like
Reply

To view or add a comment, sign in

More articles by Phil Griffiths

  • Calling the Ansible Automation Platform API Using 'Friendly' Job Template Names

    Have you ever wanted to call the AAP/Tower API to launch a Job Template? The REST API allows you to do that, fast and…

    1 Comment
  • Creating a custom EE for AWX

    This is a quick and rough guide to creating and consuming a custom execution environment (EE) in AWX. What You'll Need…

    29 Comments
  • Ansible Execution Environments

    Introduction Ansible as a automation platform offering is evolving further, making customer automation runtimes easier…

    15 Comments
  • AWX 18.0.0 with Containerised Execution Environments

    The upstream of Ansible Automation Platform, AWX has just landed with a new exciting release. Thought I'd give it a try…

    4 Comments
  • Ansible Features I Missed

    Well, ok some of these aren't particularly new, but I've only just become aware of them. Even after years of Ansible…

    4 Comments
  • Tuning RHEL Using Ansible System Roles

    Take the pain out of some performance tuning using RHEL's tuned functionality. Take even more pain out setting it up…

    1 Comment
  • Oh Molecule You've Come A Long Way

    I often get asked about Ansible testing, best practices and related topics. If there's one tool I'd have in the kit bag…

    4 Comments
  • Holy crap batman! sudo's bust!

    As we all know, software has bugs, no one escapes! How you respond and fix those bugs is what's important. If you ever…

    1 Comment
  • RHEL OS Image Builder (part two)

    This is part 2 of the blog series. Part one is here.

    1 Comment
  • RHEL8 OS Image Builder (part one)

    Following on from this post for setting up a quick RHEL VM with minimal fuss, this is what I really wanted it for!…

Explore content categories