Vim 101: Virtual Editing
Visual mode and Blockwise Visual mode have several associated settings. In this article, we’re going to look at virtualedit
, which is definitely something to consider adding to your .vimrc
.
To get up to speed with Visual mode, take a look at these previous Vim 101 articles:
The virtualedit
setting basically allows block selections to operate across lines regardless of the underlying text. In this screenshot, I've pressed CTRL-V
and selected a block. Notice how the block is limited to the characters in the file:
By typing set virtualedit=block
, rectangular selections can be made. The shorthand for this is set ve=block
. The cursor can now be placed anywhere — including after the ends of lines and in the middle of tabs:
Vim’s documentation for virtualedit
(:help 've'
) suggests this is useful for selecting text in tables — imagine a space-separated text file of tabular data.
If you’re laying out plain text files in a strict tabular structure, then using set ve=all
might be useful because moving beyond the end of a line and then switching to Insert mode and typing will cause extra spaces to be added. It's actually very intuitive.