Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 795
Soyuz Avatar asked Jan 17 '12 16:01

Soyuz


1 Answers

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.

like image 178
NPE Avatar answered Oct 12 '22 11:10

NPE