On a particular init.pp file, I have the following definition:

class temp_executor {
  if $::fqdn =~ /host.*01/ {
    include ::temp_executor::deploy

deploy.pp is on the same folder as init.pp.

I want to jump to that deploy.pp file, while highlighting ::temp_executor::deploy by pressing gf or gd or something similar.

Currently I have to look for the file by name, and while using fzf is quick, it's not as good as jumping.

I've installed the rails-vim plugin (https://vimawesome.com/plugin/rails-vim) but I don't know how to go about this particular movement.

Thanks in advance for the help!


To clarify, temp_executor is the name of the module in puppet, and deploy.pp is the name of the manifest on that module's folder.

So the structure is like this:

│   │   deploy.pp
│   │   init.pp
│   │   (...)

The expected behavior for me would be to highlight the word deploy the line include ::temp_executor::deploy and jump to the file deploy.pp

  • 1
    Welcome to Vi and Vim! I don’t think this has anything to do with rails. Rather, you need to set the include, includeexpr, and maybe suffixesadd options for the filetype you’re working with. Then gf should work fine.
    – D. Ben Knoble
    Jul 29 '20 at 15:07
  • You may also need to set path
    – D. Ben Knoble
    Jul 29 '20 at 15:08
  • @D.BenKnoble I think we made the same mistake: the OP wants to jump to a definition in another file, not to the file under the cursor. tags and/or LSP might be the way to go.
    – Biggybi
    Jul 29 '20 at 15:19
  • @Biggybi i’m not sure—the questions says jump to deploy.pp .. OP, can you edit to clarify ?
    – D. Ben Knoble
    Jul 29 '20 at 15:27
  • The suffixesadd did it, thanks a lot for this!
    – pr3c0g
    Jul 29 '20 at 18:53

This works when your cursor is on the file name, deploy.pp in your example.

:setlocal suffixesadd=.pp

'suffixesadd' is the option responsible for the filenames tested when you try to jump with gf, and other commands.

When you input the above command, temp_executor.pp will be tested by gf.

You can drop the command in a ftplugin file. Or you could put something like this in your vimrc:

augroup Suffixepp
  au FileType pp setlocal suffixesadd=.pp
augroup END

You'll also need to set the path, unless both files are in the current working directory. gf will only try the folders listed by path.

Finally, depending on your language, you may need to set a proper includeexpr, to use the include as an actual filename.

Useful doc:

  • :h 'suffixesadd'
  • :h 'path'
  • :h 'include'
  • :h 'includeexpr'
  • Why delete? I do think youre missing includeexpr at the least, but it’s a good start
    – D. Ben Knoble
    Jul 29 '20 at 15:09
  • @D.BenKnoble I never used includeexpr, but in the case where both files are in the same directory, is it necessary?
    – Biggybi
    Jul 29 '20 at 16:04
  • It can be when the import syntax isn’t file-based (eg, java and python use ., and rust uses ::, instead of /, so you want to translate those first)
    – D. Ben Knoble
    Jul 29 '20 at 16:21
  • Using the command you mentioned :setlocal suffixesadd=pp when editing the file, I still get "Can't find "deploy" in path", so it doesn't look like it's adding it to the suffixes? I'm using VIM - Vi IMproved 8.2 on mac os x, if that's relevant.
    – pr3c0g
    Jul 29 '20 at 18:37
  • @pr3c0g Ugh, I missed a dot : it's .pp. I cleaned the answer with an edit. Hope it works now!
    – Biggybi
    Jul 29 '20 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.