I want to replace each profile with a line with an incremental index starting with 1 at the beginning of each line, so the replacement lines will be varargin{1} , varargin{2} , varargin{3} ... For large numbers, the number line should naturally be more than 1 character, for example: ... varargin{9} , varargin{10} ... Input is MATLAB code, sample inputs and required outputs are presented below. I am primarily looking for a vim solution, but other ways to do this are also welcome.
The expression below creates indexes starting with 1 , but they change only for each row.
:let @a=1 | %s/\v.*'\zs.*\ze\);/\=substitute(submatch(0), '\s[a-zA-Z0-9{}_.]*', ' varargin{'.(@a+setreg('a',@a+1)).'}', 'g')/g
My question is:
How can I reset index 1 at the beginning of each line and increment the index by 1 between each send?
The above code is a modified version of the Replace with Ascending Numbers example provided at http://vim.wikia.com/wiki/Substitute_with_incrementing_numbers :
:let @a=1 | %s/abc/\='xyz_'.(@a+setreg('a',@a+1))/g
Input Example # 1:
messages.msg1.English = xprintf('analysis directory is on %s\n', analysis_dir);
The required output, for example, input No. 1:
messages.msg1.English = xprintf('analysis directory is on %s\n', varargin{1});
Input Example # 2:
messages.msg15.English = xprintf('the following sessions (%d pcs) have been approved: %s', handling_struct.n_of_accepted, handling_struct.accepted_sessions_vector);
The required output, for example, input No. 2:
messages.msg15.English = xprintf('the following sessions (%d pcs) have been approved: %s', varargin{1}, varargin{2});
Input Example # 3:
messages.msg19.English = xprintf('looking for files ''%s'' in %d separate dirs', give_file_struct.regex, number_of_dirs);
The required output, for example, input No. 3:
messages.msg19.English = xprintf('looking for files ''%s'' in %d separate dirs', varargin{1}, varargin{2});