Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions doc/blink-cmp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ For more common configurations, see the recipes <../recipes.md>.
},

-- Use a preset for snippets, check the snippets documentation for more information
snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' },
snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' | 'vsnip' },

-- Experimental signature help support
signature = { enabled = true }
Expand Down Expand Up @@ -1714,7 +1714,8 @@ snippets. The built-in `snippets` source will load friendly-snippets
<https://github.com/rafamadriz/friendly-snippets>, if available, and load any
snippets found at `~/.config/nvim/snippets/`. For use with Luasnip, see the
|blink-cmp-luasnip-section|. For use with mini.snippets, see the
|blink-cmp-mini.snippets-section|.
|blink-cmp-mini.snippets-section|. For use with vim-vsnip, see the
|blink-cmp-vim-vsnip-section|.


FRIENDLY SNIPPETS ~
Expand Down Expand Up @@ -1831,6 +1832,23 @@ MINI.SNIPPETS ~
<


VIM-VSNIP ~

>lua
{
'saghen/blink.cmp',
dependencies = 'echasnovski/mini.snippets',
opts = {
snippets = { preset = 'mini_snippets' },
-- ensure you have the `snippets` source (enabled by default)
sources = {
default = { 'lsp', 'path', 'snippets', 'buffer' },
},
}
}
<


DISABLE ALL SNIPPETS ~

>lua
Expand Down
2 changes: 1 addition & 1 deletion doc/configuration/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ For more common configurations, see the [recipes](../recipes.md).
},

-- Use a preset for snippets, check the snippets documentation for more information
snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' },
snippets = { preset = 'default' | 'luasnip' | 'mini_snippets' | 'vsnip' },

-- Experimental signature help support
signature = { enabled = true }
Expand Down
17 changes: 16 additions & 1 deletion doc/configuration/snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Snippets
---
# Snippets<!-- panvimdoc-ignore-start --> <Badge type="info"><a href="./reference#snippets">Go to default configuration</a></Badge><!-- panvimdoc-ignore-end -->

Blink uses the `vim.snippet` API by default for expanding and navigating snippets. The built-in `snippets` source will load [friendly-snippets](https://github.com/rafamadriz/friendly-snippets), if available, and load any snippets found at `~/.config/nvim/snippets/`. For use with Luasnip, see the [Luasnip section](#luasnip). For use with mini.snippets, see the [mini.snippets section](#mini-snippets).
Blink uses the `vim.snippet` API by default for expanding and navigating snippets. The built-in `snippets` source will load [friendly-snippets](https://github.com/rafamadriz/friendly-snippets), if available, and load any snippets found at `~/.config/nvim/snippets/`. For use with Luasnip, see the [Luasnip section](#luasnip). For use with mini.snippets, see the [mini.snippets section](#mini-snippets). For use with vim-vsnip, see the [vim-vsnip section](#vim-vsnip).

## Friendly Snippets

Expand Down Expand Up @@ -98,6 +98,21 @@ There's a great introduction to writing custom snippets [in the nvim-scissors re
}
```

## `vim-vsnip`

```lua
{
'saghen/blink.cmp',
dependencies = {'hrsh7th/vim-vsnip', 'https://codeberg.org/FelipeLema/bink-cmp-vsnip.git'},
opts = {
snippets = { preset = 'vsnip' },
sources = {
default = { 'lsp', 'path', 'vsnip', 'buffer' },
},
}
}
```

## Disable all snippets

```lua
Expand Down
15 changes: 11 additions & 4 deletions lua/blink/cmp/config/snippets.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--- @class (exact) blink.cmp.SnippetsConfig
--- @field preset 'default' | 'luasnip' | 'mini_snippets'
--- @field preset 'default' | 'luasnip' | 'mini_snippets' | 'vsnip'
--- @field expand fun(snippet: string) Function to use when expanding LSP provided snippets
--- @field active fun(filter?: { direction?: number }): boolean Function to use when checking if a snippet is active
--- @field jump fun(direction: number) Function to use when jumping between tab stops in a snippet, where direction can be negative or positive
--- @field score_offset number Offset to the score of all snippet items

--- @param handlers table<'default' | 'luasnip' | 'mini_snippets', fun(...): any>
--- @param handlers table<'default' | 'luasnip' | 'mini_snippets' | 'vsnip', fun(...): any>
local function by_preset(handlers)
return function(...)
local preset = require('blink.cmp.config').snippets.preset
Expand Down Expand Up @@ -37,6 +37,7 @@ local snippets = {
-- we run after it completes it callback. We do this by resubscribing to TextChangedI
require('blink.cmp').resubscribe()
end,
vsnip = function(snippet) vim.fn['vsnip#anonymous'](snippet) end,
}),
active = by_preset({
default = function(filter) return vim.snippet.active(filter) end,
Expand All @@ -50,6 +51,7 @@ local snippets = {
if not _G.MiniSnippets then error('mini.snippets has not been setup') end
return MiniSnippets.session.get(false) ~= nil
end,
vsnip = function() return vim.fn.empty(vim.fn['vsnip#get_session']()) ~= 1 end,
}),
jump = by_preset({
default = function(direction) vim.snippet.jump(direction) end,
Expand All @@ -62,6 +64,11 @@ local snippets = {
if not _G.MiniSnippets then error('mini.snippets has not been setup') end
MiniSnippets.session.jump(direction == -1 and 'prev' or 'next')
end,
vsnip = function(direction)
local session = vim.fn['vsnip#get_session']()
if vim.fn.empty(session) == 1 then return false end
return session.jumpable(direction)
end,
}),
score_offset = -3,
},
Expand All @@ -71,8 +78,8 @@ function snippets.validate(config)
validate('snippets', {
preset = {
config.preset,
function(preset) return vim.tbl_contains({ 'default', 'luasnip', 'mini_snippets' }, preset) end,
'one of: "default", "luasnip", "mini_snippets"',
function(preset) return vim.tbl_contains({ 'default', 'luasnip', 'mini_snippets', 'vsnip' }, preset) end,
'one of: "default", "luasnip", "mini_snippets", "vsnip"',
},
expand = { config.expand, 'function' },
active = { config.active, 'function' },
Expand Down
Loading