Jul 31, 2012

vim for FORTRAN


This page contains useful configuration of vim for FORTRAN.

I summarize several useful configurations:
  • style of source file (the default is fixed style):
:let fortran_free_source=1
:let fortran_fixed_source=1
add them prior to the :syntax on command
if you want to switch between free style and fixed style, add the following lines:

nmap <S-F> :set syntax=fortran<CR>:let b:fortran_fixed_source=!b:fortran_fixed_source<CR>:set syntax=text<CR>:set syntax=fortran<CR>
nmap <C-F> :filetype detect<CR>

  • enable Tabs in FORTRAN (otherwise they are marked as ugly red blocks):
:let fortran_have_tabs=1
  • code folding:
" :za toggle code folding
" :zr (zR) open all
" :zm (zM) close all
" :zc close
" :zo open

set foldmethod=indent
set foldnestmax=10
set nofoldenable " no fold by default
set foldlevel=1   " some value I don't know...
" code folding for fortran
:let fortran_fold=1
:let fortran_fold_conditionals=1
:let fortran_fold_multilinecomments=1
  • an enhanced vim script for FORTRAN 2003 keywords, can be found here.
  • block comments
this plugin supports block comments for FORTRAN and others.
description:
Global Plugin to comment and un-comment lines in different source files in both normal and visual mode
usage:
ctrl-c to comment a single line ctrl-x to un-comment a single line
shift-v and select multiple lines, then ctrl-c to comment the selected multiple lines
shift-v and select multiple lines, then ctrl-x to un-comment the selected multiple lines
supports:
c, c++, java, php[2345], proc, css, html, htm, xml, xhtml, vim, vimrc, sql, sh, ksh, csh, perl, tex, fortran, ml, caml, ocaml, vhdl, haskel and normal files

Jul 4, 2012