The plugin makes it possible to easily save text or code snippets and to paste them at a given place if needed. For this purpose, a simple snippet management is provided, which offers the possibility to select among the available snippets using Telescope The snippets are persisted in an external file.
Make sure that both neovim and the plugin telescope.nvim are installed. Just follow the installation sections of them.
Install the Neovim API for Haskell nvim-hs using your favorite nvim plugin manager. (e.g. vim-plug)
Plug 'neovimhaskell/nvim-hs.vim'- Clone this Git Repository
- Create a file that is loaded by neovim on startup and add the following content:
vim.cmd( [[
call nvimhs#start('PATH/TO/THE/REPO', 'snips', [])
]])- Run
stack buildin your repository's folder - Test the installation: run
:echo SnipsVersion(), this should print a message to the status line.
- Open a file in Neovim and select the code lines you want to save as snippet.
- Switch to Neovims command mode by typing
:and typeSnipsCreatejust after:'<,'>. - In the newly opened buffer, replace words that you want to use as placeholders by a string that is quoted by
<#/#>Note: if you use the same quoted string multiple times, snips-nvim will use the same text replacements when you use the snippet. - Switch to Neovims command mode by typing
:and typeSnipsSavejust after:. - Enter a name for the new snippet
The snippet will now be saved and it is possible to retrieve it at any time.
If you created a snippet, you can retrieve it at any time.
- Open any file in Neovim
- Switch to Neovims command mode by typing
:and typeSnipsjust after:. - Telescope opens and you are able to fuzzy find your desired snippet by typing the snippets name
- Choose a Snippet to insert by hitting Enter
- Snips-nvim asks you now to add the placeholder replacement texts. (Placeholders with the same names, will get the same values.)
The snippet is now pasted to your previous opened buffer.
Note: snips-nvim stores and retrieves snippets per filetype. Therefore telescope only shows you the snippets matching the filetype of your currently opened buffer.
You can set the filetype of a file manually using :set filetype=haskell
- export the function in the module definition
- start cabal using
cabal repl - execute the function (e.g. for a function
helloin the modulePlugin.FprodTeamjust runPlugin.FprodTeam.hello) Tip: See also: Debug in nvim-hs
add a keybinding to your nvim config: nvim:
vim.keymap.set("n", "<F5>",
function()
vim.cmd([[ call nvimhs#compileAndRestart('snips') ]])
print("recompiled")
end
)To run all tests, follow the steps below.
Start cabal in the test folder:
cabal v2-repl testsExecute the main function:
ghci> main- Nvim-hs API documentation
- List of functions that are provided by nvim-hs
- Proof of Concept for the JSON parsing (as on Raphaels Laptop, the Snippet first didn't run)
- Github Issue for M1 with nvim-hs
This plugin was initially created by Raphal Lüthy, Andri Wild & Tobias Wyss.
