nvim-fortran-snippets
December 30, 2024 ยท View on GitHub
A Neovim plugin providing LuaSnip snippets for Fortran programming. These snippets are designed to help you quickly create boilerplate code for modules, derived types, and more.
Features
- Fortran-specific snippets:
- Snippets to streamline modern Fortran development.
- Integration with LuaSnip:
- Uses LuaSnip for snippet management.
- Easy installation:
- Compatible with
packer.nvim.
- Compatible with
Installation
Prerequisites
- Neovim 0.10+: Required for Lua-based configuration and plugins.
- LuaSnip: This plugin relies on LuaSnip. Ensure it is installed.
Installing with packer.nvim
-
Add the plugin to your
packer.nvimconfiguration:require("packer").startup(function(use) -- Install LuaSnip (dependency) use "L3MON4D3/LuaSnip" -- Install nvim-fortran-snippets use { "gustav-jansen/nvim-fortran-snippets", config = function() require("fortran_snippets").setup() end, } end) -
Run the following command in Neovim to install the plugin:
:PackerSync
Usage
- Open a Fortran file (
*.f90,*.f95, etc.). - Trigger snippets using your LuaSnip keybindings (usually
<Tab>or<C-l>for expansion). - Example:
- Type
ndtand expand it to insert a derived type skeleton.
- Type
Example Snippets
ndt
Expands into:
module module_name
implicit none
private
public :: type_name
type :: type_name
contains
procedure :: cleanup => cleanup
procedure :: clear => clear
end type type_name
interface type_name
module procedure constructor
end interface constructor
contains
function constructor() result(this)
type(type_name) :: this
call this%clear()
end function constructor
subroutine cleanup(this)
class(type_name), intent(inout) :: this
call this%clear()
end subroutine cleanup
subroutine clear(this)
class(type_name), intent(inout) :: this
end subroutine clear
end module module_name
Adding More Snippets
To extend or customize the snippets:
- Open the
snippets.luafile in the plugin directory (lua/fortran_snippets/snippets.lua). - Add new snippet definitions as separate functions.
Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue for feature requests or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.