This commit is contained in:
YuhangQ 2022-11-25 15:42:27 +08:00
parent 504f938082
commit d1a1b650ae
7 changed files with 204 additions and 29 deletions

View File

@ -27,3 +27,5 @@ require("plugin-config.nvim-treesitter") -- (新增)
-- 内置LSP (新增)
require("lsp.setup")
require("lsp.cmp") -- (新增)

View File

@ -9,18 +9,18 @@ vim.wo.number = true
vim.wo.relativenumber = true
-- 高亮所在行
vim.wo.cursorline = true
-- 显示左侧图标指示
-- 显示左侧图标指示4
vim.wo.signcolumn = "yes"
-- 右侧参考线,超过表示代码太长了,考虑换行
vim.wo.colorcolumn = "80"
-- 缩进2个空格等于一个Tab
vim.o.tabstop = 2
vim.bo.tabstop = 2
vim.o.softtabstop = 2
vim.o.tabstop = 4
vim.bo.tabstop = 4
vim.o.softtabstop = 4
vim.o.shiftround = true
-- >> << 时移动长度
vim.o.shiftwidth = 2
vim.bo.shiftwidth = 2
vim.o.shiftwidth = 4
vim.bo.shiftwidth = 4
-- 空格替代tab
vim.o.expandtab = true
vim.bo.expandtab = true

View File

@ -166,4 +166,51 @@ pluginKeys.mapLSP = function(mapbuf)
-- mapbuf('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opt)
end
pluginKeys.cmp = function(cmp)
return {
-- 出现补全
["<A-.>"] = cmp.mapping(cmp.mapping.complete(), {"i", "c"}),
-- 取消
["<A-,>"] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close()
}),
-- 上一个
["<C-k>"] = cmp.mapping.select_prev_item(),
-- 下一个
["<C-j>"] = cmp.mapping.select_next_item(),
-- 确认
["<CR>"] = cmp.mapping.confirm({
select = true,
behavior = cmp.ConfirmBehavior.Replace
}),
-- 如果窗口内容太多,可以滚动
["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), {"i", "c"}),
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), {"i", "c"}),
-- Super Tab
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, {"i", "s"}),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, {"i", "s"})
-- end of super Tab
}
end
return pluginKeys

57
lua/lsp/cmp.lua Normal file
View File

@ -0,0 +1,57 @@
local cmp = require("cmp")
cmp.setup({
-- 指定 snippet 引擎
snippet = {
expand = function(args)
-- For `vsnip` users.
vim.fn["vsnip#anonymous"](args.body)
-- For `luasnip` users.
-- require('luasnip').lsp_expand(args.body)
-- For `ultisnips` users.
-- vim.fn["UltiSnips#Anon"](args.body)
-- For `snippy` users.
-- require'snippy'.expand_snippet(args.body)
end,
},
-- 补全源
sources = cmp.config.sources({
{ name = "nvim_lsp" },
-- For vsnip users.
{ name = "vsnip" },
-- For luasnip users.
-- { name = 'luasnip' },
--For ultisnips users.
-- { name = 'ultisnips' },
-- -- For snippy users.
-- { name = 'snippy' },
}, { { name = "buffer" }, { name = "path" } }),
-- 快捷键设置
mapping = require("keybindings").cmp(cmp),
})
-- / 查找模式使用 buffer 源
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
-- : 命令行模式中使用 path 和 cmdline 源.
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})

View File

@ -31,6 +31,20 @@ packer.startup({
-- Lspconfig
use({ "neovim/nvim-lspconfig" })
-- 补全引擎
use("hrsh7th/nvim-cmp")
-- snippet 引擎
use("hrsh7th/vim-vsnip")
-- 补全源
use("hrsh7th/cmp-vsnip")
use("hrsh7th/cmp-nvim-lsp") -- { name = nvim_lsp }
use("hrsh7th/cmp-buffer") -- { name = 'buffer' },
use("hrsh7th/cmp-path") -- { name = 'path' }
use("hrsh7th/cmp-cmdline") -- { name = 'cmdline' }
-- 常见编程语言代码段
use("rafamadriz/friendly-snippets")
--------------------- colorschemes --------------------
-- tokyonight
use("folke/tokyonight.nvim")

View File

@ -49,8 +49,8 @@ local function save_profiles(threshold)
end
time([[Luarocks path setup]], true)
local package_path_str = "/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua"
local install_cpath_pattern = "/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so"
local package_path_str = "/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua"
local install_cpath_pattern = "/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so"
if not string.find(package.path, package_path_str, 1, true) then
package.path = package.path .. ';' .. package_path_str
end
@ -76,108 +76,148 @@ time([[Defining packer_plugins]], true)
_G.packer_plugins = {
["bufferline.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/bufferline.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/bufferline.nvim",
url = "https://github.com/akinsho/bufferline.nvim"
},
["cmp-buffer"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-buffer",
url = "https://github.com/hrsh7th/cmp-buffer"
},
["cmp-cmdline"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-cmdline",
url = "https://github.com/hrsh7th/cmp-cmdline"
},
["cmp-nvim-lsp"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
url = "https://github.com/hrsh7th/cmp-nvim-lsp"
},
["cmp-path"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-path",
url = "https://github.com/hrsh7th/cmp-path"
},
["cmp-vsnip"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-vsnip",
url = "https://github.com/hrsh7th/cmp-vsnip"
},
["dashboard-nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/dashboard-nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/dashboard-nvim",
url = "https://github.com/glepnir/dashboard-nvim"
},
["friendly-snippets"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/friendly-snippets",
url = "https://github.com/rafamadriz/friendly-snippets"
},
["gruvbox.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/gruvbox.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/gruvbox.nvim",
url = "https://github.com/ellisonleao/gruvbox.nvim"
},
["lualine-lsp-progress"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/lualine-lsp-progress",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/lualine-lsp-progress",
url = "https://github.com/arkav/lualine-lsp-progress"
},
["lualine.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/lualine.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/lualine.nvim",
url = "https://github.com/nvim-lualine/lualine.nvim"
},
["lush.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/lush.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/lush.nvim",
url = "https://github.com/rktjmp/lush.nvim"
},
["nightfox.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nightfox.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nightfox.nvim",
url = "https://github.com/EdenEast/nightfox.nvim"
},
["nord.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nord.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nord.nvim",
url = "https://github.com/shaunsingh/nord.nvim"
},
["nvim-cmp"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-cmp",
url = "https://github.com/hrsh7th/nvim-cmp"
},
["nvim-lsp-installer"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer",
url = "https://github.com/williamboman/nvim-lsp-installer"
},
["nvim-lspconfig"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
url = "https://github.com/neovim/nvim-lspconfig"
},
["nvim-tree.lua"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-tree.lua",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-tree.lua",
url = "https://github.com/kyazdani42/nvim-tree.lua"
},
["nvim-treesitter"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
url = "https://github.com/nvim-treesitter/nvim-treesitter"
},
["nvim-web-devicons"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-web-devicons",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-web-devicons",
url = "https://github.com/kyazdani42/nvim-web-devicons"
},
["oceanic-next"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/oceanic-next",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/oceanic-next",
url = "https://github.com/mhartington/oceanic-next"
},
["onedark.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/onedark.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/onedark.nvim",
url = "https://github.com/ful1e5/onedark.nvim"
},
["packer.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/packer.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/packer.nvim",
url = "https://github.com/wbthomason/packer.nvim"
},
["plenary.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/plenary.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/plenary.nvim",
url = "https://github.com/nvim-lua/plenary.nvim"
},
["project.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/project.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/project.nvim",
url = "https://github.com/ahmedkhalf/project.nvim"
},
["telescope.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/telescope.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/telescope.nvim",
url = "https://github.com/nvim-telescope/telescope.nvim"
},
["tokyonight.nvim"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/tokyonight.nvim",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/tokyonight.nvim",
url = "https://github.com/folke/tokyonight.nvim"
},
["vim-bbye"] = {
loaded = true,
path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/vim-bbye",
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/vim-bbye",
url = "https://github.com/moll/vim-bbye"
},
["vim-vsnip"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/vim-vsnip",
url = "https://github.com/hrsh7th/vim-vsnip"
}
}

15
test.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
int main (int argc, char *argv[])
{
map<int, int> mp;
mp.size();
mp.size();
return 0;
}