increment list

2013-05-09 Thread shawn wilson
Quite often I've got a list, either:

1 - do this first
2 - do this next
3 - go home

or
/^
([0-3][0-9])-  # 0 Day
([A-Z][a-z][a-z])- # 1 Month
([0-9]{4})# 2 Year
/x;

And I alter something and need to change the list. I can make a macro
where I 'j0cw' or 'f#wcw' but then how do I make the incrementing
work?

-- 
-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
vim_use group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: increment list

2013-05-09 Thread Charles Campbell

shawn wilson wrote:

Quite often I've got a list, either:

1 - do this first
2 - do this next
3 - go home

or
/^
([0-3][0-9])-  # 0 Day
([A-Z][a-z][a-z])- # 1 Month
([0-9]{4})# 2 Year
/x;

And I alter something and need to change the list. I can make a macro
where I 'j0cw' or 'f#wcw' but then how do I make the incrementing
work?


I believe that visincr will do what you want; you can get visincr from:

http://www.drchip.org/astronaut/vim/index.html#VISINCR (cutting edge)
http://vim.sf.net/scripts/script.php?script_id=670  (stable)

Quick Overview:

   :I[#]   left justified incremented list
   :II   [# [zfill]]   right justified incremented list
   :IO   [#]   left justified octal incremented list
   :IIO  [# [zfill]]   right justified octal incremented list
   :IX   [#]   left justified hex. incremented lsit
   :IIX  [# [zfill]]   right justified hex. incremented lsit
   :IYMD [# [zfill]]   year/month/day incremented list
   :IMDY [# [zfill]]   month/day/year incremented list
   :IDMY [# [zfill]]   day/month/year incremented list
   :IA   [#]   alphameric incremented list
   :ID   [#]   dayname incremented list
   :IM   [#]   monthname incremented list

Installation: if you're using vim 7.2 or 7.3,

   vim visincr.vba.gz
   :so %
   :q

Regards,
C Campbell

--
--
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups vim_use group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: increment list

2013-05-09 Thread Paul Isambert
 Quite often I've got a list, either:
 
 1 - do this first
 2 - do this next
 3 - go home
 
 or
 /^
 ([0-3][0-9])-  # 0 Day
 ([A-Z][a-z][a-z])- # 1 Month
 ([0-9]{4})# 2 Year
 /x;
 
 And I alter something and need to change the list. I can make a macro
 where I 'j0cw' or 'f#wcw' but then how do I make the incrementing
 work?

You can try defining a function like this:

function! Increment (...) range
  let i = a:firstline
  let pattern = a:0 ? a:1 : '\d\+'
  while i = a:lastline
call setline(i, substitute(getline(i), pattern, '\=submatch(0)+1', ''))
let i += 1
  endwhile
endfunction

Then you can call Increment on a range and it will increment all numbers 
matching the given pattern (or the first encountered number if no pattern is 
given). For instance, the first lists could be incremented with

:','call Increment()

(in Visual mode) and the second with

:','call Increment('#\s*\zs\d\+')

(Don't forget `\zs'!)

That was just off my head, though, and simpler solutions may exist.

Best,
Paul

-- 
-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
vim_use group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: increment list

2013-05-09 Thread shawn wilson
Thanks y'all. I'm not sure which I like better. (probably the simple
function though)

-- 
-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
vim_use group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.