AASHISH SHARMA
AASHISH SHARMA

Reputation: 73

angle brackets when selecting a block of text in vim in visual mode

Whenever I select a block of text in normal mode and then hit : to write a command :'<,'> sign appears. What is the use/meaning of this.It does not happen when I have not selected a block of text or using normal mode.

I am using gnome terminal in manjaro.

Upvotes: 0

Views: 247

Answers (1)

romainl
romainl

Reputation: 196556

Editing-related Ex commands (the commands you type after :, like :s) work on a line, this is an "address":

" the line is not specified so current line is assumed
:s/foo/bar

" works on the current line
:.s/foo/bar

" works on line 5
:5s/foo/bar

or on several lines, this is a "range":

" works on lines from 5 through 10
:5,10s/foo/bar

Vim is not limited to line numbers: you can use lots of things that can ultimately be turned into a line number. For example:

" works on the second line above the current line
:-2s/foo/bar

" works on lines from mark 'a through next occurrence of "potemkine"
:'a,/potemkine/s/foo/bar

In this case…

  • '< is an automatic mark placed by Vim at the beginning of the last visual selection,
  • '> is another automatic mark placed by Vim at the end of the last visual selection,
  • '<,'> is a range that covers the last visual selection.

Since you were in visual mode before pressing :, Vim assumes that you want to do something with the selection and helpfully inserts the appropriate range for you.

See :help :range, :help '<, and :h v_:.

Upvotes: 2

Related Questions