Skip to content

Commit

Permalink
Added completion
Browse files Browse the repository at this point in the history
  • Loading branch information
liul85 committed Aug 5, 2022
1 parent b3d65a3 commit 24c1b13
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ require "options"
require "keymaps"
require "plugins"
require "colorschema"
require "completion"
75 changes: 75 additions & 0 deletions lua/completion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-----------------------------------------------------------
-- Autocomplete configuration file
-----------------------------------------------------------

-- Plugin: nvim-cmp
-- url: https://github.com/hrsh7th/nvim-cmp


local cmp_status_ok, cmp = pcall(require, 'cmp')
if not cmp_status_ok then
return
end

local luasnip_status_ok, luasnip = pcall(require, 'luasnip')
if not luasnip_status_ok then
return
end

cmp.setup {
-- Load snippet support
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},

-- Completion settings
completion = {
--completeopt = 'menu,menuone,noselect'
keyword_length = 2
},

-- Key mapping
mapping = {
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},

-- Tab mapping
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end
},

-- Load sources, see: https://github.com/topics/nvim-cmp
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'path' },
{ name = 'buffer' },
},
}

11 changes: 11 additions & 0 deletions lua/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ return packer.startup(function(use)
-- gruvbox colorscheme
use 'ellisonleao/gruvbox.nvim'

-- Autocomplete
use {
'hrsh7th/nvim-cmp',
requires = {
'L3MON4D3/LuaSnip',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
'hrsh7th/cmp-buffer',
'saadparwaiz1/cmp_luasnip',
},
}
-- Automatically set up your configuration after cloning packer.nvim
-- Put this at the end after all plugins
if PACKER_BOOTSTRAP then
Expand Down

0 comments on commit 24c1b13

Please sign in to comment.