Skip to main content
replaced http://vi.stackexchange.com/ with https://vi.stackexchange.com/
Source Link

I read this description of a different example, substitute commandsubstitute 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:

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

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?

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:

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

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?

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:

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

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?

code formatting for sample input, please
Source Link
muru
  • 25.4k
  • 8
  • 86
  • 146

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"start1 on some line, followed by text, followed by a line that contains "start2"start2, followed by a line that has "end"end. In outline, like this:

texttexttext

.Rh start1

.Rf some text

some more

...

.Rh start2

more text

...

.Rh end

textytextytext

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

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

The way I read it so far, :g /start1/... says to globally search for "start1"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?

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:

texttexttext

.Rh start1

.Rf some text

some more

...

.Rh start2

more text

...

.Rh end

textytextytext

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?

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:

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

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?

Source Link
Addem
  • 141
  • 6

How does this search-and-replace command work? `:g /start1/.,/start2/-1 move /end/-1`

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:

texttexttext

.Rh start1

.Rf some text

some more

...

.Rh start2

more text

...

.Rh end

textytextytext

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?