2

I am using SpaceVim as Ruby on Rails IDE and installed the tpope/vim-rails plugin.

Commands such as :Econtroller, :Emodel and :find are working just fine, but the gf command provided by this plugin is not working in SpaceVim.

When I try to use it, it shows me an error message such as the ones below:

# for partial
Can't find file "users/edit_form" in path

# with association
User has_many :notes
Can't find file "notes" in path
  • Does it work with regular vim? – Maxim Kim Nov 10 '19 at 10:26
  • Yes it works with regular vim. Also gf works with sass partial, but is not working for the view template. If I rename the partial name i.e. render partial: 'partial_1' to render partial: '_partial_1' then also gf works. – Bipin Manandhar Nov 11 '19 at 8:40
  • 1
    You need to make sure path is set right: check with :verbose set path? – D. Ben Knoble May 3 at 14:40
1

I have exactly the same problem. It seems that SpaceVim overrides the gf command in some way so that rails-vim plugin's gf doesn't check for _ on partial names anymore. Also, you have to be on the partial name itself (instead of anywhere on the same line, thanks to vim-ruby plugin) for gf to work. So maybe it messes with vim-ruby too.

| improve this answer | |
  • What does :map gf show you in SpaceVim? – filbranden May 3 at 22:43
  • 1
    with :verbose map gf on spacevim, I get n gf gf Last set from ~/.SpaceVim/autoload/SpaceVim/mapping/g.vim line 50 . So clearly, SpaceVim resets the gf command. I tried to comment this line; also tried to replace this line by the gf fuction from vim-ruby (but it's not supposed to work that way apparently) – Tim May 8 at 7:00
  • With a regular setup (with vim-ruby), map gf gives me n gf @<SNR>118_c:find <Plug><cfile><CR> – Tim May 8 at 7:11
  • 1
    Actually, just deleting nmap g [G] (line 6) and nmap gf gf (line 50) inside .SpaceVim/autoload/SpaceVim/mapping/g.vim allows gf to work again. But then I lose the g SpaceVim menu (which I could still get with [G]. – Tim May 8 at 14:14
  • 1
    Wow awesome! Thank you, your answer answered so many questions I had – Tim May 12 at 14:20
0

vim-rails implements the gf key-binding by adding a mapping for it.

But it will only add a mapping for gf if it detects it wasn't mapped before, or if a previous mapping for gf matches a regex including _gf(v:count, Ruby or Rails (presumably because it's overriding known mappings from other related plug-ins by tpope such as vim-ruby or projectionist.)

The code snippet is:

let pattern = '^$\|_gf(v:count\|[Rr]uby\|[Rr]ails'
if mapcheck('gf', 'n') =~# pattern
  nmap <buffer><silent> gf         <SID>:find <Plug><cfile><CR>

On the other hand, SpaceVim defines a mapping for gf:

nnoremap gf gf

It's an odd mapping that just maps it to itself... (Not sure why SpaceVim wants such a mapping, since it doesn't seem to do anything, just maps the command to itself. I just posted a follow up question about these odd mappings.)

If it was installed, the gf mapping from vim-rails would supercede the mapping from SpaceVim.

But since vim-rails checks first, it finds the mapping from SpaceVim, which doesn't match its regex of expected mappings to override, it never really installs its gf key-binding, which causes the problem as reported here.

(Simply dropping the nnoremap gf gf is not enough, since the used mapcheck() will match prefixes and SpaceVim also creates a mapping for g by itself, so that mapping breaks the checks as well.)

Even though this issue seems to be triggered by the odd set of mappings created by SpaceVim, perhaps the easiest fix here would be to fix vim-rails to also install its gf key-binding if it finds the SpaceVim one, simply by adding a straight ^gf$ to the list of mappings to replace in its mapcheck().

UPDATE: I sent out PR #558 to suggest this change to vim-rails. Tested it on SpaceVim and it worked for me as expected.

UPDATE 2: The PR was merged upstream by tpope, so latest vim-rails should now work fine with SpaceVim! 🎉

| improve this answer | |
-1

You can check :map gf, it will tell you what this key is mapped to.

| improve this answer | |
  • 1
    I think the problem is not what gf is mapped to since the command executed seems to be the correct one, the issue is that the command doesn't open the right files. – statox Oct 11 '19 at 8:08
  • 1
    Yes the gf is working as expected for scss partials but is not working for html partial and association with has_many e.g. has_many :users, but works with has_one :user – Bipin Manandhar Nov 20 '19 at 13:32
  • Hi @WangShidong, I spent some time looking into this one and wrote an answer with my findings. I'll try to send a PR to vim-rails to make it work with SpaceVim. I'm puzzled about the nnoremap gf gf mapping in SpaceVim and I posted a follow up question about it, maybe I can get your attention there? Thanks! – filbranden May 10 at 6:52

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.