julia-vim icon indicating copy to clipboard operation
julia-vim copied to clipboard

Matchit [% and ]% motions don't work reliably

Open rcantangus opened this issue 10 years ago • 2 comments

It seems that these motions rarely work as expected. Likewise a% produces odd results.

E.g., with the cursor placed on the:

  • "s" of s = 1 [% doesn't jump to "function" and ]% doesn't jump to the function's "end"
  • "if" or "for" [% doesn't jump to "function" and ]% doesn't jump to the corresponding "end" (and takes a long time to decide not to jump)
  • "end" of either of the "if" or "for" blocks ]% doesn't jump to the function's "end"
function stride(a::AbstractArray, i::Integer)
    if i > ndims(a)
        return length(a)
    end
    s = 1
    for n=1:(i-1)
        s *= size(a, n)
    end
    return s
end

As an aside, would it be possible to send these to Bram Moolenaar for inclusion in the distributed runtime files? Having this work out of the box with Vim is a much nicer experience for the casual Julia user.

rcantangus avatar Oct 24 '15 15:10 rcantangus

I never used the [% and ]% motions, but I tried to look into this and it seems that the issue is with the matchit plugin: these commands assume that the keywords are defined via regexes, but in order to make the % command work correctly I had to use a function (which is supported by matchit, but apparently only for %). They also seem broken in other filetypes.

So for the time being I just pushed a "fix" which avoid the weirdness and basically disables the matchit engine unless you are on a keyword.

Fortunately, you can fix the behaviour by using the provided julia-motion commands (see :help julia-vim-blocks) which can be customized (see :help g:julia_blocks_mappings).

By default, the motion commands are mapped to [j, [[, etc and the selection to aj, but there's nothing to prevent you to use [%, ]% and a% instead.

carlobaldassi avatar Jan 24 '16 21:01 carlobaldassi

Oh and about inclusion in vim: I think Julia is still too much of a moving target for that. My plan is to ask for inclusion when Julia reaches 1.0.

carlobaldassi avatar Jan 24 '16 22:01 carlobaldassi