Reputation: 9649
It's quite straitforward for VI/M to mark a block of lines from Mth line to Nth line ready to delete, cut & past, or copy & paste.
:M,N d
:M,N m p
:M,N t p
If it's further required for VI/M to mark a block of characters from Ith character of Mth line to Jth character of Nth line, is it possible to accomplish similarly to the above?
@EDIT
Except the next answer asked for visual block mode
, how about the option on typing a succinct ex command?
@EDIT 2
To clarify the meaning of a block of characters:
visual block mode
, directly called upon by pressing Ctrl-v in normal mode
visual character mode
, directly called upon by pressing v in normal mode
visual line mode
, directly called upon by pressing V in normal mode
. In this case, the handy solution in ex mode
has been illustrated above when this topic was originally raised.@SOLUTION
Selecting abitrary zipzag area of successive characters from line M, column I to line N, column J in ex mode
exactly like in visual character mode
:
mark:
:normal! MggI|vNggJ|
delete:
:normal! MggI|vNggJ|d
yank:
:normal! MggI|vNggJ|y
move to line X column Y
:normal! MggI|vNggJ|dXggY|p
copy to line X column Y
:normal! MggI|vNggJ|yXggY|p
@SOLUTION 2
Selecting abitrary square block of characters from line M, column I to line N, column J in ex mode
exactly like in visual block mode
:
mark:
:execute "normal! MggI|\<C-v>NggJ|"
delete:
:execute "normal! MggI|\<C-v>NggJ|d"
yank:
:execute "normal! MggI|\<C-v>NggJ|y"
move to line X column Y
:execute "normal! MggI|\<C-v>NggJ|dXggY|p"
copy to line X column Y
:execute "normal! MggI|\<C-v>NggJ|yXggY|p"
Upvotes: 3
Views: 5305
Reputation: 53624
You can use visual block mode from an ex command mode using normal!
: for example, to select a block (line, column) from (42, 10) to (54, 20) and yank it (both lines must have at least 20 characters or virtualedit=block
should be set):
execute "normal! 42gg10|\<C-v>54gg20|y"
. It is very straightforward way to do this, useful only in scripts.
Note that this command has at least following side-effects:
'<
, '>
, '[
, ']
, ''
.@"
, @0
.v:count
and v:count1
variables.Upvotes: 4
Reputation: 1982
Ctrl+V enables visual block mode, then you can use the arrow keys to select the block.
Upvotes: 3