fortran胡乱缩进看的很难受,发现vscode的Modern Fortran除了高亮外还有很多很强力的功能。仔细配置了一下。

1. 安装插件和gfortran

  • vs code安装Modern Fortran插件。
  • 安装gfortran:下载MingW,添加环境变量。下载链接:x86_64的4个均可。

https://github.com/niXman/mingw-builds-binaries/releases

2. 配置fortls

fortls用于实现代码跳转。

  • 先python安装:pip install fortls
  • Everything寻找fortls.exe的路径,如D:\anaconda3\Scripts\fortls.exe
  • vs code设置Path to the Fortran language server (fortls)为该路径。
  • 使用方法:右键点击,即可跳转

3. 配置findent

  • 一样先python安装:pip install findent。命令行输入findent -h看是否安装成功。
  • Everything寻找findent.exe的路径,为D:\anaconda3\bin\findent.exe
  • 设置vs code的路径fortran.formatting.pathD:\anaconda3\bin\注:此时路径不包含.exe
  • 参数设置:Fortran › Formatting: Findent Args-i4,即缩进四个空格;-Rr,结尾补充模块名称。

PS:好像pip安装完后vs code能找到默认位置;有时候需要重启vs code才能生效。
参考

https://marketplace.visualstudio.com/items?itemName=fortran-lang.linter-gfortran
https://pypi.org/project/findent/
https://zhuanlan.zhihu.com/p/592312472
https://github.com/fortran-lang/vscode-fortran-support/discussions/527
https://zhuanlan.zhihu.com/p/618931548

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐