value1|value2|value3
into:
def foo(x="value1"
y="value2"
z="value3")
But I ran into a problem when trying to apply this function to a range. The range gets confused because I am appending additional lines. I solved this problem by using the range keyword and using a:firstline, a:lastline, and a for loop that skips every four lines.
Something like this:
This is the incomplete version because the actual problem I'm trying to solve is slightly different, but the crux of the problem is still the same.
function! ReFormat() range
let num_lines = a:lastline - a:firstline + 1
for linenum in range(a:firstline, a:firstline + (num_lines - 1) * 4, 4)
let line = getline(linenum)
...
endfor
endfunction
Is there not some helper method that knows how to append using ranges. My coworker said that in emacs he's able to get the current cursor position. In vim we can get the current line '.', but if we could get the cursor position as the range iterates, we wouldn't have to worry about the number of lines appended.
Thanks for reading my rambling,
Eric
I can also use a macro, but that too suffers from the same problem.
What do you mean that the global command marks the already processed lines?
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
I do like the use of "\=Reformat()". That's pretty clean.
Eric
I'm not sure whether you still need the answer to this question, but:
:help getpos()
Also:
:help line()
:help col()
:help virtcol()
Any of these functions can return information about the cursor position.
Maybe you already know about these and I misunderstand your question? You mentioned using '.' to get the current line, by which you might mean line('.'), but if that's the case I'm not sure what your problem is because that will give you the cursor line.
--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/BSej2dwukdA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.