# How to increment a previously used substitution digit

6 messages
Open this post in threaded view
|

## How to increment a previously used substitution digit

 Hi, I have something like this - reg a0 = abc[0] reg a0 = abc[0] reg a0 = abc[0] reg a0 = abc[0] I am trying to create something like this - reg a0 = abc[0] reg a1 = abc[1] reg a2 = abc[2] reg a3 = abc[3] Any recommendations on how I can do this at a command line? TIA Sanjay --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php-~----------~----~----~----~------~----~------~--~---
Open this post in threaded view
|

## Re: How to increment a previously used substitution digit

 On Thu, Mar 12, at 12:42 parekh wrote: > > Hi, > > I have something like this - > reg a0 = abc[0] > reg a0 = abc[0] > reg a0 = abc[0] > reg a0 = abc[0] > > I am trying to create something like this - > reg a0 = abc[0] > reg a1 = abc[1] > reg a2 = abc[2] > reg a3 = abc[3] > > Any recommendations on how I can do this at a command line? Here is a possible way: Source this function, function! Increm() range     let nr = 1     let line = a:firstline + 1     while line <= a:lastline         let string = getline(line)         call setline(line, substitute(string, '[[:digit:]]\+', nr, 'g'))         let nr += 1         let line += 1     endwhile endfunction :1,4 call Increm() or while selecting the lines :'<,'>call Increm() > TIA > Sanjay Regards, Ag. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php-~----------~----~----~----~------~----~------~--~---
Open this post in threaded view
|

## Re: How to increment a previously used substitution digit

 In reply to this post by parekh On Mar 13, 8:42 am, parekh  wrote: > Any recommendations on how I can do this at a command line? Do you mean a shell prompt, or vim's command line? If the lines you want to change are contiguous, the visincr script (from vim.org) works well. Another approach would be:     :let n = 0     :g/reg a0/s/a\zs0/\=n/|s/\[0\]/\='['.n.']'/|let n+=1 I suppose you could use     vim -c "let n = 0|g/reg a0/s/a\zs0/\=n/|s/\[0\]/\='['.n.']'/|let n +=1" -c x to do it all from a shell prompt. Regards, John --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php-~----------~----~----~----~------~----~------~--~---
Open this post in threaded view
|

## Re: How to increment a previously used substitution digit

 In reply to this post by parekh On 3月13日, 上午3时42分, parekh <[hidden email]> wrote: > Hi, > > I have something like this - > reg a0 = abc[0] > reg a0 = abc[0] > reg a0 = abc[0] > reg a0 = abc[0] > > I am trying to create something like this - > reg a0 = abc[0] > reg a1 = abc[1] > reg a2 = abc[2] > reg a3 = abc[3] > > Any recommendations on how I can do this at a command line? put your cursor on the first line, input: qqyyp7ljddkq then, put cursor to second line, press 3@q now every thing is done :-) --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php-~----------~----~----~----~------~----~------~--~---