From d1f7f4f6213d5335e3685b80c805d3a54ce8d427 Mon Sep 17 00:00:00 2001 From: uga-rosa <82267684+uga-rosa@users.noreply.github.com> Date: Wed, 25 Aug 2021 21:45:24 +0900 Subject: [PATCH] Add mapping example to README (#70) * Add mapping example to README * move to FAQ section --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 134e760..1660bc1 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,6 @@ mapping = { } ``` - #### completion.autocomplete (type: cmp.TriggerEvent[]) Which events should trigger `autocompletion`. @@ -335,6 +334,50 @@ The `cmp-buffer` source makes index of the current buffer so if the current buff For example, `typescript-language-server` will returns 15k items to the client. In such case, the time near the 100ms will be consumed just to parse payloads as JSON. +#### How to setup supertab-like mapping? + +This is supertab-like mapping for [LuaSnip](https://github.com/L3MON4D3/LuaSnip) + +```lua +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end +local check_back_space = function() + local col = vim.fn.col '.' - 1 + return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil +end +local luasnip = require("luasnip") + +-- supertab-like mapping +mapping = { + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(t(""), "n") + elseif luasnip.expand_or_jumpable() then + vim.fn.feedkeys(t("luasnip-expand-or-jump"), "") + elseif check_back_space() then + vim.fn.feedkeys(t(""), "n") + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(t(""), "n") + elseif luasnip.jumpable(-1) then + vim.fn.feedkeys(t("luasnip-jump-prev"), "") + else + fallback() + end + end, { + "i", + "s", + }), +} +``` Source creation ====================