How to copy code from docs to an editor

Apologies for this naive question, but I haven't figured out a simple way to do this...

If I find some example of commands in some docs such as
Code:
# mkdir -p /usr/local/jails/templates/13.2-RELEASE-skeleton/home
# mkdir -p /usr/local/jails/templates/13.2-RELEASE-skeleton/usr
# mv /usr/local/jails/templates/13.2-RELEASE-base/etc /usr/local/jails/templates/13.2-RELEASE-skeleton/etc
# mv /usr/local/jails/templates/13.2-RELEASE-base/usr/local /usr/local/jails/templates/13.2-RELEASE-skeleton/usr/local
# mv /usr/local/jails/templates/13.2-RELEASE-base/tmp /usr/local/jails/templates/13.2-RELEASE-skeleton/tmp
# mv /usr/local/jails/templates/13.2-RELEASE-base/var /usr/local/jails/templates/13.2-RELEASE-skeleton/var
# mv /usr/local/jails/templates/13.2-RELEASE-base/root /usr/local/jails/templates/13.2-RELEASE-skeleton/root
and I want to paste it into my editor, I have to delete all the lines begining with #.

Is there a straightforward way of doing this, which I haven't stumbled upon?
 
It all depends on your editor.
If you are using vi,
:1,$ s/#//
In emacs crtl-meta-shift-5 brings up "query replace regex" then you enter
# RET RET !
 
Alternatively you can save it to temp.txt, and then run
sed -i "s|^# ||" temp.txt
and the copy the content of modified temp.txt into wherever you want it to be.

Yet another alternative would be to open the file in vim, place cursor on the first #, press Ctrl+V, go right once and down to the last line, and then press x (or d, I don't remember) to delete the selection.
 
If you're in VIM, <ctrl>-v works similar to <shift>-v, but it selects a block instead of whole lines. You can use <ctrl>-v to select a 'visual block', then 'd' to delete whatever the block selected.
 
Back
Top