简体   繁体   中英

Using vim, what is “ '<,'>”?

While using Vim, in visual mode, selecting text and then calling a colon command shows : '<,'> instead of just : as it would show when I do other things (such as opening a file).

What does '<,'> mean?

Using linux (debian) , gnome-terminal , vim7.2

It means that the command that you type after :'<,'> will operate on the part of the file that you've selected.

For example, :'<,'>d would delete the selected block, whereas :d deletes the line under the cursor.

Similarly, :'<,'>w fragment.txt would write the selected block to the file called fragment.txt .

The two comma-separated things ( '< and '> ) are marks that correspond to the start and the end of the selected area. From the help pages ( :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}.

When used in this manner, the marks simply specify the range for the command that follows (see :help range ). They can of course be mixed and matched with other line number specifiers. For example, the following command would delete all lines from the start of the selected area to the end of the file:

:'<,$d

The Vim Wiki has more information on Vim ranges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM