Skip to content

please add a concrete example #55

Open

Description

@jabbalaci

By reading the README it was not clear to me how to use this plugin. Using this screencast (http://vimcasts.org/episodes/creating-repeatable-mappings-with-repeat-vim/) I managed to figure out how it works. Here is a concrete example, I think it would be a good idea to add it (or something similar) to the README:

before

nnoremap <Leader>' viw<esc>a'<esc>hbi'<esc>lel

It surrounds the current word (manual solution).

after

nnoremap <silent> <Plug>SurroundWordWithApostrophe  viw<esc>a'<esc>hbi'<esc>lel
    \ :call repeat#set("\<Plug>SurroundWordWithApostrophe", v:count)<cr>
nmap <Leader>'  <Plug>SurroundWordWithApostrophe

Now it's repeatable with the "." command.

Activity

  1. robertf57 commented on May 27, 2016

    @robertf57

    I agree with jabbalaci. It's not at all clear how to use this plugin. I thought you could execute a plugin command, move to another position in your file, hit ".", and the command would repeat itself. Clearly that's not the case as you still need to create a custom mapping for this to work.

  2. Goli4thus commented on Mar 2, 2023

    @Goli4thus

    I also agree with the above. Just tried to integration vim-repeat with my own plugin (still unreleased) and stuggled quite a bit.
    Neither by looking at the official help page or README, nor by looking at the developer comments in vim-repeat source code, nor by looking at other plugins like vim-surround or nerdcommenter did it really make click for me.
    Only after stumbling over this discussion and seeing the example by @jabbalaci did it make more sense. With some trial and error after that I finally got it working for my own case.

    But yeah, having a couple simple examples would make adoption more doable.

    Here's my gist of what I've learned today:

    Let's say originally we had a mapping like this one:

    execute 'nnoremap <leader>k ' .
                \ ':call MyPlugin#DoStuff(1, 2)<CR>'
    

    Adding vim-repeat:

    execute 'nnoremap <silent> <Plug>MyPluginMap ' .
                \ ':call MyPlugin#DoStuff(1, 2)<CR>'
                \ ':call repeat#set("\<Plug>MyPluginMap", -1)<CR>'
    execute 'nnoremap <leader>k ' .
                \ '<Plug>MyPluginMap'
    

    This example makes use of the second variable being -1, which ignores any count prefixes to the mapping call.
    In a sense it's about introducing <Plug>MyPluginMap, which is like a placeholder and is being used in the repeat#set() call.
    Furthermore the actual mapping then is made referencing this placeholder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions