Loading ...
Sorry, an error occurred while loading the content.

Re: Ignoring C comments with diffexpr

Expand Messages
  • Gary Johnson
    ... Here s what I ve done in my ~/.vimrc to add the -d option to diff on Unix. I used the MyDiff() function in the default Windows _vimrc as an example. set
    Message 1 of 2 , Oct 31, 2011
    • 0 Attachment
      On 2011-10-31, subhash wrote:
      > Hi,
      >
      > Could someone help me understand how to set up diffexpr variable in
      > vim (by defining my own diff function) so that I can ignore C comments
      > while diff'ing. (i.e. // or /* .... */). There seems to be a way in "
      > diff -I RE ..., " but I am not able to figure it out by myself. Would
      > be great if someone can actually give a snippet of their function as
      > an example.

      Here's what I've done in my ~/.vimrc to add the -d option to diff on
      Unix. I used the MyDiff() function in the default Windows _vimrc as
      an example.

      set diffexpr=MyDiff()
      function MyDiff()
      let opt = ""
      if &diffopt =~ "icase"
      let opt = opt . "-i "
      endif
      if &diffopt =~ "iwhite"
      let opt = opt . "-b "
      endif
      silent execute "!diff -d -a --binary " . opt . v:fname_in . " " . v:fname_new .
      \ " > " . v:fname_out
      endfunction

      As an experiment, I modified the line containing the diff command to
      add this option:

      -I '//'

      As a result, lines beginning with // but containing different text
      in two test files were not highlighted as different by vimdiff.
      However, in the time I allowed myself, I couldn't refine the regular
      expression to match only comment lines or to match /* and */. I
      hope this is of some help anyway.

      Regards,
      Gary

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    Your message has been successfully submitted and would be delivered to recipients shortly.