Last active
December 18, 2015 05:09
-
-
Save deris/5730298 to your computer and use it in GitHub Desktop.
連番入力Vim script(from manga_osyo's code at Lingr)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:fix_number(pattern, ...) | |
if a:0 > 2 | |
return | |
endif | |
let s:start = exists('g:fix_number_default_start') ? g:fix_number_default_start : 0 | |
let s:step = exists('g:fix_number_default_step') ? g:fix_number_default_step : 1 | |
if a:0 >= 1 | |
let s:start = a:1 | |
endif | |
if a:0 >= 2 | |
let s:step = a:2 | |
endif | |
let pattern = exists('g:fix_number_default_pattern') ? g:fix_number_default_pattern : '\(\d\+\)' | |
let pattern = empty(a:pattern) ? pattern : a:pattern | |
let s:counter = 0 | |
silent execute "'<,'>s/".pattern.'/\=s:matched(submatch(1))/g' | |
endfunction | |
function! s:matched(match) | |
if exists('g:fix_number_use_first_number') && | |
\g:fix_number_use_first_number == 1 | |
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