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

Re: .F90 as well as .f90

Expand Messages
  • Gary Johnson
    ... Vim s filename suffix to filetype translation is performed by the script $VIMRUNTIME/filetype.vim. The version of that file shipped with vim-6.2 includes
    Message 1 of 2 , Jun 24, 2003
    • 0 Attachment
      On 2003-06-23, Curtis Cooper <curtis@...> wrote:
      > Hi,
      >
      > I'm trying to write a proper .vimrc file that recognizes .F90 files as
      > Fortran 90 source code files. It already works for .f90 files, i.e., as
      > soon as I type
      >
      > > vim file1.f90,
      >
      > Vim automatically recognizes the file as Fortran source file and provides
      > appropriate syntax highlighting, correct tabbing rules, etc.
      >
      > However, when I have a file file2.F90, Vim does not recognize it properly
      > as a Fortran 90 source code file. Hence, I get no syntax highlighting for
      > this file without first typing
      >
      > :set syntax=fortran
      >
      > at the Vim command.

      Vim's filename suffix to filetype translation is performed by the
      script $VIMRUNTIME/filetype.vim. The version of that file shipped
      with vim-6.2 includes these lines:

      " Fortran
      au BufNewFile,BufRead *.f,*.F,*.for,*.fpp,*.ftn,*.f77,*.f90,*.f95 setf fortran

      As you can see, the F90 suffix is not in the list. The proper way
      to fix this is to create your own ~/.vim/filetype.vim (for Unix)
      script and edit it to contain these lines:

      if exists("did_load_filetypes")
      finish
      endif
      augroup filetypedetect
      au! BufRead,BufNewFile *.F90 setfiletype fortran
      augroup END

      as shown under

      :help new-filetype

      > Here is the line in my .vimrc currently that I expected would work but
      > does not produce the expected behavior:
      >
      > autocmd FileType f,F,f90,F90 set formatoptions=croql cindent et comments=sr:!
      >
      > Because F90 is listed as well, it should work as well as f90. Does anyone
      > know what's wrong?

      You were confusing file types with file name suffixes. The correct
      syntax for an autocommand that makes those settings for fortran
      files is either

      autocmd FileType fortran setlocal formatoptions=croql cindent et comments=sr:!

      or

      au BufNewFile,BufRead *.f,*.F,*.for,*.fpp,*.ftn,*.f77,*.f90,*.F90,*.f95 setlocal formatoptions=croql cindent et comments=sr:!

      Note the use of "setlocal" instead of "set" so that the settings
      apply locally to just that buffer instead of globally to every
      buffer. But if you're happy with vim's settings for .f90 files and
      you fix your filetype detection as described above, you shouldn't
      need either of those. If you decide you do want to change some
      setting for fortran files only, you should consider putting the
      commands in a file,

      ~/.vim/after/ftplugin/fortran.vim

      See

      :help ftplugin-overrule

      HTH,
      Gary

      --
      Gary Johnson | Agilent Technologies
      garyjohn@... | Wireless Division
      | Spokane, Washington, USA
    Your message has been successfully submitted and would be delivered to recipients shortly.