Home Explore Blog CI



neovim

16th chunk of `runtime/doc/syntax.txt`
4acd18154b355277daa19fe82b4e81c822c7f120fe414f6f0000000100000fa7
 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.  Suppose
neither of these variables have been set. In that case, the syntax script
attempts to determine which source form has been used by examining the file
extension using conventions common to the ifort, gfortran, Cray, NAG, and
PathScale compilers (.f, .for, .f77 for fixed-source, .f90, .f95, .f03, .f08
for free-source).  No default is used for the .fpp and .ftn file extensions
because different compilers treat them differently. If none of this works,
then the script examines the first five columns of the first 500 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 500 or more full-line
comments, the script may incorrectly decide that the 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.

Vendor extensions ~
Fixed-form Fortran requires a maximum line length of 72 characters but the
script allows a maximum line length of 80 characters as do all compilers
created in the last three decades.  An even longer line length of 132
characters is allowed if you set the variable fortran_extended_line_length
with a command such as >
    :let fortran_extended_line_length=1

If you want additional highlighting of the CUDA Fortran extensions, you should
set the variable fortran_CUDA with a command such as >
    :let fortran_CUDA=1

To activate recognition of some common, non-standard, vendor-supplied
intrinsics, you should set the variable fortran_vendor_intrinsics with a
command such as >
    :let fortran_vendor_intrinsics=1

Tabs in Fortran files ~
Tabs are not recognized by the Fortran standards.  Tabs are not a good idea in
fixed format Fortran source code which requires fixed column boundaries.
Therefore, tabs are marked as errors.  Nevertheless, some programmers like
using tabs.  If your Fortran files contain tabs, then you should set the
variable fortran_have_tabs in your vimrc with a command such as >
    :let fortran_have_tabs=1
Unfortunately, the use of tabs will mean that the syntax file will not be able
to detect incorrect margins.

Syntax folding of Fortran files ~
Vim will fold your file using foldmethod=syntax, if you set the variable
fortran_fold in your .vimrc with a command such as >
    :let fortran_fold=1
to instruct the syntax script to define fold regions for program units, that
is main programs starting with a program statement, subroutines, function
subprograms, modules, submodules, blocks of comment lines, and block data
units. Block, interface, associate, critical, type definition, and change team
constructs will also be folded.  If you also set the variable
fortran_fold_conditionals with a command such as >
    :let fortran_fold_conditionals=1
then fold regions will also be defined for do loops, if blocks, select case,
select type, and select rank constructs.  Note that defining fold regions can
be slow for large files.

The syntax/fortran.vim script contains embedded comments that tell you how to
comment and/or uncomment some lines to (a) activate recognition of some
non-standard, vendor-supplied intrinsics and (b) to prevent features deleted
or declared obsolescent in the 2008 standard from being highlighted as todo
items.

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.

For further information related to Fortran, see |ft-fortran-indent| and
|ft-fortran-plugin|.

Title: Fortran Syntax Configuration Details
Summary
Explanation of Fortran syntax highlighting behavior in Vim, including automatic detection of fixed or free source form based on file extension and content. Describes settings for vendor extensions, line length, CUDA Fortran, and non-standard intrinsics. Discusses handling tabs, syntax folding options, and limitations of the syntax highlighting.