In Vim visual mode, why does the command start with '<,'>?
When I pop into Vim's visual mode to, for example, indent a block of text, the c开发者_如何学编程ommand 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.
'<
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.
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
It's a range defined by two special marks (a mark in an anchor in the text named as "quote+1 letter")
'< `< To the first line or character of the last selected Visual area in the current buffer. For block mode it may also be the last character in the first line (to be able to define the block). {not in Vi}.
'> `> To the last line or character of the last selected Visual area in the current buffer. For block mode it may also be the first character of the last line (to be able to define the block). Note that 'selection' applies, the position may be just after the Visual area. {not in Vi}.
Source
Once you select in Visual Mode e.g. five lines, then '<,'>
means that you will execute the command in that region.
so :'<,'>s/replaceMe/WithThis/g
will apply to only that selection
Taking the time to add some points of trivia to the already given answers
:*
usually means the same (:he cpo-star
),hitting
C-u
in command line mode removes the range marker (actually, removes to the beginning of the line)
精彩评论