fix: modify nvim-cmp

This commit is contained in:
2022-09-28 11:47:03 +08:00
parent 322da92402
commit 7a1c3989d1
7 changed files with 135 additions and 179 deletions
+5
View File
@@ -1,5 +1,6 @@
run: run:
tests: false tests: false
timeout: 1m
linters: linters:
enable: enable:
- govet - govet
@@ -12,8 +13,12 @@ linters:
- gofmt - gofmt
- stylecheck - stylecheck
- revive - revive
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
disable-all: true disable-all: true
linters-settings: linters-settings:
staticcheck:
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
checks: ["all"]
revive: revive:
# Maximum number of open files at the same time. # Maximum number of open files at the same time.
# See https://github.com/mgechev/revive#command-line-flags # See https://github.com/mgechev/revive#command-line-flags
+1 -1
View File
@@ -134,7 +134,7 @@ alias alert='terminal-notifier -title "Terminal" -message "Done with task! Exit
# git # git
alias gitb="git branch --show-current | tr -d '\n' | pbcopy" alias gitb="git branch --show-current | tr -d '\n' | pbcopy"
alias ct="go test -gcflags=all=-l -cover ./..." alias ct="go test -gcflags=all=-l -cover ./..."
alias ci="golangci-lint run ./..." alias ci="golangci-lint -c=~/.dotfile/.golangci.yml run ./..."
alias gt="go test -gcflags=all=-l " alias gt="go test -gcflags=all=-l "
alias swg="swag init -o docs -g " alias swg="swag init -o docs -g "
alias sws="swagger serve -F=swagger" alias sws="swagger serve -F=swagger"
+24 -24
View File
@@ -1,10 +1,10 @@
vim.api.nvim_set_keymap('n', '-', ':RnvimrToggle<CR>', {noremap = true, silent = true}) vim.api.nvim_set_keymap('n', '-', ':RnvimrToggle<CR>', { noremap = true, silent = true })
-- better window movement -- better window movement
vim.api.nvim_set_keymap('n', '<C-h>', '<C-w>h', {silent = true}) vim.api.nvim_set_keymap('n', '<C-h>', '<C-w>h', { silent = true })
vim.api.nvim_set_keymap('n', '<C-j>', '<C-w>j', {silent = true}) vim.api.nvim_set_keymap('n', '<C-j>', '<C-w>j', { silent = true })
vim.api.nvim_set_keymap('n', '<C-k>', '<C-w>k', {silent = true}) vim.api.nvim_set_keymap('n', '<C-k>', '<C-w>k', { silent = true })
vim.api.nvim_set_keymap('n', '<C-l>', '<C-w>l', {silent = true}) vim.api.nvim_set_keymap('n', '<C-l>', '<C-w>l', { silent = true })
-- better edit -- better edit
vim.api.nvim_set_keymap('n', 'Y', 'y$', {}) vim.api.nvim_set_keymap('n', 'Y', 'y$', {})
@@ -25,27 +25,27 @@ vim.api.nvim_set_keymap('n', 'Y', 'y$', {})
-- TODO fix this -- TODO fix this
-- resize with arrows -- resize with arrows
vim.api.nvim_set_keymap('n', '<C-Up>', ':resize -2<CR>', {silent = true}) vim.api.nvim_set_keymap('n', '<C-Up>', ':resize -2<CR>', { silent = true })
vim.api.nvim_set_keymap('n', '<C-Down>', ':resize +2<CR>', {silent = true}) vim.api.nvim_set_keymap('n', '<C-Down>', ':resize +2<CR>', { silent = true })
vim.api.nvim_set_keymap('n', '<C-Left>', ':vertical resize -2<CR>', {silent = true}) vim.api.nvim_set_keymap('n', '<C-Left>', ':vertical resize -2<CR>', { silent = true })
vim.api.nvim_set_keymap('n', '<C-Right>', ':vertical resize +2<CR>', {silent = true}) vim.api.nvim_set_keymap('n', '<C-Right>', ':vertical resize +2<CR>', { silent = true })
-- better indenting -- better indenting
vim.api.nvim_set_keymap('v', '<', '<gv', {noremap = true, silent = true}) vim.api.nvim_set_keymap('v', '<', '<gv', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '>', '>gv', {noremap = true, silent = true}) vim.api.nvim_set_keymap('v', '>', '>gv', { noremap = true, silent = true })
-- I hate escape -- I hate escape
vim.api.nvim_set_keymap('i', 'jk', '<ESC>', {noremap = true, silent = true}) vim.api.nvim_set_keymap('i', 'jk', '<ESC>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', 'kj', '<ESC>', {noremap = true, silent = true}) vim.api.nvim_set_keymap('i', 'kj', '<ESC>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', 'jj', '<ESC>', {noremap = true, silent = true}) vim.api.nvim_set_keymap('i', 'jj', '<ESC>', { noremap = true, silent = true })
-- Tab switch buffer -- Tab switch buffer
vim.api.nvim_set_keymap('n', '<TAB>', ':bnext<CR>', {noremap = true, silent = true}) vim.api.nvim_set_keymap('n', '<TAB>', ':bnext<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<S-TAB>', ':bprevious<CR>', {noremap = true, silent = true}) vim.api.nvim_set_keymap('n', '<S-TAB>', ':bprevious<CR>', { noremap = true, silent = true })
-- Move selected line / block of text in visual mode -- Move selected line / block of text in visual mode
vim.api.nvim_set_keymap('x', 'K', ':move \'<-2<CR>gv-gv', {noremap = true, silent = true}) vim.api.nvim_set_keymap('x', 'K', ':move \'<-2<CR>gv-gv', { noremap = true, silent = true })
vim.api.nvim_set_keymap('x', 'J', ':move \'>+1<CR>gv-gv', {noremap = true, silent = true}) vim.api.nvim_set_keymap('x', 'J', ':move \'>+1<CR>gv-gv', { noremap = true, silent = true })
-- Better nav for omnicomplete -- Better nav for omnicomplete
vim.cmd('inoremap <expr> <c-j> (\"\\<C-n>\")') vim.cmd('inoremap <expr> <c-j> (\"\\<C-n>\")')
@@ -69,13 +69,13 @@ vim.cmd('vnoremap P "0P')
-- ]]) -- ]])
-- Toggle the QuickFix window -- Toggle the QuickFix window
vim.api.nvim_set_keymap('', '<C-q>', ':call QuickFixToggle()<CR>', {noremap = true, silent = true}) vim.api.nvim_set_keymap('', '<C-q>', ':call QuickFixToggle()<CR>', { noremap = true, silent = true })
-- nvim-compe key map -- nvim-compe key map
vim.cmd('inoremap <silent><expr> <C-Space> compe#complete()') -- vim.cmd('inoremap <silent><expr> <C-Space> compe#complete()')
vim.cmd("inoremap <silent><expr> <CR> compe#confirm('<CR>')") -- vim.cmd("inoremap <silent><expr> <CR> compe#confirm('<CR>')")
vim.cmd("inoremap <silent><expr> <C-e> compe#close('<C-e>')") -- vim.cmd("inoremap <silent><expr> <C-e> compe#close('<C-e>')")
vim.cmd("inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })") -- vim.cmd("inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })")
vim.cmd("inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })") -- vim.cmd("inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })")
+1 -1
View File
@@ -12,7 +12,7 @@ require('pluginconfig/neotest')
require('pluginconfig/numb') require('pluginconfig/numb')
require('pluginconfig/nvim-autopairs') require('pluginconfig/nvim-autopairs')
require('pluginconfig/nvim-colorizer') require('pluginconfig/nvim-colorizer')
require('pluginconfig/nvim-compe') require('pluginconfig/nvim-cmp')
require('pluginconfig/fzf-lua') require('pluginconfig/fzf-lua')
require('pluginconfig/nvim-tree') -- This plugin must be required somewhere before colorscheme. Placing it after will break navigation keymappings require('pluginconfig/nvim-tree') -- This plugin must be required somewhere before colorscheme. Placing it after will break navigation keymappings
require('pluginconfig/nvim-treesitter') require('pluginconfig/nvim-treesitter')
+92
View File
@@ -0,0 +1,92 @@
local lspkind = require('lspkind')
local cmp = require 'cmp'
local function keymapping(cmp)
return {
-- 上一个
['<C-k>'] = cmp.mapping.select_prev_item(),
-- 下一个
['<C-j>'] = cmp.mapping.select_next_item(),
-- 出现补全
['<A-.>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
-- 取消
['<A-,>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
-- 确认
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({
select = true,
behavior = cmp.ConfirmBehavior.Replace
}),
-- ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-u>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
}
end
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 = keymapping(cmp),
-- 使用lspkind-nvim显示类型图标
formatting = {
format = lspkind.cmp_format({
with_text = true, -- do not show text alongside icons
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
before = function(entry, vim_item)
-- Source 显示提示来源
vim_item.menu = "[" .. string.upper(entry.source.name) .. "]"
return vim_item
end
})
},
}
-- Use buffer source for `/`.
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':'.
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-150
View File
@@ -1,150 +0,0 @@
vim.o.completeopt = "menuone,noselect"
require'compe'.setup {
enabled = true,
autocomplete = true,
debug = false,
min_length = 1,
preselect = 'enable',
throttle_time = 80,
source_timeout = 200,
incomplete_delay = 400,
max_abbr_width = 100,
max_kind_width = 100,
max_menu_width = 100,
documentation = true,
source = {
path = {kind = "  (Path)"},
buffer = {kind = "  (Buffer)"},
calc = {kind = "  (Calc)"},
vsnip = {kind = "  (Snippet)"},
nvim_lsp = {kind = "  (LSP)"},
-- nvim_lua = {kind = "  "},
nvim_lua = false,
spell = {kind = "  (Spell)"},
tags = false,
vim_dadbod_completion = true,
-- snippets_nvim = {kind = "  "},
-- ultisnips = {kind = "  "},
-- treesitter = {kind = "  "},
emoji = {kind = " ﲃ (Emoji)", filetypes={"markdown", "text"}}
-- for emoji press : (idk if that in compe tho)
}
}
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- ﬘
-- 
-- 
-- 
-- m
-- 
-- 
-- 
-- 
-- 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
-- if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
-- return true
-- else
-- return false
-- end
-- end
-- -- Use (s-)tab to:
-- --- move to prev/next item in completion menuone
-- --- jump to prev/next snippet's placeholder
-- _G.tab_complete = function()
-- if vim.fn.pumvisible() == 1 then
-- return t "<C-n>"
-- elseif vim.fn.call("vsnip#available", {1}) == 1 then
-- return t "<Plug>(vsnip-expand-or-jump)"
-- elseif check_back_space() then
-- return t "<Tab>"
-- else
-- return vim.fn['compe#complete']()
-- end
-- end
-- _G.s_tab_complete = function()
-- if vim.fn.pumvisible() == 1 then
-- return t "<C-p>"
-- elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
-- return t "<Plug>(vsnip-jump-prev)"
-- else
-- return t "<S-Tab>"
-- end
-- end
-- vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
-- vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
-- vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
-- vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
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
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif vim.fn.call("vsnip#available", {1}) == 1 then
return t "<Plug>(vsnip-expand-or-jump)"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
+12 -3
View File
@@ -60,8 +60,18 @@ return require("packer").startup(function(use)
-- Debugging -- Debugging
use { "mfussenegger/nvim-dap", opt = true } use { "mfussenegger/nvim-dap", opt = true }
-- Autocomplete -- nvim-cmp
use { "hrsh7th/nvim-compe", opt = true } 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 'hrsh7th/nvim-cmp'
-- vsnip
use 'hrsh7th/cmp-vsnip' -- { name = 'vsnip' }
use 'hrsh7th/vim-vsnip'
use 'rafamadriz/friendly-snippets'
-- lspkind
use 'onsails/lspkind-nvim'
-- Treesitter -- Treesitter
use { "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" } use { "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" }
@@ -155,7 +165,6 @@ return require("packer").startup(function(use)
require_plugin("telescope.nvim") require_plugin("telescope.nvim")
require_plugin('telescope-project.nvim') require_plugin('telescope-project.nvim')
require_plugin("nvim-dap") require_plugin("nvim-dap")
require_plugin("nvim-compe")
require_plugin("nvim-ts-autotag") require_plugin("nvim-ts-autotag")
require_plugin('vim-matchup') require_plugin('vim-matchup')
require_plugin("nvim-tree.lua") require_plugin("nvim-tree.lua")