Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ Accepts a dictionary in the form of `'regex-for-file': 'filetype'`.

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

##### g:ansible_ftdetect_filename_regex
`let g:ansible_ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'`

Accepts a regex string that is used to match the filename to determine if the file should use the Ansible filetype

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

## goto role under cursor (similar to gf)

This behavior is not supported out of the box, but you can use [this snippet](https://gist.github.com/mtyurt/3529a999af675a0aff00eb14ab1fdde3) in your vimrc.
Expand Down
7 changes: 6 additions & 1 deletion ftdetect/ansible.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ function! s:isAnsible()
let filename = expand("%:t")
if filepath =~ '\v/(tasks|roles|handlers)/.*\.ya?ml$' | return 1 | en
if filepath =~ '\v/(group|host)_vars/' | return 1 | en
if filename =~ '\v(playbook|site|main|local|requirements)\.ya?ml$' | return 1 | en
let s:ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'
if exists("g:ansible_ftdetect_filename_regex")
let s:ftdetect_filename_regex = g:ansible_ftdetect_filename_regex
endif

if filename =~ s:ftdetect_filename_regex | return 1 | en

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