0

(I'm really not sure how I would google this. Sorry if this has already been asked and please just link me in the right direction in that case)

I'm using Vim in cygwin environment and marked a line in visual mode using 0,v,$. When I then pressed :, Vim automatically wrote :'<, '> into the command line. I'm wondering what this does and what all the signs mean. The one thing I found using google is from the vim wiki.

:'<,'>w !cat > /dev/clipboard

Could you please explain this command step by step? I've been working with Vim for about a year now, but I still consider myself a complete newbie to it.

  • 1
    Consider V instead of 0v$ – user859 Apr 24 '17 at 10:38
3

Surprisingly, better than Google is to search in Vim's builtin help.

:h '<

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

:h '>

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

So this represents selected region, and it will run given command on those lines only.

  • '< - first visually selected line
  • , - till
  • '> - last visually selected line
  • w - write - will use only selected lines
  • ! - use/run external command (instead of file in this context)
  • rest is a shell command

Additional reads: :h v_:, :h :range, :h :w_c

  • 2
    Small addition: 'x refers to mark x. < and > are simply special marks automatically set on the beginning and end of the visual selection – Philippos Apr 24 '17 at 7:38
  • Those two answers came fast! Thanks! I completely forgot to check the inbuilt help. I'll accept this answer (but I'll wait a bit just incase some more answers fly in) – lucidbrot Apr 24 '17 at 7:39
  • it actually is :h ranges not :h range! Note the s. – mike Apr 24 '17 at 9:19
  • Note the : before range, or type :h E14, but :h ranges is also good, it's the same part of doc, it contains the :h :range. – grodzik Apr 24 '17 at 9:43
1

'<,'> is not a command, but a range. You can prefix any command with a range.

If you want to know more: :h ranges.

'<,'> is always displayed, when you select with visual mode and it refers to the selected text.

Basically, ranges allow you to narrow an ex command to the range given. Ranges can be specified via a number of ways:

  • relative line numbers
  • absolute line numbers
  • searches
  • marks
  • visual mode

On a sidenote, you might be interested to know, that V visually selects a whole line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.