Thursday, August 8, 2013

Re: How to append lines when iterating over a range.

I suggest using a substitute that calls a function using \= (see :help sub-replace).

For example:

function! ReFormat(stuff)
let l = split(a:stuff, '|')
let x = l[0]
let y = l[1]
let z = l[2]
return 'def foo(x="' . x . '"' . "\n"
\ . ' y="' . y . '"' . "\n"
\ . ' z="' . z . '")'
endfunction

:%s/\w\+|\w\+|\w\+/\=ReFormat(submatch(0))

If the pattern that finds the lines to process is different to that which identifies the text within the line, use :global, say

:g/whatever/s/\w\+|\w\+|\w\+/\=ReFormat(submatch(0))

Using a function that processes a range is hard IMO.

Regards, John Little

--
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: