I've got lots of Java classes whose fields need Xml attributes - sounds like a perfect job for a Vim script!
Given some lines like:
private String lName;
private String fName;
private String eAddr;
private int age;
I need the script to produce
@XmlElement(name = "LName")
private String lName;
@XmlElement(name = "FName")
private String fName;
@XmlElement(name = "EAddr")
private String eAddr;
@XmlElement(name = "Age")
private int age;
so within the for-loop of my function I need to read each line, extract the field name, tweak it a bit, add the fieldname to a new string and insert that string on a newline before the line in the buffer.
Question: can a for-loop go backwards? Similar to C++ where you can
for( int ii = 10 ; ii > 0 ; --ii ) {
dostuff
}
Going backwards would seem to be necssary to prevent the insertion from messing up the positions of all previous lines.
Or maybe an easier way would be to just read from the first buffer and write into a 2nd buffer, then write out the contents of the 2nd buffer to the file. That has the advantage of the for-loop going fwd.
All thoughts, suggestions, constructive criticism and especially examples are all welcome!
TIA,
Still-learning Steve
--
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
No comments:
Post a Comment