Escolar Documentos
Profissional Documentos
Cultura Documentos
This choice
should be appropriate for most users most of the time because Fortran 95 is a
superset of Fortran 90 and almost a superset of Fortran 77.
When you create a new fortran file, the syntax script assumes fixed source
form. If you always use free source form, then >
:let fortran_free_source=1
in your .vimrc prior to the :syntax on command. If you always use fixed source
form, then >
:let fortran_fixed_source=1
in your .vimrc prior to the :syntax on command.
If the form of the source code depends upon the file extension, then it is
most convenient to set fortran_free_source in a ftplugin file. For more
information on ftplugin files, see |ftplugin|. For example, if all your
fortran files with an .f90 extension are written in free source form and the
rest in fixed source form, add the following code to your ftplugin file >
let s:extfname = expand("%:e")
if s:extfname ==? "f90"
let fortran_free_source=1
unlet! fortran_fixed_source
else
let fortran_fixed_source=1
unlet! fortran_free_source
endif
Note that this will work only if the "filetype plugin indent on" command
precedes the "syntax on" command in your .vimrc file.
When you edit an existing fortran file, the syntax script will assume free
source form if the fortran_free_source variable has been set, and assumes fixed
source form if the fortran_fixed_source variable has been set. If neither of
these variables have been set, the syntax script attempts to determine which
source form has been used by examining the first five columns of the first 250
lines of your file. If no signs of free source form are detected, then the file
is assumed to be in fixed source form. The algorithm should work in the vast
majority of cases. In some cases, such as a file that begins with 250 or more
full-line comments, the script may incorrectly decide that the fortran code is
in fixed form. If that happens, just add a non-comment statement beginning
anywhere in the first five columns of the first twenty five lines, save (:w) and
then reload (:e!) the file.
If you use f77 with extensions, even common ones like do/enddo loops, do/while
loops and free source form that are supported by most f77 compilers including
g77 (GNU Fortran), then you will probably find the default highlighting
satisfactory. However, if you use strict f77 with no extensions, not even free
source form or the MIL STD 1753 extensions, then the advantages of setting the
dialect to f77 are that names such as SUM are recognized as user variable
names and not highlighted as f9x intrinsic functions, that obsolete constructs
such as ASSIGN statements are not highlighted as todo items, and that fixed
source form will be assumed.
If you use elf90 or F, the advantage of setting the dialect appropriately is
that f90 features excluded from these dialects will be highlighted as todo
items and that free source form will be assumed as required for these
dialects.
If all your fortran files use the same dialect, set fortran_dialect in your
.vimrc prior to your syntax on statement. If the dialect depends upon the file
extension, then it is most convenient to set it in a ftplugin file. For more
information on ftplugin files, see |ftplugin|. For example, if all your
fortran files with an .f90 extension are written in the elf subset, your
ftplugin file should contain the code >
let s:extfname = expand("%:e")
if s:extfname ==? "f90"
let fortran_dialect="elf"
else
unlet! fortran_dialect
endif
Note that this will work only if the "filetype plugin indent on" command
precedes the "syntax on" command in your .vimrc file.
Finer control is necessary if the file extension does not uniquely identify
the dialect. You can override the default dialect, on a file-by-file basis, by
including a comment with the directive "fortran_dialect=xx" (where xx=f77 or
elf or F or f90 or f95) in one of the first three lines in your file. For
example, your older .f files may be written in extended f77 but your newer
ones may be F codes, and you would identify the latter by including in the
first three lines of those files a Fortran comment of the form >
! fortran_dialect=F
F overrides elf if both directives are present.
Limitations ~
Parenthesis checking does not catch too few closing parentheses. Hollerith
strings are not recognized. Some keywords may be highlighted incorrectly
because Fortran90 has no reserved words.