I installed zsh, and I'm using vi.

I want to copy a line from vi to somewhere else. How may I do this?

  • Could you clarify what is your environment: • are you using Terminal or xterm (from XQuartz)? • do you want to paste your line within vi or within another application? Which one?
    – dan
    Dec 7 '13 at 10:19
  • I enviroment is Mac Mavericks.yes,i want to paster line within vi another appliction.
    – fuyou001
    Dec 7 '13 at 13:10
  • Are you using Terminal or xterm or something else I haven't been able to guess?
    – dan
    Dec 7 '13 at 15:12
  1. Position the cursor where you want to begin copying.
  2. Press v (or upper case V if you want to cut whole lines).
  3. Move the cursor to the end of what you want to copy.
  4. Press y.
  5. Move to where you would like to paste.
  6. Press P to paste before the cursor, or p to paste after.

Source: http://vim.wikia.com/wiki/Copy,_cut_and_paste

  • thanks! you method only in vi .if i want to copy text from vi to System paste ?
    – fuyou001
    Dec 7 '13 at 6:47
  • Use the mouse :-)
    – nohillside
    Dec 7 '13 at 11:11
  • the mouse is not effect
    – fuyou001
    Dec 7 '13 at 13:09
  • Are you running vi inside Terminal? Selecting the text with the mouse and pressing Cmd-C will put it into the system clipboard.
    – nohillside
    Dec 7 '13 at 14:09

I can't remember if the default vi is vim or not. If it is, and you don't have the mouse, you can get things into the pasteboard by selecting a range (using visual mode) and writing it to pbcopy (similar to this answer)

:'<,'>w !pbcopy 
  • Yes vi on MacOS X is vim.
    – dan
    Dec 9 '13 at 21:54
  • i try it .it is cut,not copy
    – fuyou001
    Dec 10 '13 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .