I read this description of a different example, substitute command and it was very helpful, but I'm still not fully certain how to interpret the commands in :g /start1/.,/start2/-1 move /end/-1. It is supposed to be something that has the text start1 on some line, followed by text, followed by a line that contains start2, followed by a line that has end. In outline, like this:

.Rh start1 
.Rf some text 
some more 
.Rh start2 
more text 
.Rh end 

The search-and-replace command is supposed to take everything from .Rh start1 to just before .Rh start2 and move it between .Rh end and textytextytext.

The way I read it so far, :g /start1/... says to globally search for start1 and do .... Now since the ... is .,/start2/-1 move /end/-1 what does this mean? I take the . to be a regex for "any character", which is just followed by a comma. Is Vim searching for that character-comma combination? Or is it replacing the start1 line with it?

1 Answer 1


After reading some websites I think I may have answered my own question. I believe the behavior goes like this:


indeed means, throughout the document, search for "start1" and do "...".

The "..." is .,/start2/-1 ... where the . is actually not a regex but a Vim symbol that effectively refers to the line on which the search string was found, and the comma means "select everything from the first part to the next part". The first part was, as we've seen, the line on which "start1" appears. The next part is the start2/-1 which is the next line on which "start2" appears, and then back-stepped by 1. So this effectively selects everything from start1 to start2, not including the line containing start2.

The command move is then given and blah blah blah the rest is obvious.

  • "After reading some websites […]" Why don't you read Vim's built-in documentation instead?
    – romainl
    Feb 1, 2016 at 6:52
  • I've read that too, up to a point. But it is at times not the most readable, so I try to check out many sources.
    – Addem
    Feb 1, 2016 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.