lazy loading : compe

This commit is contained in:
siduck76 2021-06-24 22:49:42 +05:30
parent bbadee53ad
commit e771a32ab8
4 changed files with 91 additions and 78 deletions

View File

@ -10,7 +10,6 @@ require("neoscroll").setup() -- smooth scroll
-- lsp stuff -- lsp stuff
require "nvim-lspconfig" require "nvim-lspconfig"
require "compe-completion"
local cmd = vim.cmd local cmd = vim.cmd
local g = vim.g local g = vim.g

View File

@ -1,6 +1,7 @@
vim.o.completeopt = "menuone,noselect" local M = {}
require "compe".setup { M.config = function()
require "compe".setup {
enabled = true, enabled = true,
autocomplete = true, autocomplete = true,
debug = false, debug = false,
@ -15,60 +16,10 @@ require "compe".setup {
documentation = true, documentation = true,
source = { source = {
buffer = {kind = "", true}, buffer = {kind = "", true},
vsnip = {kind = ""}, --replace to what sign you prefer vsnip = {kind = ""},
nvim_lsp = true nvim_lsp = true
} }
} }
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end end
local check_back_space = function() return M
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
-- tab completion
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
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
-- mappings
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})
function _G.completions()
local npairs = require("nvim-autopairs")
if vim.fn.pumvisible() == 1 then
if vim.fn.complete_info()["selected"] ~= -1 then
return vim.fn["compe#confirm"]("<CR>")
end
end
return npairs.check_break_line_char()
end
vim.api.nvim_set_keymap("i", "<CR>", "v:lua.completions()", {expr = true})

View File

@ -1,4 +1,4 @@
local function map(mode, lhs, rhs, opts) local function map(mode, lhs, rhs, opts)
local options = {noremap = true} local options = {noremap = true}
if opts then if opts then
options = vim.tbl_extend("force", options, opts) options = vim.tbl_extend("force", options, opts)
@ -8,7 +8,7 @@ end
local opt = {} local opt = {}
-- dont copy any deleted text , this is disabled by default so uncomment the below mappings if you want them! -- dont copy any deleted text , this is disabled by default so uncomment the below mappings if you want them
--[[ remove this line --[[ remove this line
map("n", "dd", [=[ "_dd ]=], opt) map("n", "dd", [=[ "_dd ]=], opt)
@ -16,18 +16,20 @@ map("v", "dd", [=[ "_dd ]=], opt)
map("v", "x", [=[ "_x ]=], opt) map("v", "x", [=[ "_x ]=], opt)
this line too ]] this line too ]]
--
-- OPEN TERMINALS -- -- OPEN TERMINALS --
map("n", "<C-l>", [[<Cmd>vnew term://bash <CR>]], opt) -- term over right map("n", "<C-l>", [[<Cmd>vnew term://bash <CR>]], opt) -- term over right
map("n", "<C-x>", [[<Cmd> split term://bash | resize 10 <CR>]], opt) -- term bottom map("n", "<C-x>", [[<Cmd> split term://bash | resize 10 <CR>]], opt) -- term bottom
map("n", "<C-t>t", [[<Cmd> tabnew | term <CR>]], opt) -- term newtab map("n", "<C-t>t", [[<Cmd> tabnew | term <CR>]], opt) -- term newtab
-- COPY EVERYTHING -- -- copy whole file content
map("n", "<C-a>", [[ <Cmd> %y+<CR>]], opt) map("n", "<C-a>", [[ <Cmd> %y+<CR>]], opt)
-- toggle numbers --- -- toggle numbers
map("n", "<leader>n", [[ <Cmd> set nu!<CR>]], opt) map("n", "<leader>n", [[ <Cmd> set nu!<CR>]], opt)
-- toggle truezen.nvim's ataraxis and minimalist mode -- Truezen.nvim
map("n", "<leader>z", [[ <Cmd> TZAtaraxis<CR>]], opt) map("n", "<leader>z", [[ <Cmd> TZAtaraxis<CR>]], opt)
map("n", "<leader>m", [[ <Cmd> TZMinimalist<CR>]], opt) map("n", "<leader>m", [[ <Cmd> TZMinimalist<CR>]], opt)
@ -37,3 +39,55 @@ map("n", "<C-s>", [[ <Cmd> w <CR>]], opt)
-- Commenter Keybinding -- Commenter Keybinding
map("n", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true}) map("n", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true})
map("v", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true}) map("v", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true})
-- compe stuff
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
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
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
function _G.completions()
local npairs = require("nvim-autopairs")
if vim.fn.pumvisible() == 1 then
if vim.fn.complete_info()["selected"] ~= -1 then
return vim.fn["compe#confirm"]("<CR>")
end
end
return npairs.check_break_line_char()
end
-- compe mappings
map("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
map("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
map("i", "<CR>", "v:lua.completions()", {expr = true})

View File

@ -13,7 +13,16 @@ return packer.startup(
-- lang stuff -- lang stuff
use "nvim-treesitter/nvim-treesitter" use "nvim-treesitter/nvim-treesitter"
use "neovim/nvim-lspconfig" use "neovim/nvim-lspconfig"
use "hrsh7th/nvim-compe"
-- loads compe and vsnip in insert mode only
use {
"hrsh7th/nvim-compe",
event = "InsertEnter",
config = function()
require("compe-completion").config()
end
}
use "onsails/lspkind-nvim" use "onsails/lspkind-nvim"
use "sbdchd/neoformat" use "sbdchd/neoformat"
use "nvim-lua/plenary.nvim" use "nvim-lua/plenary.nvim"
@ -23,7 +32,7 @@ return packer.startup(
use "akinsho/nvim-bufferline.lua" use "akinsho/nvim-bufferline.lua"
use "glepnir/galaxyline.nvim" use "glepnir/galaxyline.nvim"
use "windwp/nvim-autopairs" use "windwp/nvim-autopairs"
use "alvan/vim-closetag" -- use "alvan/vim-closetag" -- for html
-- Comment -- Comment
use "terrortylor/nvim-comment" use "terrortylor/nvim-comment"