- Home
- Blogs
- George Boobyer's blog
- Ansible - Sublime Text
Ansible - Sublime Text
I have been using TextWrangler as my editor for Ansible files. Very handy, light weight and powerful editor and you can open a whole folder set as a 'project' - but not so handy as you can only edit one file at a time, having to save every time you move to another file; which you do a lot as you pop back and forth between vars, tasks and handlers. So I thought I would revisit Sublime text - that I haven't used in a while and didn't want to use a full blown IDE (Netbeans for example). This was prompted by @dan_bohea who pointed me towards the syntax highlighter for Ansible for Sublime text - http://jamie.ideasasylum.com/2014/08/ansible-syntax-highlighting-sublime I still use TextWrangler for day to day text file editing as many of its features are excellent - search and replace functionality for example. So my challenge was to set up Sublime text to have the following features:
- Ansible syntax highlighting
- Readable fonts for the side-bar file list display
- Hidden text display
- Illegal character display
- Strip trailing whitespace on save
It is worth noting that TextWrangler provides a lot of this functionality and has the configuration options to strip trailing white space and ensure files end with a line break - very handy!
Ansible Syntax Highlighting
Really easy to set up - just follow the instructions here but basically:
- Install the Sublime Text package manager if you haven't already,
- Install the Ansible package,
- Install the Applysyntax plugin (enable Ansible files to be auto discovered)
- Select a colour scheme and update the preferences to auto discover Yaml files and you are set.
Update the font size for the side bar file listing
I also like to update the font size in the side bar file view, which is particularly obtuse to do (although once you get it you realize you can update almost anything...) I followed the instructions at http://stackoverflow.com/questions/23045968/increase-the-font-size-of-te.... Again simple instructions, install the Package Resource Viewer and add a font size value to the sidebar_label settings in the Theme default settings.
Display invisibles
Another things I like to do is set the editor to show invisibles. Easy to do in TextWrangler (View>Test Display>Show Invisibles) and again a bit of a mission in Sublime Text but just follow the instructions at - http://tosbourn.com/how-to-turn-on-invisible-characters-in-sublime-text-2/
In order to do this in Sublime you need to open your preferences file (On OSx that is ⌘+,) and insert the line "draw_white_space": "all". By default it is set to "selection" and the other option is for it to be "off".
Illegal character display
Finally just because you can get bitten by illegal characters you can install the Unicode Character Highlighter package and that will show you illegal characters such as non breaking spaces and trailing spaces etc
Strip trailing whitespace on save
This is another feature easy to set up in TextWrangler (Preferences>Text Files>Strip Trailing Whitespace). In the user preferences (option-,) add the following: "trim_trailing_white_space_on_save": true
Then when you save files any stray spaces at the end of lines will get stripped. If you want more control over this (e.g. do it on demand not on save then you can use the Trailing Spaces plugin
End result
Contact Details
Blue-Bag Ltd
- info [at] blue-bag.com
- Telephone: 0843 2894522
- Blue-Bag HQ:
The Garage, Manor Farm
Chilcompton, Radstock
Somerset, BA3 4HP, United Kingdom - Telephone: (+44) 01761 411542
- Blue-Bag Brighton:
Unit 35 Level 6 North, New England House
New England Street, Brighton
BN1 4GH United Kingdom - Telephone: (+44) 07944 938204
- VAT GB 748125034
- UK Company Reg: 3932829