Since the exact command depends on the editor/ide and possibly the OS, please specify your environment.
–
David HarrisDec 28 '10 at 21:39

2

This question was mistakenly migrated to meta. This is a question not only about here on Ask Ubuntu - but in any application. Answers should be application independent whenever possible.
–
Marco Ceppi♦Dec 29 '10 at 2:38

4 Answers
4

The first xsel -b reads the clipboard, sed adds four spaces (^ matches start-of-line), then the second xsel -b puts it back on the clipboard. Drop the -b to use the primary selection instead (the middle-click-paste buffer).

Example:

# put two lines in the clipboard, "abc" and "123", for the example
# the \n is a newline, and echo adds another newline to the end
$ echo $'abc\n123' | xsel -b

If you're already in an editor, it surely supports some way of doing this easily (maybe just selecting lines and pressing tab), but this works outside of any specific editor.
–
Fred NurkDec 29 '10 at 5:05

1

This is great. I've added a keyboard shortcut to run xsel -b | sed "s/^/$(zenity --entry --title "Modify clipboard" --text "Enter text to be prepended to each line in the clipboard:")/" | xsel -b.
–
ændrükDec 30 '10 at 0:54

@ændrük: There are some special characters you need to be careful of (or escape) with that method, but otherwise, I'm glad it works well.
–
Fred NurkDec 31 '10 at 22:12

I use the pentadactyl plug-in for Firefox. (This is a successor to the vimperator plugin.)

Besides a lot of other great features, it lets you edit any text box in a webpage with an external editor. (You press Ctrl-I when editing the text box and an editor opens; when the editor saves the file, it is automatically copied back into the text box.) I use gvim as my external editor. In (g)vim, the > key in visual mode (i.e., when characters are selected or highlighted) will indent all the selected lines by an amount you set in your .vimrc.

There are ways of setting up pentadactyl to tell gvim what filetype is being edited (e.g., html or markdown for this page, or bbcode for the Ubuntu forums, etc., so you can use filetype-specific plugins and even get syntax highlighting.)

I regularly use Gedit's automatic tab indentation, so for this to work I would have to first set Edit ▸ Preferences ▸ Editor ▸ Insert spaces instead of tabs, then press Tab , and then unset Edit ▸ Preferences ▸ Editor ▸ Insert spaces instead of tabs again, which I feel is a little too cumbersome.
–
ændrükDec 29 '10 at 21:55