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
v
start visual selection, use any movement command to complete selectionve, vip, v)
etc
V
visually select current lineVgg, ggVG
etc
Ctrl+v
visually select column(s)Ctrl+v3j2l
to select a 4x3 block, etc
Editing
d
delete the selected textc
clear the selected text and change to Insert mode- for visually selected column, after
c
type any text and pressEsc
key. The typed text will be repeated across all lines
- for visually selected column, after
I
after selecting withCtrl+v
, pressI
, type text and pressEsc
key to replicate text across all lines to left of the selected columnA
after selecting withCtrl+v
, pressA
, type text and pressEsc
key to replicate text across all lines to right of the selected columnra
replace every character of the selected text with a:
perform Command Line mode editing commands likeg,s,!,normal
on selected textJ
join selected lines with space character in betweengJ
join selected lines without any character in between:h visual-operators
for 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 versaU
change visually selected text to UPPERCASEu
change visually selected text to lowercase
Further Reading
- For more info on Visual mode,
:h visual-mode
- Visual mode tutorial
- Visual mode examples