Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less viewer: Copy all the lines to clipboard

Tags:

linux

editor

There has already been a post in stackoverflow for VI editor for copying all the text into the clipboard. (Copy all the lines to clipboard) I want to do the same thing with the less viewer. I tried to search online for the process called "yank" and I did not find anything for it.

How do I copy all lines in the less editor into the clip board.

And I cannot close less and reopen it in vi. It is because of the fact that I have managed to load this file into the editor and while I have loaded it, the file has already been moved in the back end. It is a long story. The easiest solution for me now is to copy the contents of the file into memory.

like image 524
xarzu Avatar asked Aug 14 '14 20:08

xarzu


People also ask

How do I copy all the lines in vi editor and paste in notepad?

Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

How do I copy and paste from less?

You can repurpose less's 'v' command for this. When less runs, press 'v' to open the present file in the $EDITOR; in this case, open it with xsel -ib < {the file's name} . Using xsel -ib puts the data on the clipboard, so you can ctrl-V to paste the data where you want it.

How do I copy whole content in Linux?

CTRL A means "Mark the entire file. CTRL C means "Copy the selection.

How do I copy text from vi editor to clipboard?

In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard. Go to any external application and CMD + v to paste.


1 Answers

less doesn't have a clipboard, but you may be able to get it to output what's stored in its buffers to a new file. This will only work if the entire contents of the file are buffered:

  1. Type g to go to the top of the file
  2. Type | (that's a pipe character, not an L or I) to indicate that you want to output to a pipe
  3. Type $ to indicate that you want the output content to go to the end of the file
  4. Type dd of=/path/to/new/file and press Enter

The dd command will take the piped data and save it to the file passed to the of= argument.

like image 181
depquid Avatar answered Sep 29 '22 22:09

depquid