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

Re: vb syntax highlighting for vim

Expand Messages
  • Tim Chase
    ... It looks like it s simply mis-identifying the file-type. You should be able to force it by issuing ... I ve got a project here at work where I m using M4
    Message 1 of 7 , Jul 22, 2005
    • 0 Attachment
      > I have copied the entire contents of a file in VBA (from MS Excel 97),
      > and pasted into a blank file. Renamed to a .vb extension, and I get no
      > highlighting. As another exercise I 'exported' the file from within VBA,
      > which produced a .cls file. I discovered that highlighting partially
      > (and badly) worked through the .cls vim syntax file. Of course I then
      > discovered that this isn't a MS-related syntax file at all, so of course
      > it doesn't work properly.
      >
      > So in other words, syntax highlighting is working, just not with this
      > syntax file. Are you able to help here?

      It looks like it's simply mis-identifying the file-type. You
      should be able to force it by issuing

      :set syntax=vb

      I've got a project here at work where I'm using M4 to preprocess
      my VB files, so I've got a bunch of *.inc files containing VB
      code...they show up as highlighted as (IIRC) POV ray-tracer files
      and look totally messed up. Forcing the syntax as above solves
      the problem for me. For a more lasting solution, you'd have to
      get the filetype detection to identify the *.cls files as VB
      files. This is done by default in filetype.vim, but if you want
      to override it, I suspect there's some per-user directory that
      can have files dropped in it. I think you create your own
      filetype.vim file in ~/.vim/ftplugin/ or ~/.vim/after/ you can
      have it detect as much automatically.

      The apropos section of the help is found at

      :help 43.2

      This still doesn't solve the problem of automatically detecting
      the file-type when pasting in an empty buffer, but that's just by
      design...an empty buffer has *no* file-type. So you should just
      be able to force it as above by manually setting 'syntax'

      Hope this helps,

      -tim
    • Tony Mechelynck
      ... From: Tim Chase To: Gregory Orange Cc: Sent: Friday, July 22, 2005 3:04 PM
      Message 2 of 7 , Jul 22, 2005
      • 0 Attachment
        ----- Original Message -----
        From: "Tim Chase" <vim@...>
        To: "Gregory Orange" <gregory.orange@...>
        Cc: <vim@...>
        Sent: Friday, July 22, 2005 3:04 PM
        Subject: Re: vb syntax highlighting for vim


        >> I have copied the entire contents of a file in VBA (from MS Excel 97),
        >> and pasted into a blank file. Renamed to a .vb extension, and I get no
        >> highlighting. As another exercise I 'exported' the file from within VBA,
        >> which produced a .cls file. I discovered that highlighting partially (and
        >> badly) worked through the .cls vim syntax file. Of course I then
        >> discovered that this isn't a MS-related syntax file at all, so of course
        >> it doesn't work properly.
        >>
        >> So in other words, syntax highlighting is working, just not with this
        >> syntax file. Are you able to help here?
        >
        > It looks like it's simply mis-identifying the file-type. You should be
        > able to force it by issuing
        >
        > :set syntax=vb
        >
        > I've got a project here at work where I'm using M4 to preprocess my VB
        > files, so I've got a bunch of *.inc files containing VB code...they show
        > up as highlighted as (IIRC) POV ray-tracer files and look totally messed
        > up. Forcing the syntax as above solves the problem for me. For a more
        > lasting solution, you'd have to get the filetype detection to identify the
        > *.cls files as VB files. This is done by default in filetype.vim, but if
        > you want to override it, I suspect there's some per-user directory that
        > can have files dropped in it. I think you create your own filetype.vim
        > file in ~/.vim/ftplugin/ or ~/.vim/after/ you can have it detect as much
        > automatically.
        >
        > The apropos section of the help is found at
        >
        > :help 43.2
        >
        > This still doesn't solve the problem of automatically detecting the
        > file-type when pasting in an empty buffer, but that's just by design...an
        > empty buffer has *no* file-type. So you should just be able to force it
        > as above by manually setting 'syntax'
        >
        > Hope this helps,
        >
        > -tim

        An empty buffer can have a filetype if it has a file name: for instance,

        :e foobar.htm

        gives the current buffer "html" filetype even if there isn't yet a file of
        that name. The filetype detection is done by autocommands triggered by
        BufRead,BufNewFile (BufRead when editing an existing file, after reading it
        into the buffer; and BufNewFile when the file doesn't yet exist).

        You could also use modelines (see ":help modeline") if you use files of
        different syntaxes with the same extension, or if you want to override the
        default filteype for some particular file. When pasting into an empty
        buffer, you would then create the modeline and issue the ":e" command
        without parameters to reload the file and re-evaluate the buffer options.

        Best regards,
        Tony.
      • Tim Chase
        ... Sorry...my mis-type. I intended to type new buffer , as opened by ... or ... or just opening vim with no arguments. As Tony alluded, if all your new
        Message 3 of 7 , Jul 22, 2005
        • 0 Attachment
          > An empty buffer can have a filetype if it has a file name: for
          > instance,
          >
          > :e foobar.htm

          Sorry...my mis-type. I intended to type "new buffer", as opened by

          :new
          or
          :enew

          or just opening vim with no arguments. As Tony alluded, if all
          your new buffers are going to be of type "VB", you can make use
          of the BufNew and BufNewFile events can be used to set a default
          syntax. However, there may be plenty of times you're using it
          for non-VB work, so it may be easier to simply map a command such as

          :nnoremap <f4> :set syntax=vb<cr>

          so you can just pound <f4> and have it automatically turn on VB
          syntax.

          -tim


          (PS: I replied to your original email, CC'ing to the vim@...
          list as there are folks like Tony better versed in the magic ways
          of where to properly put things so that future upgrades don't
          break things, and who can catch any mis-types or biff-ups I may
          have made. Hope you didn't mind :)
        • Tony Mechelynck
          ... From: Tim Chase To: Gregory Orange Cc: Tony Mechelynck ;
          Message 4 of 7 , Jul 22, 2005
          • 0 Attachment
            ----- Original Message -----
            From: "Tim Chase" <vim@...>
            To: "Gregory Orange" <gregory.orange@...>
            Cc: "Tony Mechelynck" <antoine.mechelynck@...>; <vim@...>
            Sent: Friday, July 22, 2005 4:23 PM
            Subject: Re: vb syntax highlighting for vim


            >> An empty buffer can have a filetype if it has a file name: for
            >> instance,
            >>
            >> :e foobar.htm
            >
            > Sorry...my mis-type. I intended to type "new buffer", as opened by
            >
            > :new
            > or
            > :enew
            >
            > or just opening vim with no arguments. As Tony alluded, if all
            > your new buffers are going to be of type "VB", you can make use
            > of the BufNew and BufNewFile events can be used to set a default
            > syntax. However, there may be plenty of times you're using it
            > for non-VB work, so it may be easier to simply map a command such as
            >
            > :nnoremap <f4> :set syntax=vb<cr>
            >
            > so you can just pound <f4> and have it automatically turn on VB
            > syntax.
            >
            > -tim
            [...]

            Or you can add (I don't know VB so I'm not sure this is proper syntax for a
            VB program comment) something like

            REM vim: ft=vb
            or
            REM vim: set ft=vb : set VB syntax in Vim

            near the top or bottom of the file so that /that/ file will always get vb
            filetype (and syntax) from then on. (see ":help modeline").

            Best regards,
            Tony.
          • Tim Chase
            ... If it s something she does frequently, you can make it even easier for her by either mapping it to a single keypress in your vimrc file: nnoremap :set
            Message 5 of 7 , Sep 2, 2005
            • 0 Attachment
              > For the time being I've got the user doing :set syntax=vb, and she is
              > happy. If it becomes something she has to use a lot, and it gets
              > cumbersome, then I'll pester you further.

              If it's something she does frequently, you can make it even
              easier for her by either mapping it to a single keypress in your
              vimrc file:

              nnoremap <f4> :set syntax=vb<cr>

              (all characters typed literally). That way, it's as simple as
              hitting <f4> (or whatever your key of choice is.

              Or, you can actually get vim to properly detect the file type.
              This is where I rely on the other smart folks on the list :) I
              never remember *where* to put the filetype detection. IIRC, it
              goes in something like ~/.vim/filetype.vim and would contain
              something along the lines of

              " other VB extensions...
              augroup filetypedetect
              au! BufRead,BufNewFile *.frm,*.bas setfiletype vb
              augroup END

              (at least according to the help: ":help new-filetype"). This
              should at least correctly set the file type for *.frm and *.bas
              files. If you're opening an empty buffer without a file name,
              Vim doesn't give it a filetype by default, so if you paste VB
              code into it, you'll have to set type filetype manually, as per
              the above mapping.

              > Thank you for your assistance in making such a fine tool work a little
              > bit better for us.

              Always glad to lend a hand.

              -tim
            • Hakim
              ... That s always annoyed me: having to edit a single monolithic file like that means that it s hard to automatically install a plugin to deal with a
              Message 6 of 7 , Sep 2, 2005
              • 0 Attachment
                Tim Chase wrote:

                > Or, you can actually get vim to properly detect the file type. This is
                > where I rely on the other smart folks on the list :) I never remember
                > *where* to put the filetype detection. IIRC, it goes in something
                > like ~/.vim/filetype.vim and would contain something along the lines of

                That's always annoyed me: having to edit a single monolithic file like
                that means that it's hard to automatically install a plugin to deal with
                a particular language or app. (So for example, the viki plugin - or
                some vim wiki plugin if not that one - has manual steps to edit
                filetype.vim).
                I *think* there's an option though to have multiple .vim files that do
                filetype checking, which could be cleaner, but dunno where this is
                documented. Any ideas?

                --
                osfameron
              • Tofer Chagnon
                ... Try :help new-filetype Tofer
                Message 7 of 7 , Sep 2, 2005
                • 0 Attachment
                  On 9/2/05, Hakim <hakim@...> wrote:

                  > I *think* there's an option though to have multiple .vim files that do
                  > filetype checking, which could be cleaner, but dunno where this is
                  > documented. Any ideas?
                  >

                  Try :help new-filetype

                  Tofer
                Your message has been successfully submitted and would be delivered to recipients shortly.