Visual Block Mode

(This reference page is modified from Sandip Chitale's Rectangular Edit documentation. Thanks Sandip.)

Block Mode in action

This NetBeans screenshot shows a visual block mode selection. Notice that the status bar displays both jVi's current mode and the dimensions of the block mode selection. The cursor is in the lower right corner of the selected block. It can be moved around with the arrow keys to extend and shrink the selection. There are commands to shift the cursor to other corners.

Notes for non vi/vim users using Block Mode

Selecting a Rectangular Region

o lower case,
moves cursor to
opposite corner
O upper case,
moves cursor to
other end of line
end result
of entering
oO
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
Notice that entering oOoO touches all four corners returning the cursor to its original position.

When there are TABS in the selection, the display may not look correct, however the commands behave correctly.

Block Mode Commands

Note that most commands that add text take an optional count, in particular the p, P, I and A commands, this results in tiling the block. See the last example.

By default the delete, yank and put commands operate on an internal buffer. To use them with the clipboard, prepend the command with "*. For example, "*d deletes the block and places the text in the clipboard. (the double quote is part of the command).

When jvi (vim) puts block mode data into a buffer, the d and y commands, it marks that buffer as containing block mode data. The P command behaves differently if the buffer does not contain block mode data.

The following examples all assume the buffer has block mode data. The last examples show advanced command features in action.

If there are TABS in the selection, they are "split" as needed to square things up.

Selection
Command Result Buffer
0123456789
0123456789
0123456789
0123456789
0123456789
x or d
delete
0123456789
01789
01789
01789
0123456789
2345
2345
2345
0123456789
0123456789
0123456789
0123456789
0123456789
y
yank
0123456789
0123456789
0123456789
0123456789
0123456789
2345
2345
2345
01234
01234
01234
01234
01234
P uppercase
put before
cursor,
from buffer
01234
01-- 234
01++++ 234
01*****234
01234
--
++++
*****
no change
01234
01234
01234
01234
01234
p lowercase
put after
cursor,
from buffer
01234
012-- 34
012++++ 34
012*****34
01234
--
++++
*****
no change
In next, buffer first provides the source data,
then it is replaced by what was deleted.
01234567
01234567
01234567
01234567
01234567
P or p
replace
selected
from buffer
01234567
01-- 567
01++++ 567
01*****567
01234567
after
234
234
234
0123456789
0123456789
0123456789
0123456789
0123456789
rx
replace all
with char
0123456789
01xxxxx789
01xxxxx789
01xxxxx789
0123456789
no change
0123456789
0123456789
0123456789
0123456789
0123456789
c-+*<ESC>
change each
line selection
to user text
0123456789
01-+*789
01-+*789
01-+*789
0123456789
no change
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
U

Uppercase
aBcDeFgHiJ
aBCDEFGHiJ
aBCDEFGHiJ
aBCDEFGHiJ
aBcDeFgHiJ
no change
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
u

Lowercase
aBcDeFgHiJ
aBcdefgHiJ
aBcdefgHiJ
aBcdefgHiJ
aBcDeFgHiJ
no change
01234
01234
01234
01234
01234
I#*<ESC>
insert
before block
01234
0#*1234
0#*1234
0#*1234
01234
no change
01234
01234
01234
01234
01234
A*#<ESC>
append
after block
01234
0123*#4
0123*#4
0123*#4
01234
no change
Notice that the behavior of I and A are different when short lines are included in the selection. This is intentional so that both types of behavior are available.
01234
01234
0
0
01234
01234
I+=<ESC>
insert
before block
01234
01+=234
0
0
01+=234
01234
no change
I, insert, does not affect short lines (above).
A, append, modifies short lines (below).
01234
01234
0
0
01234
01234
A++<ESC>
append
after block
01234
0123++4
0 ++
0 ++
0123++4
01234
no change
The following example shows how p, the put command, inserts blanks after short lines to complete a put. The $ in the example command move the cursor to the end of the line.
01234
01234
0
0
01234
01234
y$p
put extends
short lines
if needed
01234
01234012
0 0
0 0
01234012
01234
012
0
0
012
Here is an example using a count with the put command. The buffer contents are shown before the command is exectued.
0123
0123
0123
0123
0123
3p
tile three
copies of
buffer
0123
01ababab23
01cdcdcd23
01efefef23
0123
ab
cd
ef
no change