Skip to content

Commit c84f8bb

Browse files
authoredOct 7, 2021
Add option for detecting which filenames get the ansible filetype
1 parent 40e28ee commit c84f8bb

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎README.md

+7
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ Accepts a dictionary in the form of `'regex-for-file': 'filetype'`.
135135

136136
All files ending in `*.j2` that aren't matched will simply get the `jinja2` filetype.
137137

138+
##### g:ansible_ftdetect_filename_regex
139+
`let g:ansible_ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'`
140+
141+
Accepts a regex string that is used to match the filename to determine if the file should use the Ansible filetype
142+
143+
Can be used to avoid clashes with other files that are named the same - e.g. main.yaml used in github workflows by removing `main` from the regex
144+
138145
## goto role under cursor (similar to gf)
139146

140147
This behavior is not supported out of the box, but you can use [this snippet](https://gist.github.com/mtyurt/3529a999af675a0aff00eb14ab1fdde3) in your vimrc.

‎ftdetect/ansible.vim

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ function! s:isAnsible()
33
let filename = expand("%:t")
44
if filepath =~ '\v/(tasks|roles|handlers)/.*\.ya?ml$' | return 1 | en
55
if filepath =~ '\v/(group|host)_vars/' | return 1 | en
6-
if filename =~ '\v(playbook|site|main|local|requirements)\.ya?ml$' | return 1 | en
6+
let s:ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'
7+
if exists("g:ansible_ftdetect_filename_regex")
8+
let s:ftdetect_filename_regex = g:ansible_ftdetect_filename_regex
9+
endif
10+
11+
if filename =~ s:ftdetect_filename_regex | return 1 | en
712

813
let shebang = getline(1)
914
if shebang =~# '^#!.*/bin/env\s\+ansible-playbook\>' | return 1 | en

0 commit comments

Comments
 (0)
Please sign in to comment.