Skip to content

Instantly share code, notes, and snippets.

@jettero
Last active August 29, 2018 12:33
Show Gist options
  • Save jettero/60f85c069768cb209e8ac801ef2ca69b to your computer and use it in GitHub Desktop.
Save jettero/60f85c069768cb209e8ac801ef2ca69b to your computer and use it in GitHub Desktop.
Attempt at rational re-writing of salt://whatever/file.sls into something else (part 1 of ??)
" vi:ft=vim:
" in the olden days, this was how I opened files. I like having gf actually
" issue <c-w>f (open the file under cursor in a new window); but occasionally,
" I really want the original gf; which I map to gF
nmap gf <C-w>f
nnoremap gF gf
" the above works just fine for the below actual filepath
" /etc/resolv.conf
" but fails completely to deal with the below fake one
" what I really want gf to open is $SALTSTACK_FILE_ROOT/top.sls
" salt://top.sls
" So I wrote this mess
" mostly based on this guy's article: http://andrewradev.com/2016/03/09/building-a-better-gf-mapping/
" which itself is mostly based on this guy's work: https://github.com/tpope/vim-rails
fun! xlate#cfile()
if expand('<cfile>') =~ "^salt://"
return substitute(expand('<cfile>'), "^salt://", "$SALTSTACK_FILE_ROOT/", '')
endif
return expand('<cfile>')
endfun
" map the "key" <Plug><cfile> to xlate#cfile()
cmap <buffer><script><expr> <Plug><cfile> xlate#cfile()
" map the "key" <Plug>xlate-?? to the actions :split/:find
nmap <buffer> <Plug>xlate-gf :split <Plug><cfile><cr>
nmap <buffer> <Plug>xlate-gF :find <Plug><cfile><cr>
" map the keys gf/gF to the "keys" <Plug>/xlate-??
nmap <buffer> gf <Plug>xlate-gf
nmap <buffer> gF <Plug>xlate-gF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment