Skip to main content
Fix typo
Source Link
Antony
  • 2.6k
  • 12
  • 19

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principle.

Another option is to indent your lines, and then use the '[ and '] marks, which delimit previously changed text:

:3,4> | '[,']m1

This still isn't a condensing, but for more complicated ranges it may be worth the effort, and might be your best bet. But maybe for simple edits do the simple thing.

Finally: I guess we're talking about general principles here. But in this particular case, after your step #2, the Normal mode commands dd>jjp would also achieve the same result.

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principle.

Another option is to indent your lines, and then use the '[ and '] marks, which delimit previously changed text:

:3,4> | '[,']m1

This still isn't a condensing, but for more complicated ranges it may be worth the effort, and might be your best bet. But maybe for simple edits do the simple thing.

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principle.

Another option is to indent your lines, and then use the '[ and '] marks, which delimit previously changed text:

:3,4> | '[,']m1

This still isn't a condensing, but for more complicated ranges it may be worth the effort, and might be your best bet. But maybe for simple edits do the simple thing.

Finally: I guess we're talking about general principles here. But in this particular case, after your step #2, the Normal mode commands dd>jjp would also achieve the same result.

changed text marks
Source Link
Antony
  • 2.6k
  • 12
  • 19

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principle. For

Another option is to indent your lines, and then use the '[ and '] marks, which delimit previously changed text:

:3,4> | '[,']m1

This still isn't a condensing, but for more complicated ranges it may be worth the effort, butand might be your best bet. But maybe for simple edits do the simple thing.

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principle. For more complicated ranges it may be worth the effort, but for simple edits do the simple thing.

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principle.

Another option is to indent your lines, and then use the '[ and '] marks, which delimit previously changed text:

:3,4> | '[,']m1

This still isn't a condensing, but for more complicated ranges it may be worth the effort, and might be your best bet. But maybe for simple edits do the simple thing.

shift indented lines
Source Link
Antony
  • 2.6k
  • 12
  • 19

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principalprinciple. For more complicated ranges it may be worth the effort, but for simple edits do the simple thing.

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

That's hardly a condensing of the original command but shows the general principal. For more complicated ranges it may be worth the effort, but for simple edits do the simple thing.

Short answer: no.

You can use the :global command to pick some lines to operate on, and then give a sequence of commands to operate on those selected lines:

:3,4 g/^/ > | m1

We're only interested in the range, but :g also wants a pattern. So in this case we'll just use /^/ which will always match in a line.

This however moves each line in sequence which reverses the order of the moved lines. A simple way to rectify this is to mark the last inserted line (line 2 at this point) before you start the :global and move the indented lines before it:

:k x | 3,4 g/^/ > | m 'x-

Or you could shift each line up by 2, provided you know you've inserted exactly 2 new lines:

:3,4 g/^/ > | m-2

That's hardly a condensing of the original command but shows the general principle. For more complicated ranges it may be worth the effort, but for simple edits do the simple thing.

Fix reversal.
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading