We can do actions on a selection, just like any other ranges. While we have text
selected in visual mode, with
: we can enter command mode and the prompt will
be pre filled with
'<: Start of selection.
'>: End of selection.
It works like any other ranges like
12,15 which means from line 12 to line 15.
Save to a new file
We can save the selected content into a new file with
w, the command will look
Pipe to a shell command
We can do some fancy magic with
'<,'>!cmd. The output of the command will
replace the selected content. A few examples:
'<,'>!sort: sort selected lines with the
'<,'>!sort | uniq': Sort and remove duplicated lines.
'<,'>!pandoc -f markdown -t html': Convert markdown to HTML.
'<,'>!python3': Evaluate with
python3and replace with the output.
2021-12-07 00:00 +0000