Merge pull request #11 from NTBBloodbath/patch-1

fix(readme): correct code block for nvim-cmp example
This commit is contained in:
Daniel Mathiot
2021-08-28 15:52:30 +02:00
committed by GitHub

View File

@@ -87,42 +87,43 @@ If you want to add `<Tab>` completion instead, be sure you don't have a completi
<details> <details>
<summary>nvim-cmp</summary> <summary>nvim-cmp</summary>
```lua ```lua
local cmp = require('cmp') local cmp = require('cmp')
local neogen = require('neogen') local neogen = require('neogen')
local t = function(str) local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true) return vim.api.nvim_replace_termcodes(str, true, true, true)
end end
local check_back_space = function() local check_back_space = function()
local col = vim.fn.col '.' - 1 local col = vim.fn.col '.' - 1
return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil
end end
cmp.setup { cmp.setup {
... ...
-- You must set mapping if you want.
mapping = {
["<tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(t("<C-n>"), "n")
elseif neogen.jumpable() then
vim.fn.feedkeys(t("<cmd>lua require('neogen').jump_next()<CR>"), "")
elseif check_back_space() then
vim.fn.feedkeys(t("<tab>"), "n")
else
fallback()
end
end, {
"i",
"s",
}),
},
...
}
```
-- You must set mapping if you want.
mapping = {
["<tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(t("<C-n>"), "n")
elseif neogen.jumpable() then
vim.fn.feedkeys(t("<cmd>lua require('neogen').jump_next()<CR>"), "")
elseif check_back_space() then
vim.fn.feedkeys(t("<tab>"), "n")
else
fallback()
end
end, {
"i",
"s",
}),
},
...
}
```
</details> </details>
## Configuration ## Configuration