skeept
skeept

Reputation: 12413

Repeating last function call with dot

I wrote a small function and added a map to jump to the next line that does not match the two first chars in the current line:

function! JumpToNextNonMatching()
  let curr_line = getline('.')
  let spattern = '^[^' . curr_line[0] . '][^' . curr_line[1] . ']'
  call search(spattern)
endfunction
nnoremap ,n :<C-U>call JumpToNextNonMatching()<CR><C-L>

so if I hit ,n it will jump to next line that doesn't match the criteria. I would like to use the repeat.vim plugin to use . to repeat this operation, i.e., jump to the next line that doesn't match the criteria.

How can I do this with the plugin mentioned or are there better alternatives that I can use?

Upvotes: 0

Views: 299

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172648

You should have told us what exactly you're struggling with. Using repeat.vim doesn't require many changes:

  1. You need to introduce an intermediate <Plug> mapping for repeat to invoke.
  2. You need to register your mapping with the plugin at the end of your command's execution.

Here you are:

function! JumpToNextNonMatching()
    let curr_line = getline('.')
    let spattern = '^[^' . curr_line[0] . '][^' . curr_line[1] . ']'
    call search(spattern)

    silent! call repeat#set("\<Plug>JumpToNextNonMatching")
endfunction
nnoremap <Plug>JumpToNextNonMatching :<C-U>call JumpToNextNonMatching()<CR><C-L>
nmap ,n <Plug>JumpToNextNonMatching

Upvotes: 3

Related Questions