Stupid Unix tricks I learned today

If I don’t write this down in the next 5 minutes, I’ll surely forget it forever.

emacs had some problems opening a file when when it was checked into cvs. Then it had permissions problems when I moved the ,v file out of the way. The problem was that the disk was mounted on NFS and sudo doesn’t quite work over NFS.

Instead I decided to be a real man and use vi. First thing I had to do was insert the contents of a another file into the current one. No problem: :r (filename)

Then I had to substitute all $’s with \$’s. Hmm, that was a little tougher. :s subsitiutes only the first instance on one line. Adding /g does all on the line. To do them all, I had to use this magic incantation:

:1,$s/\/\$/g

The first part specifies the range to use.

Who said vi isn’t intuitive?

3 Comments

  1. But wait! There’s more.

    you can also do
    :%s/\/\$/g
    which does all instances of all of the lines. % is a short wildcard character for all lines.

    I’m pretty sure there’s a eleven key meta-combination for that in emacs, but I can’t remember it off hand.

Leave a Reply

Your email address will not be published. Required fields are marked *