I have 69 files in which I want to prepend lines 5 to penultimate with a short string. How could I address the penultimate line? :5,61s/^/X/g would do it if I manually look up that the last line is 62, but if I want to script it for all the files, how can I do that? I could imagine doing something like vim +:5,$((`cat test.txt|wc -l` - 1))s/^/X/g|:x test.txtfrom the command line, but as I'm not dealing with a simple search and replace as in my above example I think I won't be able to provide it from the command line, how can I do it from within vim?
specifying a range the last of which is the penultimate line
range
You can express the penultimate line with $-1. So, in your case, to prepend X in front of all the lines from the fifth down to the second to last one, you could use the following substitution command::5,$-1s/^/XYou can find more information on how to write a range in :help :range.