Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vim visual mode, why does the command start with '<,'>?

Tags:

vim

When I pop into Vim's visual mode to, for example, indent a block of text, the command prompt always starts with '<,'>. Can someone break down for me why this is or rather what it does? It seems like it's got something to do with markers but I'm not entirely sure of this based on the manual stuff I've read so far.

like image 679
buley Avatar asked Oct 13 '11 19:10

buley


2 Answers

'< is the first line visually selected, and '> is the last line visually selected. This is vim's way of making your command apply to only the visual area.

like image 106
Ned Batchelder Avatar answered Sep 21 '22 21:09

Ned Batchelder


The '<,'> at the beginning of your command line represents the range which you have selected . This is the also the range of test onto which the command you are about to enter would be applied.

For example if I selected a region of text in visual mode and then wanted to replace all occurrences of 'stack' with 'overflow' my command would look like:

:'<,'>s/stack/overflow/g

Without visual mode this same command would have to be accomplished by specifying the line range by hand eg:

:1,10s/helo/hello/g
like image 33
dtyler Avatar answered Sep 20 '22 21:09

dtyler