tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.1k stars 383 forks source link

Make `gf` mapping work with SpaceVim #558

Closed filbranden closed 4 years ago

filbranden commented 4 years ago

SpaceVim includes a nnoremap gf gf, in order to clobber a mapping it installs for the g prefix, which displays a "guide" for the commands starting with g. (They do the same for the mappings with the z prefix.)

This ends up preventing vim-rails from installing a gf mapping of itself, since it uses a mapcheck() to only install a mapping when either none exists or a mapping it knowingly wants to override is present. But the mapping to itself from SpaceVim prevents that check from succeeding, which in turn prevents vim-rails from installing its own gf mapping.

This affects gf, but not <C-W>f or <C-W>gf which work as expected.

In order to work around this problem, update the pattern used by the mapcheck() checking for the gf mapping to also succeed when the mapped expression matches gf exactly.

Tested on Pos*t.first, confirmed that it works same as <C-W>f would work. Also checked output of :map gf on SpaceVim with vim-rails, which matches the expected:

n  gf           @<SNR>183_:find <Plug><cfile><CR>
n  gf          * gf
n  g             [G]

This issue was originally raised on StackExchange: How to get tpope/vim-rails gf command to work with SpaceVim?

And about the weird mapping of SpaceVim: Why would you use nnoremap gf gf as SpaceVim does?

tpope commented 4 years ago

Weird but ok!