diff --git a/init.lua b/init.lua index 2750a44..0fc7f3b 100644 --- a/init.lua +++ b/init.lua @@ -10,7 +10,6 @@ require("neoscroll").setup() -- smooth scroll -- lsp stuff require "nvim-lspconfig" -require "compe-completion" local cmd = vim.cmd local g = vim.g diff --git a/lua/compe-completion.lua b/lua/compe-completion.lua index 79ee38a..b9170ae 100644 --- a/lua/compe-completion.lua +++ b/lua/compe-completion.lua @@ -1,74 +1,25 @@ -vim.o.completeopt = "menuone,noselect" +local M = {} -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 = { - buffer = {kind = "﬘", true}, - vsnip = {kind = "﬌"}, --replace to what sign you prefer - nvim_lsp = true +M.config = function() + 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 = { + buffer = {kind = "﬘", true}, + vsnip = {kind = "﬌"}, + nvim_lsp = 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 - --- tab completion - -_G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif check_back_space() then - return t "" - else - return vim.fn["compe#complete"]() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then - return t "(vsnip-jump-prev)" - else - return t "" - end -end - --- mappings - -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "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"]("") - end - end - return npairs.check_break_line_char() -end - -vim.api.nvim_set_keymap("i", "", "v:lua.completions()", {expr = true}) +return M diff --git a/lua/mappings.lua b/lua/mappings.lua index 8d95498..433a06a 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -1,4 +1,4 @@ - local function map(mode, lhs, rhs, opts) +local function map(mode, lhs, rhs, opts) local options = {noremap = true} if opts then options = vim.tbl_extend("force", options, opts) @@ -8,7 +8,7 @@ end 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 map("n", "dd", [=[ "_dd ]=], opt) @@ -16,18 +16,20 @@ map("v", "dd", [=[ "_dd ]=], opt) map("v", "x", [=[ "_x ]=], opt) this line too ]] +-- + -- OPEN TERMINALS -- map("n", "", [[vnew term://bash ]], opt) -- term over right map("n", "", [[ split term://bash | resize 10 ]], opt) -- term bottom map("n", "t", [[ tabnew | term ]], opt) -- term newtab --- COPY EVERYTHING -- +-- copy whole file content map("n", "", [[ %y+]], opt) --- toggle numbers --- +-- toggle numbers map("n", "n", [[ set nu!]], opt) --- toggle truezen.nvim's ataraxis and minimalist mode +-- Truezen.nvim map("n", "z", [[ TZAtaraxis]], opt) map("n", "m", [[ TZMinimalist]], opt) @@ -37,3 +39,55 @@ map("n", "", [[ w ]], opt) -- Commenter Keybinding map("n", "/", ":CommentToggle", {noremap = true, silent = true}) map("v", "/", ":CommentToggle", {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 "" + elseif check_back_space() then + return t "" + else + return vim.fn["compe#complete"]() + end +end + +_G.s_tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" + elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then + return t "(vsnip-jump-prev)" + else + return t "" + 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"]("") + end + end + return npairs.check_break_line_char() +end + +-- compe mappings +map("i", "", "v:lua.tab_complete()", {expr = true}) +map("s", "", "v:lua.tab_complete()", {expr = true}) +map("i", "", "v:lua.s_tab_complete()", {expr = true}) +map("s", "", "v:lua.s_tab_complete()", {expr = true}) +map("i", "", "v:lua.completions()", {expr = true}) diff --git a/lua/pluginList.lua b/lua/pluginList.lua index 13d94d3..5f8f6d0 100644 --- a/lua/pluginList.lua +++ b/lua/pluginList.lua @@ -13,7 +13,16 @@ return packer.startup( -- lang stuff use "nvim-treesitter/nvim-treesitter" 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 "sbdchd/neoformat" use "nvim-lua/plenary.nvim" @@ -23,7 +32,7 @@ return packer.startup( use "akinsho/nvim-bufferline.lua" use "glepnir/galaxyline.nvim" use "windwp/nvim-autopairs" - use "alvan/vim-closetag" + -- use "alvan/vim-closetag" -- for html -- Comment use "terrortylor/nvim-comment"