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

前端 未结 5 1057
醉酒成梦
醉酒成梦 2021-01-04 09:47

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 w

相关标签:
5条回答
  • 2021-01-04 10:13

    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)

    0 讨论(0)
  • 2021-01-04 10:23

    '< 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.

    0 讨论(0)
  • 2021-01-04 10:29

    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
    
    0 讨论(0)
  • 2021-01-04 10:30

    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

    0 讨论(0)
  • 2021-01-04 10:33

    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

    0 讨论(0)
提交回复
热议问题