Add mapping example to README (#70)
* Add mapping example to README * move to FAQ section
This commit is contained in:
45
README.md
45
README.md
@@ -165,7 +165,6 @@ mapping = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
#### completion.autocomplete (type: cmp.TriggerEvent[])
|
#### completion.autocomplete (type: cmp.TriggerEvent[])
|
||||||
|
|
||||||
Which events should trigger `autocompletion`.
|
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.
|
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.
|
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
|
Source creation
|
||||||
====================
|
====================
|
||||||
|
|||||||
Reference in New Issue
Block a user