|
Can anyone explain this command to me? I know what the result is but I don't know what it's actually doing because all I did was modify a different thing. It finds all instances of <p> and gives them an id attribute with sequential numbers.code:
let n=1 -- Simple enough, it's defining a variable. g/<p>/ -- From what I can tell, this searches for the pattern and collates all lines that match into a new buffer of sorts which is kind of like a more/less thing? s/<p>/ -- Search for this pattern. \='<p id="'.n.'">'/ -- I get that this is the replacement part of the s command and I can see the different parts of it but it starts with an escaped equals sign, has quotes surrounding it and the variable part and some periods around the variable too? let n=n+1 -- Increasing the variable by 1. If this command is being run over and over I don't see why this part is repeated to increase the variable but let n=1 isn't repeated. If it's all repeated then n would be set to 1 at the start, the replacement would be carried out with n as 1, it would be set to n+1 (2) but then set back to 1 again? This clearly isn't the case.
|
# ¿ Aug 11, 2013 14:35 |
|
|
# ¿ Apr 27, 2024 10:30 |
|
Thanks fellas. I don't often use vim, in fact I only used it in this instance because of the ability to set a variable and increment it like that which you can't do with just plain regex in other editors.
|
# ¿ Aug 11, 2013 17:57 |