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

When I appear in visual Vim mode, for example, to indent a block of text, the command line always starts with '<,'> . Can someone break for me why this or, more precisely, what is he doing? It seems like it has something to do with markers, but I'm not quite sure about this, based on the materials I have read so far.

+4
source share
5 answers

'< is the first line visually selected, and '> is the last line selected. This is a vim way to make your team apply only to the visual area.

+6
source

'<,'> at the beginning of your command line represents the range that you have selected. It is also the range of the test to which the command you are about to enter will be entered.

For example, if I selected a text area in visual mode, and then wanted to replace all occurrences of the β€œstack” with β€œoverflow”, my command would look like this:

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

Without visual mode, the same command must be executed by specifying a range of lines manually, for example:

 :1,10s/helo/hello/g 
+7
source

This is a range defined by two special marks (anchor mark in the text with the name "quote + 1 letter")

'<`& L; The first line or character of the last selected Visual area in the current buffer. For block mode, this can also be the last character in the first line (to define a block). {not in Vi}.

'> `> To the last line or character of the last selected Visual area in the current buffer. For block mode, this may also be the first character of the last line (to define a block). Please note that the "selection" applies, the position may be immediately after the visual area. {not in Vi}.

Source

+7
source

As soon as you select in Visual mode, for example. five lines, then '<,'> means that you execute a command in this region.

therefore :'<,'>s/replaceMe/WithThis/g will only apply to this selection

+4
source

Taking the time to add some trivia points to the answers already provided

  • :* usually means the same ( :he cpo-star ),

  • pressing Cu in command line mode deletes the range marker (in fact, deletes the beginning of the line)

+1
source

All Articles