https://github.com/pabsan-0/vim-snippets
https://github.com/pabsan-0/vim-snippets
repos-ecosystem vim vim-plug vim-plugins
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/pabsan-0/vim-snippets
- Owner: pabsan-0
- Created: 2024-10-28T11:28:37.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-30T09:19:11.000Z (over 1 year ago)
- Last Synced: 2025-03-17T07:44:54.337Z (11 months ago)
- Topics: repos-ecosystem, vim, vim-plug, vim-plugins
- Language: Vim Script
- Homepage:
- Size: 1.14 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# snippets.vim
Vim integration of snippets - quick code bites with an easy copy-pasting workflow.

Search powered by [fzf.vim](https://github.com/junegunn/fzf.vim), [rg]() and [batcat]().
## Installation
This plugin requires you to have `fzf.vim` first, as well as `rg` to efficiently search your cards. For colored `fzf`-preview you'll also need `batcat`.
Install requisites:
```
sudo apt install fzf ripgrep
sudo apt install batcat # optional
```
Using vim-plug:
```
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'pabsan-0/vim-snippets'
```
Set a custom path in your `.vimrc` where your snippets are to be stored and loaded from:
```
set g:snippets_directory = ~/snippets " custom path to store your notes
```
## Usage
If unused, `s` will be the default entrypoint to the Snippets plugin:
- In normal mode, this mapping will open a snippet search FZF interface with the following controls:
- `enter`: paste snippet into the current buffer.
- `tab`: alternate ripgrep and fzf (content / card name) search.
- `C-a`: **a**dd a new snippet.
- `C-t`: open snippet in a new **t**ab.
- In visual mode, creates a new snippet from the current visual selection.
The plugin also exposes these commands:
- `SnippetsRg`: launches snippet search by file content.
- `SnippetsFzf`: launches snippet search by file name.
- `SnippetsCreate`: prompts for a filename and creates an empty snippet.
- `SnippetsCreateVisual`: prompts for a filename and creates a snippet from the current selection.
## Features
### Managing your personal snippets
You'll need a snippet collection to draw from, maybe under version control. Control it by setting this variable:
- `g:snippets_directory`: existing dir to look for and create new snippets into.
Find my collection at [pabsan-0/snippets](https://github.com/pabsan-0/snippets).
### Alternating search modes better
If you've configured `fzf` to store a search history, you can keep your query when alternating modes with `tab`. In order to do that, add the following lines to `.vimrc`.
```
let g:fzf_history_dir = '~/.local/share/fzf-history'
" Optional: Remap bindings to keep and as usual for up-down navigation
let $FZF_DEFAULT_OPTS = '--bind ctrl-n:down,ctrl-p:up,alt-n:next-history,alt-p:prev-history'
```