Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmndrsp0ck/213ce3172fdfdb7e56ad687a6a8378e9 to your computer and use it in GitHub Desktop.
Save cmndrsp0ck/213ce3172fdfdb7e56ad687a6a8378e9 to your computer and use it in GitHub Desktop.
With pearofducs/ansible-vim plugin installed, following mapping behaves like `gf`, navigates to role under cursor's tasks/main.yml file. Ideal to be used in playbooks
" vim-plug example
call plug#begin('~/.vim/plugged')
Plug 'pearofducks/ansible-vim'
call plug#end()
let g:ansible_goto_role_paths = './roles,../_common/roles'
function! FindAnsibleRoleUnderCursor()
if exists("g:ansible_goto_role_paths")
let l:role_paths = g:ansible_goto_role_paths
else
let l:role_paths = "./roles"
endif
let l:tasks_main = expand("<cfile>") . "/tasks/main.yml"
let l:found_role_path = findfile(l:tasks_main, l:role_paths)
if l:found_role_path == ""
echo l:tasks_main . " not found"
else
execute "edit " . fnameescape(l:found_role_path)
endif
endfunction
au BufRead,BufNewFile */ansible/*.yml nnoremap <leader>gr :call FindAnsibleRoleUnderCursor()<CR>
au BufRead,BufNewFile */ansible/*.yml vnoremap <leader>gr :call FindAnsibleRoleUnderCursor()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment