2

I am trying to copy the selected text from vim into system clipboard.

In visual mode, i pressed :, and the command prompt string changed as, :'<,'> Running

:'<,'> !tee >(xsel -b)

added :'<,'> into the current buffer which is not the desired result.

Then i edited the command prompt string and ran it as, :'>,'> !tee >(xsel -b)

Selection area got copied into clipboard.

How is :'>,'> different from :'<,'>?

Original question

Saravana
  • 123
  • 5
  • Apart from answering your question, have you looked at http://vi.stackexchange.com/questions/84/how-can-i-copy-text-to-the-system-clipboard-from-vim for how to yank visual selection to system clipboard? – jjaderberg Jul 29 '15 at 17:15

1 Answers1

9

The '< and '> symbols mark the beginning and end of the last selected Visual area. For commands that take a range of lines or characters, '<,'> means that the range of the command is the selected area.

jjaderberg suggests that the '>,'> range expression following a Visual selection would mean that the last line of the selection alone constitutes the range that the filter works on. AFAICT, this is the case.

As for why the '<,'> range failed in that way, I'm sorry to say I have no idea. I haven't been able to reproduce it. If anyone knows, please edit this answer.

Documentation:

  • The '< / '> symbols: :h '<
  • Using a range with a filter: :h range!
  • Beginning a command-line with a Visual Line selection: :h v_:
Peter Lewerin
  • 545
  • 4
  • 10
  • there was a space before !. it is like, :'<,'> !tee >(xsel -b) – Saravana Jul 29 '15 at 16:56
  • @MadhavanKumar: you can have spaces between the range and the command. – Peter Lewerin Jul 29 '15 at 16:57
  • Are you sure you're not mixing up "!-filter" and "!-command"? See :help ! and :help :!. Filter takes a range (:help :range!). I don't understand why one would use '>,'> for a range, however, or how this particular command is supposed to work. – jjaderberg Jul 29 '15 at 17:12
  • @jjaderberg: yes, I did, thank you for pointing that out. I thought something looked off when I wrote that paragraph, but I didn't think to look at :h range!. I'll put on my thinking hat again. – Peter Lewerin Jul 29 '15 at 17:24
  • Well the question is about visual selection marks and you have partially answered that. What I don't understand is how '>,'>, ie "from last line of last visual selection to last line of last visual selection", can work for OP. Strictly the answer is "The one selects from beginning to end of last visual selection, the other from end to end", so if you add that and references to relevant help topics you have answered the question. If your thinking hat yields result I'd be interested to know how/why OPs command works. – jjaderberg Jul 29 '15 at 17:50
  • PS Usually (f.i., in a visual mode mapping) these mark motions don't work for a "currently highlighted" area–you have to add <Esc> to the mapping to leave visual mode first. The :h v_: case is different though. Also, I can't follow up now, but a possible reason why OPs command works is that a mark motion initiated with ' (as opposed to "") is linewise. Visually select a char, escape visual mode andd'>` will delete the entire line. If OP visually selected exactly one line, it may make sense that he finds in clipboard what he expects. No idea if that's what's happening. – jjaderberg Jul 29 '15 at 18:04
  • There's a thunderstorm and I shut down my equipment in the middle of editing that comment. I got the "escaped backtick" all wrong and I can't change it now, I hope it's legible despite the terrible mark(up|down) (single-quote is linewise, as opposed to backtick–that was the point). – jjaderberg Jul 29 '15 at 18:26
  • @jjaderberg: I can't convince myself that I've reproduced the OPs setup well enough, but I think you have it there. I'll amend the answer along those lines. BTW: I was thinking of when you initiate a : command while you have a selection in Visual mode, but that's neither here or there, really. – Peter Lewerin Jul 29 '15 at 18:43
  • That seems a good answer to me. Maybe someone else can a) confirm or deny that the '>,'> is equivalent to the last line of a selection (iaaa<Esc>hv:<Left><Left><Left><Bs>><Right><Right><Right>d<Cr> on empty buffer–i.e. visually select a char on a line, enter cmd-line mode, change the range to '>,'>, add d for a command, run it–tells me that it is) and b) explain why OPs command does not work with the standard '<,'> range. But that would be sugar, you've answered the actual question asked. – jjaderberg Jul 29 '15 at 19:13