completion setup

This commit is contained in:
2024-09-30 05:17:31 +02:00
parent 437a8b0eac
commit 6a0e6be5c7
8 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
require("plugins")
require("config")

1
lua/config/init.lua Normal file
View File

@@ -0,0 +1 @@
require("config.lazy")

22
lua/config/lazy.lua Normal file
View File

@@ -0,0 +1,22 @@
require("lazy").setup({
"navarasu/onedark.nvim",
-- Auto-completion engine
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp", -- lsp auto-completion
"hrsh7th/cmp-buffer", -- buffer auto-completion
"hrsh7th/cmp-path", -- path auto-completion
"hrsh7th/cmp-cmdline", -- cmdline auto-completion
},
config = function()
require("config.nvim-cmp")
end,
},
-- Code snippet engine
{
"L3MON4D3/LuaSnip",
version = "v2.*",
},
})

79
lua/config/nvim-cmp.lua Normal file
View File

@@ -0,0 +1,79 @@
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local luasnip = require("luasnip")
local cmp = require("cmp")
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
mapping = cmp.mapping.preset.insert({
-- Use <C-b/f> to scroll the docs
['K'] = cmp.mapping.scroll_docs( -4),
['J'] = cmp.mapping.scroll_docs(4),
-- Use <C-k/j> to switch in items
['k'] = cmp.mapping.select_prev_item(),
['j'] = cmp.mapping.select_next_item(),
-- Use <CR>(Enter) to confirm selection
-- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
-- A super tab
-- sourc: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
["<Tab>"] = cmp.mapping(function(fallback)
-- Hint: if the completion menu is visible select next one
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }), -- i - insert mode; s - select mode
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable( -1) then
luasnip.jump( -1)
else
fallback()
end
end, { "i", "s" }),
}),
-- Let's configure the item's appearance
-- source: https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance
formatting = {
-- Set order from left to right
-- kind: single letter indicating the type of completion
-- abbr: abbreviation of "word"; when not empty it is used in the menu instead of "word"
-- menu: extra text for the popup menu, displayed after "word" or "abbr"
fields = { 'abbr', 'menu' },
-- customize the appearance of the completion menu
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[Lsp]',
luasnip = '[Luasnip]',
buffer = '[File]',
path = '[Path]',
})[entry.source.name]
return vim_item
end,
},
-- Set source precedence
sources = cmp.config.sources({
{ name = 'nvim_lsp' }, -- For nvim-lsp
{ name = 'luasnip' }, -- For luasnip user
{ name = 'buffer' }, -- For buffer word completion
{ name = 'path' }, -- For path completion
})
})

6
lua/config/theme.lua Normal file
View File

@@ -0,0 +1,6 @@
local onedark = require("onedark")
onedark.setup{
style = "darker"
}
onedark.load()

1
lua/plugins/init.lua Normal file
View File

@@ -0,0 +1 @@
require("lua.plugins.lazy")

13
lua/plugins/lazy.lua Normal file
View File

@@ -0,0 +1,13 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)

View File

@@ -29,6 +29,7 @@ map('n', '<leader>wc', ':close<CR>', opts)
-- tab management
map('n', '<tab>', ':tabnext<CR>', opts)
map('n', '<leader>x', ':tabclose<CR>', opts)
map('n', '<leader>n', ':$tabnew<CR>', opts)
map('n', '<leader>s', ':$tab split<CR>', opts)