Added completion and some key mappings
This commit is contained in:
93
lua/cmp_plug.lua
Normal file
93
lua/cmp_plug.lua
Normal file
@ -0,0 +1,93 @@
|
||||
local cmp = require('cmp')
|
||||
|
||||
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
|
||||
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil
|
||||
end
|
||||
|
||||
cmp.setup {
|
||||
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
-- fancy icons and a name of kind
|
||||
vim_item.kind = require("lspkind").presets.default[vim_item.kind] ..
|
||||
" " .. vim_item.kind
|
||||
-- set a name for each source
|
||||
vim_item.menu = ({
|
||||
buffer = "[Buffer]",
|
||||
nvim_lsp = "[LSP]",
|
||||
ultisnips = "[UltiSnips]",
|
||||
nvim_lua = "[Lua]",
|
||||
cmp_tabnine = "[TabNine]",
|
||||
look = "[Look]",
|
||||
path = "[Path]",
|
||||
spell = "[Spell]",
|
||||
calc = "[Calc]",
|
||||
emoji = "[Emoji]"
|
||||
})[entry.source.name]
|
||||
return vim_item
|
||||
end
|
||||
},
|
||||
mapping = {
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
['<C-n>'] = cmp.mapping.select_next_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.Insert,
|
||||
select = true
|
||||
}),
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if vim.fn.pumvisible() == 1 then
|
||||
if vim.fn["UltiSnips#CanExpandSnippet"]() == 1 or
|
||||
vim.fn["UltiSnips#CanJumpForwards"]() == 1 then
|
||||
return vim.fn.feedkeys(t(
|
||||
"<C-R>=UltiSnips#ExpandSnippetOrJump()<CR>"))
|
||||
end
|
||||
|
||||
vim.fn.feedkeys(t("<C-n>"), "n")
|
||||
elseif check_back_space() then
|
||||
vim.fn.feedkeys(t("<tab>"), "n")
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, {"i", "s"}),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if vim.fn.pumvisible() == 1 then
|
||||
vim.fn.feedkeys(t("<C-p>"), "n")
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, {"i", "s"})
|
||||
},
|
||||
snippet = {expand = function(args) vim.fn["UltiSnips#Anon"](args.body) end},
|
||||
sources = {
|
||||
{name = 'buffer'}, {name = 'nvim_lsp'}, {name = "ultisnips"},
|
||||
{name = "nvim_lua"}, {name = "look"}, {name = "path"},
|
||||
{name = 'cmp_tabnine'}, {name = "calc"}, {name = "spell"},
|
||||
{name = "emoji"}
|
||||
},
|
||||
completion = {completeopt = 'menu,menuone,noinsert'}
|
||||
}
|
||||
|
||||
-- Autopairs
|
||||
--require("nvim-autopairs.completion.cmp").setup({
|
||||
-- map_cr = true,
|
||||
-- map_complete = true,
|
||||
-- auto_select = true
|
||||
--})
|
||||
|
||||
-- TabNine
|
||||
--local tabnine = require('cmp_tabnine.config')
|
||||
--tabnine:setup({max_lines = 1000, max_num_results = 20, sort = true})
|
||||
|
||||
-- Database completion
|
||||
vim.api.nvim_exec([[
|
||||
autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })
|
||||
]], false)
|
@ -11,6 +11,20 @@ utils.map('v', '<leader>y', '"+y')
|
||||
utils.map('n', '<leader>Y', '"+yg_')
|
||||
utils.map('n', '<leader>y', '"+y')
|
||||
utils.map('n', '<leader>yy', '"+yy')
|
||||
-- Tabs and Split
|
||||
|
||||
utils.map('n', 'F2', ':tabnew .<CR>')
|
||||
-- Tabs
|
||||
utils.map('n', '<F2>', ':tabnew .<CR>')
|
||||
utils.map('i', '<F2>', '<Esc>:tabnew .<CR>')
|
||||
utils.map('n', '<S-Right>', 'gt')
|
||||
utils.map('n', '<S-Left>', 'gT')
|
||||
-- Split movement
|
||||
utils.map('n', '<A-Up>', ':wincmd k<CR>')
|
||||
utils.map('n', '<A-Down>', ':wincmd j<CR>')
|
||||
utils.map('n', '<A-Left>', ':wincmd h<CR>')
|
||||
utils.map('n', '<A-Right>', ':wincmd l<CR>')
|
||||
-- Open a new vertical split window with Ctrl - F2
|
||||
utils.map('n', '<C-F2>', '<Esc>:vsplit .<CR>')
|
||||
utils.map('i', '<C-F2>', '<Esc>:vsplit .<CR>')
|
||||
-- Open a new horizontal split window with Shift - F2
|
||||
utils.map('n', '<S-F2>', '<Esc>:split .<CR>')
|
||||
utils.map('i', '<S-F2>', '<Esc>:split .<CR>')
|
||||
|
@ -13,4 +13,19 @@ return require('packer').startup(function()
|
||||
use {'nvim-lua/plenary.nvim'}
|
||||
use {'lewis6991/gitsigns.nvim'}
|
||||
use {'kosayoda/nvim-lightbulb'}
|
||||
use {
|
||||
'kyazdani42/nvim-tree.lua',
|
||||
requires = 'kyazdani42/nvim-web-devicons'
|
||||
}
|
||||
use {'terrortylor/nvim-comment'}
|
||||
use {
|
||||
'hrsh7th/nvim-cmp',
|
||||
requires = {
|
||||
'hrsh7th/cmp-buffer', 'hrsh7th/cmp-nvim-lsp',
|
||||
'quangnguyen30192/cmp-nvim-ultisnips', 'hrsh7th/cmp-nvim-lua',
|
||||
'octaltree/cmp-look', 'hrsh7th/cmp-path', 'hrsh7th/cmp-calc',
|
||||
'f3fora/cmp-spell', 'hrsh7th/cmp-emoji'
|
||||
}
|
||||
}
|
||||
use {'onsails/lspkind-nvim'}
|
||||
end)
|
||||
|
Reference in New Issue
Block a user