Add mapping example to README (#70)

* Add mapping example to README

* move to FAQ section
This commit is contained in:
uga-rosa
2021-08-25 21:45:24 +09:00
committed by GitHub
parent 6bc0ddb58b
commit d1f7f4f621

View File

@@ -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 = {
["<tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(t("<C-n>"), "n")
elseif luasnip.expand_or_jumpable() then
vim.fn.feedkeys(t("<Plug>luasnip-expand-or-jump"), "")
elseif check_back_space() then
vim.fn.feedkeys(t("<tab>"), "n")
else
fallback()
end
end, {
"i",
"s",
}),
["<S-tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(t("<C-p>"), "n")
elseif luasnip.jumpable(-1) then
vim.fn.feedkeys(t("<Plug>luasnip-jump-prev"), "")
else
fallback()
end
end, {
"i",
"s",
}),
}
```
Source creation
====================