0

I would like to jump from method to method in Python. With Vim you can use the ]m combination to jump to the next method and the [m to the previous.

Since the ] is quite awkward to type on a Belgium keyboard. So I would like to use the repmo plugin to repeat the motion.

I successfully configured repmo to repeat the jump to the next cpp scope:

map <expr> ; repmo#LastKey(';')|sunmap ;
map <expr> , repmo#LastRevKey(',')|sunmap ,

" Still repeat fFtT (now with counts):
noremap <expr> f repmo#ZapKey('f')|sunmap f
noremap <expr> F repmo#ZapKey('F')|sunmap F
noremap <expr> t repmo#ZapKey('t')|sunmap t
noremap <expr> T repmo#ZapKey('T')|sunmap T

" Now following can also be repeated with `;` and `,`:
for keys in [ ['[[', ']]'], ['[]', ']['], ['[m', ']m'], ['[M', ']M'], ['[c', ']c'] ]
  execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
  execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor

But it doesn't work for the python filetype.

I believe it has to do that there is a custom mapping for ]m in the python filetype.

Does someone knows how to achieve that?

4
  • 1
    Wrap all that in a function (autoloaded, ideally) and call it in after/ftplugin/<filetype>.vim.
    – romainl
    Commented Nov 25, 2023 at 12:59
  • 1
    Now if only somebody had written a plugin to take care of this exact use case ...
    – Friedrich
    Commented Jul 3 at 18:25
  • @Friedrich I will write an answer tomorrow ;-) Commented Jul 3 at 18:30
  • "Self-answers are encouraged on this site. You will be able to accept your own answer after 48 hours." :-)
    – Friedrich
    Commented Jul 3 at 18:34

1 Answer 1

1

This is not really an answer to the question but because I didn't found an easy way to configure repmo-vim to support buffer mappings set for specific filetype I have developed the vim-remotions plugin.

With the vim-remotions plugins the mappings are set at the buffer level when the filetype is set which solves the problem.

Here is a super minimal vim-remotions configuration to support ]m, [m motions:

  let g:remotions_motions = {
        \ 'TtFf' : {},
        \ 'method' : { 'backward' : '[m', 'forward' : ']m' },
        \ }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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