使用vim时,“'<,'>”代表什么?

14
在使用Vim时,在可视模式下选择文本,然后调用冒号命令会显示:'<,'>,而不是像其他操作(如打开文件)一样只显示:
那么'<,'>是什么意思呢?
这是一种特殊的记号,表示当前选择的行范围。其中<表示选择范围的起始行,>表示选择范围的结束行。在执行冒号命令时,这些标记告诉Vim应该将命令应用于所选文本的行。
1个回答

30

这意味着在:'<,'>之后键入的命令将对您选择的文件部分进行操作。

例如,:'<,'>d将删除所选块,而:d将删除光标下的行。

类似地,:'<,'>w fragment.txt会将所选块写入名为fragment.txt的文件中。

两个逗号分隔的东西('<'>)是标记,对应于所选区域的开头和结尾。如帮助页面所述(: help '<):

                                                       *'<* *`<*
'<  `<                  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}.

当在这种方式下使用时,这些标记仅仅指定了之后的命令所应用的范围(参见:help range)。它们当然可以与其他行号限定符混合使用。例如,下面的命令将删除从选定区域开头到文件末尾的所有行:

:'<,$d

Vim Wiki对Vim范围有更多信息


1
获取更多信息,请参阅:help range - Benoit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接