Skip to content

Repository files navigation

Snippet Plugin for Neovim

About the Project

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.

preview

Getting started

Prerequisites

Make sure that both neovim and the plugin telescope.nvim are installed. Just follow the installation sections of them.

Installation

Install the Neovim API for Haskell nvim-hs using your favorite nvim plugin manager. (e.g. vim-plug)

Plug 'neovimhaskell/nvim-hs.vim'

Usage

Setup

  1. Clone this Git Repository
  2. 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', []) 
]])
  1. Run stack build in your repository's folder
  2. Test the installation: run :echo SnipsVersion(), this should print a message to the status line.

Creating a snippet

  1. Open a file in Neovim and select the code lines you want to save as snippet.
  2. Switch to Neovims command mode by typing : and type SnipsCreate just after :'<,'>.
  3. 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.
  4. Switch to Neovims command mode by typing : and type SnipsSave just after :.
  5. Enter a name for the new snippet

The snippet will now be saved and it is possible to retrieve it at any time.

Finding a snippet

If you created a snippet, you can retrieve it at any time.

  1. Open any file in Neovim
  2. Switch to Neovims command mode by typing : and type Snips just after :.
  3. Telescope opens and you are able to fuzzy find your desired snippet by typing the snippets name
  4. Choose a Snippet to insert by hitting Enter
  5. 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

Acknowledgments

Debugging

  1. export the function in the module definition
  2. start cabal using cabal repl
  3. execute the function (e.g. for a function hello in the module Plugin.FprodTeam just run Plugin.FprodTeam.hello) Tip: See also: Debug in nvim-hs

Recompile the plugin in Neovim

add a keybinding to your nvim config: nvim:

vim.keymap.set("n", "<F5>",
function()
  vim.cmd([[ call nvimhs#compileAndRestart('snips') ]])
  print("recompiled")
end
)

Testing

To run all tests, follow the steps below.

Start cabal in the test folder:

cabal v2-repl tests

Execute the main function:

ghci> main

Links

Contact

This plugin was initially created by Raphal Lüthy, Andri Wild & Tobias Wyss.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages