Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday August 11, 2006
01:11 PM

How do I fix this bad vim mapping?

[ #30603 ]

OK, this is not behavior I was expecting. Sometimes I'll post code in places where I don't have code or ecode tags, so I need to manually encode the '&', '<' and '>' symbols. That gets very annoying, particularly since I often find myself encoding the ampersand last, screwing up the other encodings and having to redo it. I figured that a simple vim mapping would do this:

noremap ,e  :%s/&/\&amp;/g | %s/>/\&gt;/g |%s/</\&lt;/g<cr>

However, that fails because as soon as I source my .vimrc, it rus the second and third subtitutions! So I tried again:

noremap ,e :exe '%s/&/\&amp;/g | %s/>/\&gt;/g |%s/</\&lt;/g'<cr>

That does the same thing. What gives? Am I going to have to write a function for this?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • From the fine manual:

    Since the '|' character is used to separate a map command from the next
    command, you will have to do something special to include  a '|' in {rhs}.

    There are three methods:
       use       works when                    example
       <Bar>     '<' is not in 'cpoptions'     :map _l :!ls <Bar> more^M
       \|        'b' is not in 'c

    • How did you find that in the fine manual? "help |" doesn't help, nor does my various attempts at escaping the bar. (Well, I've had trouble escaping bars before, but I equivocate ...)

      • "nor do my various attempts".

      • How did you find that in the fine manual?

        I've actually read the entire manual (because I'm writing a book on Vim), so it was more a matter of remembering than finding.

        If I hadn't, then I would have typed:

        :help bar<TAB>

        (where that <TAB> is literally the act of hitting the TAB key). That would have produced:

        bar                cpo-bar            'toolbar'          gui-scrollbars
        :bar 

        • A book on vim? Thank god. We've desperately needed a really good one. A friend of mine is kind of a vim god and people keep telling him he needs to write such a book, but it's good to know it's actually going to get written. I'll buy it!

        • This is good news. We need a good book on vim. There's a lot of power that goes way under-exploited because of the lack of readable, well-indexed documentation.
    • Google can do a pretty good job of putting bars in maps, I suspect. :-)