All Projects → quangnguyen30192 → cmp-nvim-ultisnips

quangnguyen30192 / cmp-nvim-ultisnips

Licence: Apache-2.0 license
nvim-cmp source for ultisnips

Programming Languages

lua
6591 projects
Vim Script
2826 projects
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to cmp-nvim-ultisnips

cmp-nvim-lsp-document-symbol
nvim-cmp source for textDocument/documentSymbol via nvim-lsp.
Stars: ✭ 88 (+44.26%)
Mutual labels:  nvim-cmp
cmp-rg
ripgrep source for nvim-cmp
Stars: ✭ 165 (+170.49%)
Mutual labels:  nvim-cmp
crates.nvim
A neovim plugin that helps managing crates.io dependencies
Stars: ✭ 252 (+313.11%)
Mutual labels:  nvim-cmp
cmp-spell
spell source for nvim-cmp based on vim's spellsuggest.
Stars: ✭ 99 (+62.3%)
Mutual labels:  nvim-cmp
cmp luasnip
luasnip completion source for nvim-cmp
Stars: ✭ 290 (+375.41%)
Mutual labels:  nvim-cmp
nvim-cmp
A completion plugin for neovim coded in Lua.
Stars: ✭ 4,534 (+7332.79%)
Mutual labels:  nvim-cmp
cmp-emoji
nvim-cmp source for emoji
Stars: ✭ 99 (+62.3%)
Mutual labels:  nvim-cmp
cmp-latex-symbols
Add latex symbol support for nvim-cmp.
Stars: ✭ 82 (+34.43%)
Mutual labels:  nvim-cmp
nvim
Structure, documented, super fast neovim configuration. 可能是翻斗花园最好用的 neovim 配置[^1]。
Stars: ✭ 223 (+265.57%)
Mutual labels:  nvim-cmp
cmp-tmux
Tmux completion source for nvim-cmp and nvim-compe
Stars: ✭ 98 (+60.66%)
Mutual labels:  nvim-cmp
nvim-fennel-lsp-conjure-as-clojure-ide
Basic config to transform your NVIM in a powerful Clojure IDE using fennel, clojure-lsp and conjure.
Stars: ✭ 144 (+136.07%)
Mutual labels:  nvim-cmp
cmp-vsnip
nvim-cmp source for vim-vsnip
Stars: ✭ 70 (+14.75%)
Mutual labels:  nvim-cmp
cmp-dictionary
nvim-cmp source for dictionary.
Stars: ✭ 60 (-1.64%)
Mutual labels:  nvim-cmp
cmp-under-comparator
nvim-cmp comparator function for completion items that start with one or more underlines
Stars: ✭ 77 (+26.23%)
Mutual labels:  nvim-cmp
cmp-treesitter
cmp source for treesitter
Stars: ✭ 69 (+13.11%)
Mutual labels:  nvim-cmp
cmp-path
nvim-cmp source for path
Stars: ✭ 137 (+124.59%)
Mutual labels:  nvim-cmp
cmp-skkeleton
skkeleton source for nvim-cmp
Stars: ✭ 12 (-80.33%)
Mutual labels:  nvim-cmp

cmp-nvim-ultisnips

UltiSnips completion source for nvim-cmp

Screenshot

Features

  • Composable mappings: get rid of boilerplate code in your config
  • Treesitter integration: show snippets based on the filetype at your cursor position
  • Regular expression snippets: snippets with the r option are supported
  • Custom context snippets: snippets are only shown in the correct context
  • Customization: change which and how snippets are displayed by cmp

Dependencies

Installation and Recommended Mappings

Use your favourite package manager to install this plugin:

  • vim-plug: Plug "quangnguyen30192/cmp-nvim-ultisnips"
  • packer.nvim: use("quangnguyen30192/cmp-nvim-ultisnips")

You also need to add ultisnips to your cmp sources.

Here is an example using packer.nvim:

use({
  "hrsh7th/nvim-cmp",
  requires = {
    "quangnguyen30192/cmp-nvim-ultisnips",
    config = function()
      -- optional call to setup (see customization section)
      require("cmp_nvim_ultisnips").setup{}
    end,
    -- If you want to enable filetype detection based on treesitter:
    -- requires = { "nvim-treesitter/nvim-treesitter" },
  },
  config = function()
    local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings")
    require("cmp").setup({
      snippet = {
        expand = function(args)
          vim.fn["UltiSnips#Anon"](args.body)
        end,
      },
      sources = {
        { name = "ultisnips" },
        -- more sources
      },
      -- recommended configuration for <Tab> people:
      mapping = {
        ["<Tab>"] = cmp.mapping(
          function(fallback)
            cmp_ultisnips_mappings.expand_or_jump_forwards(fallback)
          end,
          { "i", "s", --[[ "c" (to enable the mapping in command mode) ]] }
        ),
        ["<S-Tab>"] = cmp.mapping(
          function(fallback)
            cmp_ultisnips_mappings.jump_backwards(fallback)
          end,
          { "i", "s", --[[ "c" (to enable the mapping in command mode) ]] }
        ),
      },
    })
  end,
})

Mappings

You can compose your own mappings that are comprised of the following actions:

  • expand: expands the current snippet if the completion window is closed
  • jump_forwards / jump_backwards: jumps to the next / previous snippet tabstop
  • select_next_item / select_prev_item: selects the next / previous completion item

The recommended mappings use the compose function under the hood:

function M.expand_or_jump_forwards(fallback)
  M.compose { "expand", "jump_forwards", "select_next_item" }(fallback)
end

function M.jump_backwards(fallback)
  M.compose { "jump_backwards", "select_prev_item" }(fallback)
end

For example, if you prefer a separate key for jumping between snippet tabstops you can do the following:

local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings")
-- In your cmp setup:
...
mapping = {
  ["<Tab>"] = cmp.mapping(
    function(fallback)
      cmp_ultisnips_mappings.compose { "expand", "select_next_item" }(fallback)
    end,
    ...

These actions are implemented as a table { condition = ..., command = ... }. If the condition for an action fails, the next action (in the order as the action keys are passed to compose) is tried until the first condition matches. Then the command function is run. If none match, fallback is called.

Customization

Available Options

filetype_source: "treesitter" | "ultisnips_default"

Determines how the filetype of a buffer is identified. This option affects which snippets are available by UltiSnips. If set to "treesitter" and the nvim-treesitter plugin is installed, only snippets that match the filetype at the current cursor position are shown (as well as snippets included via UltiSnips' extends directive). Otherwise, or if treesitter could not determine the filetype at the current position, the available snippets are handled entirely by UltiSnips.

Default: "treesitter"


show_snippets: "expandable" | "all"

If set to "expandable", only those snippets currently expandable by UltiSnips will be shown. The snippets will always be in sync with the currently available UltiSnips snippets.

"all" will show all snippets for the current filetype except regex and custom context snippets. This is due to caching of all snippets for the current buffer. They will not update even if the snippet definitions changed

  • you can then manually reload the snippets with the command :CmpUltisnipsReloadSnippets or by using an autocommand:
autocmd BufWritePost *.snippets :CmpUltisnipsReloadSnippets

Default: "expandable"


documentation(snippet: {}): function

snippet is a table that contains the following keys (each value is a string):

  • trigger, description, options, value

Returns: a string that is shown by cmp in the documentation window. If an empty string ("") is returned, the documentation window will not appear for that snippet.

Default: require("cmp_nvim_ultisnips.snippets").documentation

By default, this shows the snippet description at the top of the documentation window followed by the snippet content (see screenshot at the top of the readme).

Example Configuration

Note: calling the setup function is only required if you wish to customize this plugin.

require("cmp_nvim_ultisnips").setup {
  filetype_source = "treesitter",
  show_snippets = "all",
  documentation = function(snippet)
    return snippet.description
  end
}

Credit

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].