Highlight ansible YAML and Jinja syntax in vim Editor

Sometimes, I’m getting a bit confused and messing up my files because I don’t have a decent format highlight. Then I thought how great would be to highlight ansible YAML and Jinja syntax in vim Editor. Also, this will helpful to have more fun over your coding. Active syntax colors in your YAML and Jinja files

Use this: https://github.com/tpope/vim-pathogen and don’t forget to give him a star if you have the opportunity.
pathogen.vim makes it super easy to install plugins and runtime files in their own private directories
Install to ~/.vim/autoload/pathogen.vim. Or copy and paste the following into your terminal/shell:

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Now add the following lines to vim ~/.vimrc to activate this and start autoloading bundles (if you don’t have the file you have ton create it).

execute pathogen#infect()
syntax on
filetype plugin indent on

Now, download the bundles to highlight the syntax and put then into your .vim/bundle folder (if you don’t have this folder, create it)

cd ~/.vim/bundle
git clone git://github.com/chase/vim-ansible-yaml.git
git clone https://github.com/lepture/vim-jinja.git

You’re done! Easy, don’t you think?

Now prepare to be amazed using “vim” with any yml and j2 file extensions (remember use “vim” instead “vi”, unless you have already figured that part)

Tell if it wasn’t great to Highlight ansible YAML and Jinja syntax in vim Editor, he?

Additional notes:

Vim sessions default to capturing all global options, which includes the 'runtimepath' that pathogen.vim manipulates. This can cause other problems too, so I recommend turning that behavior off:

set sessionoptions-=options

If you don’t like the directory name bundle, you can pass a runtime relative glob as an argument:

execute pathogen#infect('stuff/{}')

The {} indicates where the expansion should occur.
You can also pass an absolute path instead. I keep the plugins I maintain under ~/src, and this is how I add them:

execute pathogen#infect('bundle/{}', '~/src/vim/bundle/{}')

Please, visit https://github.com/tpope/vim-pathogen for more information and to give him his well deserved star.

See ya!

Leave a Reply

Your email address will not be published. Required fields are marked *