Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please add a concrete example #55

Open
jabbalaci opened this issue May 15, 2016 · 2 comments
Open

please add a concrete example #55

jabbalaci opened this issue May 15, 2016 · 2 comments

Comments

@jabbalaci
Copy link

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.

@robertf57
Copy link

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.

@Goli4thus
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants