![vim fortran indentexpr 问题](https://linux22.com/image/1358387/vim%20fortran%20indentexpr%20%E9%97%AE%E9%A2%98.png)
这里有一个奇怪的问题,无法indentexpr=FortranGetFreeIndent()
正确设置。
我第一次打开一个文件(当然是自由格式)时,new.f90
比如说:set
:set
--- Options ---
autoindent filetype=fortran incsearch smartcase
autowrite helplang=en mouse=a syntax=fortran
background=dark hidden ruler textwidth=72
backup history=500 shiftwidth=3 ttyfast
comments=:!,:*,:C hlsearch showcmd ttymouse=xterm2
commentstring=!%s ignorecase showmatch
backspace=indent,eol,start
fileencodings=ucs-bom,utf-8,default,latin1
formatoptions=tcql
include=^\c#\=\s*include\s\+
indentexpr=FortranGetFixedIndent()
indentkeys=0{,0},:,0#,!^F,o,O,e,=~end,=~case,=~if,=~else,=~do,=~where,=~elsewh
ere,=~select,=~endif,=~enddo,=~endwhere,=~endselect,=~elseif,=~type,=~interface,
=~forall,=~associate,=~block,=~enum,=~endforall,=~endassociate,=~endblock,=~ende
num
printoptions=paper:letter
runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/
vim73,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg
,.inx,.out,.toc
suffixesadd=.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Press ENTER or type command to continue
现在,如果我手动:set indentexpr=FortranGetFreeIndent()
编写一些代码
program testfree
print *,"Test free format"
end program testfree
然后下次我打开该文件时,:set indentexpr
会出现indentexpr=FortranGetFreeIndent
。
因此看起来“在前 25 行的前五列中检测到了符号”(引用自‘fortran.vim’的注释)但文件扩展名未被识别为表示自由格式的 .f90。
感谢您的帮助。
答案1
执行以下操作(或您需要的那部分):
cd
mkdir .vim
cd .vim
mkdir ftplugin
cd ftplugin
vi fortran.vim
然后,在 fortran.vim 中:
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
每次都有效。