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

when is filetype set?

Expand Messages
  • Michael P. Soulier
    Hey people. I m trying to put some logic in my .vimrc file so that different options are set when the filetype or syntax is set to mail . However, filetype
    Message 1 of 5 , Jan 2, 2001
    • 0 Attachment
      Hey people. I'm trying to put some logic in my .vimrc file so that different
      options are set when the filetype or syntax is set to "mail". However, filetype and
      syntax don't seem to be set at that point, even though it appears that they should
      be if I read the output from verbose.
      I'd like to do something like this:

      " Turn on syntax shading, depending on a few things.
      " I don't want it for mail, too hard to read.
      if &filetype == "mail"
      " Also, set it to wrap lines if we're editing mail.
      set textwidth=78
      " And lose the auto-indent.
      set noautoindent
      " Turn off syntax shading.
      syntax off
      " Have it on by default.
      else
      syntax on
      endif

      Will this not work at all in the .vimrc file?

      Mike

      --
      Michael P. Soulier <msoulier@...>
      "...the word HACK is used as a verb to indicate a massive amount
      of nerd-like effort." -Harley Hahn, A Student's Guide to UNIX
      PGP Public Key: http://www.storm.ca/~msoulier/email.phtml
    • Janakiraman .S
      ... I dont think so. You will need to execute this each time you load a buffer. Also syn off turns syntax highlighting off on all buffers. syn clear will clear
      Message 2 of 5 , Jan 3, 2001
      • 0 Attachment
        * Michael P. Soulier (msoulier@...) wrote thusly :

        > Hey people. I'm trying to put some logic in my .vimrc file so that
        > different options are set when the filetype or syntax is set to
        > "mail". However, filetype and syntax don't seem to be set at that
        > point, even though it appears that they should be if I read the output
        > from verbose.
        > I'd like to do something like this:
        >
        > " Turn on syntax shading, depending on a few things.
        > " I don't want it for mail, too hard to read.
        > if &filetype == "mail"
        > " Also, set it to wrap lines if we're editing mail.
        > set textwidth=78
        > " And lose the auto-indent.
        > set noautoindent
        > " Turn off syntax shading.
        > syntax off
        > " Have it on by default.
        > else
        > syntax on
        > endif
        >
        > Will this not work at all in the .vimrc file?

        I dont think so. You will need to execute this each time you load a
        buffer.

        Also syn off turns syntax highlighting off on all buffers.
        syn clear will clear it for the current buffer alone.

        I suggest using autocommands to achieve what you want.
        Something like

        " Set up your defaults for all files
        syn on
        au FileType * se cindent nu
        " Specific to files of filetype mail
        au FileType mail syn clear
        au FileType mail se tw=78 noai

        :he autocmd
        :he FileType
      • Michael P. Soulier
        ... Gotcha. ... Ok, I had to tweak this a bit because it was conflicting with other settings, but I believe it s finally working. Thanks for your help, and
        Message 3 of 5 , Jan 3, 2001
        • 0 Attachment
          On Wed, Jan 03, 2001 at 03:10:54PM +0530, Janakiraman .S wrote:

          > I dont think so. You will need to execute this each time you load a
          > buffer.
          >
          > Also syn off turns syntax highlighting off on all buffers.
          > syn clear will clear it for the current buffer alone.

          Gotcha.

          > I suggest using autocommands to achieve what you want.
          > Something like
          >
          > " Set up your defaults for all files
          > syn on
          > au FileType * se cindent nu
          > " Specific to files of filetype mail
          > au FileType mail syn clear
          > au FileType mail se tw=78 noai

          Ok, I had to tweak this a bit because it was conflicting with other
          settings, but I believe it's finally working.

          Thanks for your help, and I'll read up the docs again. ;-)

          Mike

          --
          Michael P. Soulier <msoulier@...>
          "...the word HACK is used as a verb to indicate a massive amount
          of nerd-like effort." -Harley Hahn, A Student's Guide to UNIX
          PGP Public Key: http://www.storm.ca/~msoulier/email.phtml
        • Benji Fisher
          ... Does this work? I do not think it should. IIRC, the standard Syntax autocommands are defined after the vimrc file is sourced. Since autocommands are
          Message 4 of 5 , Jan 3, 2001
          • 0 Attachment
            "Michael P. Soulier" wrote:
            >
            > On Wed, Jan 03, 2001 at 03:10:54PM +0530, Janakiraman .S wrote:
            >
            > > I dont think so. You will need to execute this each time you load a
            > > buffer.
            > >
            > > Also syn off turns syntax highlighting off on all buffers.
            > > syn clear will clear it for the current buffer alone.
            >
            > Gotcha.
            >
            > > I suggest using autocommands to achieve what you want.
            > > Something like
            > >
            > > " Set up your defaults for all files
            > > syn on
            > > au FileType * se cindent nu
            > > " Specific to files of filetype mail
            > > au FileType mail syn clear
            > > au FileType mail se tw=78 noai
            >
            > Ok, I had to tweak this a bit because it was conflicting with other
            > settings, but I believe it's finally working.
            >
            > Thanks for your help, and I'll read up the docs again. ;-)
            >
            > Mike

            Does this work? I do not think it should. IIRC, the standard Syntax
            autocommands are defined after the vimrc file is sourced. Since
            autocommands are executed in the order they are defined, I do not think
            yours will have any effect. Maybe if you put it in the gvimrc instead of
            the vimrc...

            There is a way to customize syntax highlighting. It will be
            different (and easier) in vim 6.0. If you are planning to RTFM, I suggest
            the following topics:

            :help startup
            :help mysyntaxfile

            HTH --Benji Fisher
          • Michael P. Soulier
            ... In my case, I actually have it this way, partly taken from Sven s .vimrc: Only do this part when compiled with support for autocommands. if
            Message 5 of 5 , Jan 3, 2001
            • 0 Attachment
              On Wed, Jan 03, 2001 at 01:53:55PM -0500, Benji Fisher wrote:

              > > > " Set up your defaults for all files
              > > > syn on
              > > > au FileType * se cindent nu
              > > > " Specific to files of filetype mail
              > > > au FileType mail syn clear
              > > > au FileType mail se tw=78 noai
              >
              > Does this work? I do not think it should. IIRC, the standard Syntax
              > autocommands are defined after the vimrc file is sourced. Since
              > autocommands are executed in the order they are defined, I do not think
              > yours will have any effect. Maybe if you put it in the gvimrc instead of
              > the vimrc...

              In my case, I actually have it this way, partly taken from Sven's .vimrc:

              " Only do this part when compiled with support for autocommands.
              if has("autocmd")

              augroup cprog
              " Remove all cprog autocommands
              au!

              " When starting to edit a file:
              " For C and C++ files set formatting of comments and set C-indenting
              on.
              " For other files switch it off.
              " Don't change the order, it's important that the line with * comes
              first.
              if version >= 5.4
              autocmd FileType * set formatoptions=tcql
              nocindent comm
              ents&
              autocmd FileType c,cpp,h set formatoptions=croql
              cindent
              "comments=sr:/*,mb:*,el:*/,://
              endif
              augroup END
              " Source our .tex definitions if it's a .tex file.
              au FileType tex so ~/.vimtexrc
              " Set up settings for mail.
              au FileType mail syn clear
              au FileType mail se tw=78 noai
              endif

              This seems to work just fine.

              > There is a way to customize syntax highlighting. It will be
              > different (and easier) in vim 6.0. If you are planning to RTFM, I suggest
              > the following topics:
              >
              > :help startup
              > :help mysyntaxfile

              I'll do that. ;-)

              Mike

              --
              Michael P. Soulier <msoulier@...>
              "...the word HACK is used as a verb to indicate a massive amount
              of nerd-like effort." -Harley Hahn, A Student's Guide to UNIX
              PGP Public Key: http://www.storm.ca/~msoulier/email.phtml
            Your message has been successfully submitted and would be delivered to recipients shortly.