Visual Mode
Visual mode is used to edit text by selecting them first
Selection can either be done using mouse or using visual commands
Selection
vstart visual selection, use any movement command to complete selectionve, vip, v)etc
Vvisually select current lineVgg, ggVGetc
Ctrl+vvisually select column(s)Ctrl+v3j2lto select a 4x3 block, etc
Editing
ddelete the selected textcclear the selected text and change to Insert mode- for visually selected column, after
ctype any text and pressEsckey. The typed text will be repeated across all lines
- for visually selected column, after
Iafter selecting withCtrl+v, pressI, type text and pressEsckey to replicate text across all lines to left of the selected columnAafter selecting withCtrl+v, pressA, type text and pressEsckey to replicate text across all lines to right of the selected columnrareplace every character of the selected text with a:perform Command Line mode editing commands likeg,s,!,normalon selected textJjoin selected lines with space character in betweengJjoin selected lines without any character in between:h visual-operatorsfor more info
Indenting
>indent the visually selected lines3>indent the visually selected lines three times<unindent the visually selected lines=indent code, taking care of nesting too. Example below
for(;;)
{
for(;;)
{
statements
}
statements
}
vip=to indent the code
for(;;)
{
for(;;)
{
statements
}
statements
}
Changing Case
~invert the case of visually selected text, i.e lowercase becomes uppercase and vice versaUchange visually selected text to UPPERCASEuchange visually selected text to lowercase
Further Reading
- For more info on Visual mode,
:h visual-mode - Visual mode tutorial
- Visual mode examples