Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Forked from deris/gist:5730298
Last active December 18, 2015 05:19
Show Gist options
  • Save osyo-manga/5731547 to your computer and use it in GitHub Desktop.
Save osyo-manga/5731547 to your computer and use it in GitHub Desktop.
function! s:fix_number(pattern, ...)
if a:0 > 2
return
endif
let s:start = get(a:, 1, get(g:, 'fix_number_default_start', 0))
let s:step = get(a:, 2, get(g:, 'fix_number_default_step', 1))
let pattern = empty(a:pattern) ? get(g, 'fix_number_default_pattern', '\(\d\+\)') : a:pattern
let s:counter = 0
silent execute "'<,'>s/".pattern.'/\=s:matched(submatch(1))/g'
endfunction
function! s:matched(match)
if get(g:, 'fix_number_use_first_number', 0)
let s:first_number = a:match
else
let s:first_number = 0
endif
return s:first_number + s:start + s:step()
endfunction
function! s:step()
let tmp = s:counter
let s:counter += s:step
return tmp
endfunction
command! -count -nargs=*
\ FixNumber
\ call s:fix_number(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment