-- TODO: figure out how to simplify the snippets config -- TODO: figure out how to create custom snippets -- TODO: is it possible to use luasnip without nvim-cpm? local function prequire(...) local status, lib = pcall(require, ...) if (status) then return lib end return nil end local luasnip = prequire('luasnip') local cmp = prequire("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 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 cmp and cmp.visible() then cmp.select_next_item() elseif luasnip and luasnip.expand_or_jumpable() then return t("luasnip-expand-or-jump") elseif check_back_space() then return t "" else cmp.complete() end return "" end _G.s_tab_complete = function() if cmp and cmp.visible() then cmp.select_prev_item() elseif luasnip and luasnip.jumpable(-1) then return t("luasnip-jump-prev") else return t "" end return "" end 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}) vim.api.nvim_set_keymap("i", "", "luasnip-next-choice", {}) vim.api.nvim_set_keymap("s", "", "luasnip-next-choice", {}) require("luasnip.loaders.from_vscode").lazy_load()