In comp.editors, Ottavio Caruso <
ottavio2006...@yahoo.com> wrote:
You've already gotten one response, just adding some other ideas.
> ------------
>
> This is block 1
> some text in block 1
> some text in block 1
> some text in block 1
> some text in block 1
> End block 1
>
> This is block 2
> some text in block 2
> some text in block 2
> some text in block 2
> some text in block 2
> End block 2
>
> This is block 3
> some text in block 3
> some text in block 3
> some text in block 3
> some text in block 3
> End block 3
>
> ------------
>
> I want to move block 2 and paste it after block 3.
Since your blocks are clearly marked at start and end, you can use the
ex move command very easily:
:/This is block 2/,/End block 2/ move /End block 3/
Or, to include the blank lines:
:/This is block 2/,/End block 2/+1 move /End block 3/+1
More generally:
: (start address), (end address) action (action arg)
Where start address defaults to current line, and if end address is
ommited will default to the start line (single line action).
> Is it possible to mark the beginning and the end of a block and then
> "cut" it and put it in the buffer?
I use ex commands with named marks very regularly. I have some
conventions for remembering what mark is what. To me:
'a a starting address
'e an ending address
'm an alternative to the unnamed mark, ''
To create a mark in vi mode: use "mn" where "m" starts the mark action
and "n" is the name of the mark. "mm" is super easy to type, hence my
use as the alternative alternative to the unnamed mark (ie a very
short lived mark for some particular need).
Other marks as needed, usually some initial as a mnemonic, eg
'v variable init
'f start of sub foo
'z zookeeper config
> In vim, this is easy: put the cursor at the beginning of the block,
> press "P", down arrow till the end of the block, "dd" and then "p" will
> paste the text.
In any vi or vi clone:
This is easy: put the cursor at the beginning of the block,
press "ma" to create mark a, move to the end of the block eg "}"
works well for blank line delimited blocks, "d'a" to delete to
mark a (storing in unnamed buffer) and then move to desired new
location and "p" will paste the text.
For the ex style interface you can ":mark a" to put mark a on the
current line and dereference the marks in a manner similar to vi:
:'a, 'e move 'm
The 'move' and 'mark' ex commands can both be abbreviated, to 'm' and
'ma' respectively, but that might be harder to remember.
Marks will be cleared when the line they are on is deleted or moved.
Marks will not be cleared, and will follow the line when other lines
are added or deleted.
line 1
line 2 mark a
line 3
line 4 mark e
line 5
line 6 mark m
line 7
line 8 mark z
line 9
Delete line 1, and all the marks shift up:
new line 1 mark a
new line 2
new line 3 mark e
new line 4
new line 5 mark m
new line 6
new line 7 mark z
new line 8
: 'a, 'e move 'm
post-move line 1
post-move line 2 mark m
post-move line 3 old mark a, no mark now
post-move line 4
post-move line 5 old mark e, no mark now
post-move line 6
post-move line 7 mark z
post-move line 8
Because so many commands operate based on movements, learning and using
a variety of movements (eg the paragraph move "{" and "}" I mentioned
earlier) can make your time in vi go faster. But if those various
commands are too hard to remember or mentally calculate, then using the
named marks becomes a powerful substitute.
Elijah
------
is friends with all the movements