# Setting up SublimeText 3 for Ansible

I love using Sublime Text 3 for Ansible work, especially after some minor tweaks. The packages I have installed are: Ansible syntax highlighting, ApplySyntax, Jinja2 syntax support, SublimeLinter, and SublimeLinter-pyyaml.

For ApplySyntax you want to change the user settings to contain something like the following below. It's based on the best practices for Ansible directory layout, but with one change, I prefer to have playbooks in their own subdirectory.

{
"syntaxes": [
{
"syntax": "Ansible/Ansible",
"rules": [
{ "file_path": ".*/defaults/.*.ya?ml$" }, { "file_path": ".*/handlers/.*.ya?ml$" },
{ "file_path": ".*/meta/.*.ya?ml$" }, { "file_path": ".*/tasks/.*.ya?ml$" },
{ "file_path": ".*/vars/.*.ya?ml$" }, { "file_path": ".*/inventory/group_vars/.*" }, { "file_path": ".*/inventory/host_vars/.*" }, { "file_path": ".*/inventory/.*" }, { "file_path": ".*/playbooks/.*.ya?ml$" }
]
},
{
"syntax": "Jinja2/Syntaxes/Jinja Templates",
"rules": [
{ "file_path": ".*/templates/.*.j2\$" }
]
}
]
}

The above will ensure that the Ansible syntax highlighting gets used for the regular expressions defined in the file_path matches.

Then in the SublimeLinter user settings make sure that syntax_map contains an entry "ansible": "yaml". This will ensure that all views marked with the Ansible file type will now automatically use the SublimeLinter-pyyaml linter.

# Sublime Text with 80 and 120 column rulers

For many programming languages we still like to use either 80 or 120 columns in our editors to ensure it fits easily on print, as well as to use it as an aid for ensuring concise code.

In Sublime Text you can set vertical rulers for this by going to Preferences » User File Preferences and add rulers 80 120 and save the file.

For Sublime Text 2 it's under Preferences » Settings — User, but the configuration file is now in JSON format, so you need to add "rulers": [80, 120] and maybe you need to append a comma at the end if you have more configuration directives following it.

Addition 2013: in Sublime Text 3 it is still under Preferences » Settings — User and the file is still in JSON, so simply add "rulers": [80, 120], like in the example for Sublime Text 2.