Find the answer to your Linux question:
Results 1 to 4 of 4
Hi all, I'm trying to do a search and replace inside a visual block as shown below :s/\%V5043/g but it gives an error - Invalid character after \% Obviously, this ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    9

    VIM visual block search and replace


    Hi all,

    I'm trying to do a search and replace inside a visual block as shown below
    :s/\%V504\503/g

    but it gives an error - Invalid character after \%

    Obviously, this happens in search too.
    /\%V504

    But the same works in another machine. So I doubt I'm missing some configuration in VIM or some VIM package needs to be installed. Please help.

    --
    Regards,
    Subith Premdas

  2. #2
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    699
    Can you give us the text you have, and what you want it changed to?

    If you only give us your command, we can only assume what you want based on what is not working.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    I suspect that the problem has to do wit the magic settings on the two machines. The magic settings control when you need to provide \ certain search commands:

    Code:
                                                    'magic' 'nomagic'
    'magic'                 boolean (default on)
                            global
            Changes the special characters that can be used in search patterns.
            See pattern.
            NOTE: To avoid portability problems with using patterns, always keep
            this option at the default "on".  Only switch it off when working with
            old Vi scripts.  In any other situation write patterns that work when
            'magic' is on.  Include "\M" when you want to /\M.
    You might try this:
    Code:
    :%s/\v%V504/503
    Here the pattern is explicitly given a magic setting (with \v), meaning that the % does not require an escape, and that the values of 'magic' will be ignored.

  4. #4
    Just Joined!
    Join Date
    Jan 2011
    Posts
    9
    Hi Cabhan,

    Thanks for the reply. But this too didn't work.
    I get this error E71: Invalid character after \%

    Could you please help me how to set this magic settings, or how to check what setting do i currently have so that i can compare two machines and make changes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •