Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VIM : used for Fortran files .f or .f90

1,727 views
Skip to first unread message

bru

unread,
Oct 3, 2007, 6:23:56 AM10/3/07
to
Hello!

The VIM version I use does the following when I edit .f or .f90
source Fortran files :

displays a yellow color when I am beyond 72 column and does an
automatic new line when I tape in this zone. I have two questions :

1) which command do I have to make in VIM to allow me to have , instead
of fixed format, free source format?

2) Is it possible, by putting some command in my vimrc file, to have
automatically free format when editing .f90 file and fixed format with
.f files

Thaks in advance

Bernard Bru

Mikolaj Machowski

unread,
Oct 3, 2007, 12:26:14 PM10/3/07
to
bru scripsit:

Excerpt from:

:help fortran.vim

Fortran source code form ~
Fortran 9x code can be in either fixed or free source form. Note that the
syntax highlighting will not be correct if the form is incorrectly set.

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.

m.
--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078
vim.pl - http://skawina.eu.org/mikolaj
CLEWN - http://clewn.sf.net

bru

unread,
Oct 4, 2007, 5:18:59 AM10/4/07
to
> let fortran_free_source=1let 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.
>
> m.

Thank you very much, I should have read the corresponding help!!

So I put the command in my .vimrc file :

let fortran_fixed_source=1

but why this command dont act when editing a file?

For me it seems too difficult to write a file type plugin

If I put in my existing fortran source file :
PROGRAM XXXXX in column 1 and
USE TOTO also in column 1

it is still recognised as a fixed source form file!!

please find attached my vimrc file

Regards

Bernard Bru

vvimrc

Mikolaj Machowski

unread,
Oct 4, 2007, 11:57:01 AM10/4/07
to
bru scripsit:

>
> Thank you very much, I should have read the corresponding help!!
>
> So I put the command in my .vimrc file :
>
> let fortran_fixed_source=1
^^^^^^^^^^^^^^^^^^^^^^^^^^

>
> but why this command dont act when editing a file?
>
> For me it seems too difficult to write a file type plugin
>
> If I put in my existing fortran source file :
> PROGRAM XXXXX in column 1 and
> USE TOTO also in column 1
>
> it is still recognised as a fixed source form file!!

>
> please find attached my vimrc file
>
>

> " Switch syntax highlighting on, when the terminal has colors
> " Also switch on highlighting the last used search pattern.
> if &t_Co > 2 || has("gui_running")
> " let fortran_free_source=1
> syntax on
> set hlsearch
> endif
> hi statement ctermfg=cyan

In attached vimrc proper line is commented -> " at the beginning of
line. Try to remove it.

Bernard Bru

unread,
Oct 5, 2007, 4:52:31 AM10/5/07
to
Mikolaj Machowski wrote:
> bru scripsit:
>
>>Thank you very much, I should have read the corresponding help!!
>>
>>So I put the command in my .vimrc file :
>>
>>let fortran_fixed_source=1
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>>but why this command dont act when editing a file?
>>
>>For me it seems too difficult to write a file type plugin
>>
>>If I put in my existing fortran source file :
>>PROGRAM XXXXX in column 1 and
>>USE TOTO also in column 1
>>
>>it is still recognised as a fixed source form file!!
>
>
>>please find attached my vimrc file
>>
>>
>>" Switch syntax highlighting on, when the terminal has colors
>>" Also switch on highlighting the last used search pattern.
>>if &t_Co > 2 || has("gui_running")
>>" let fortran_free_source=1let fortran_free_source=1

>> syntax on
>> set hlsearch
>>endif
>>hi statement ctermfg=cyan
>
>
> In attached vimrc proper line is commented -> " at the beginning of
> line. Try to remove it.
>
> m.
OK it works when putting in my .vimrc :

let fortran_free_source=1

but you told me that if I do not put this command in the .vimrc file
and if I put in my source code the first statements in column 1, vim
automatically detects free source form.However vim stays in fixed source
form!!

Best regards

Bernard Bru

0 new messages