- Follow the LazyVim installation guide: https://www.lazyvim.org/installation
- Clear the cache by running the following commands:
rm -rf ~/.local/share/nvim
rm -rf ~/.local/state/nvim
rm -rf ~/.cache/nvim
rm -rf ~/.config/nvim- Installation link for LazyVim - https://www.lazyvim.org/installation
- After installing LazyVim, ensure that you have updated and installed all the defaults.
- Use the LazyVim extras (use the
xoption).
- In the LazyVim extras menu, select and install LuaSnip. This ensures all dependencies are installed correctly.
- Paste the following LuaSnip example snippets into your
init.luafile:
(Note: You can organize your snippets into separate folders, but for quick testing, you can directly add them this way to verify they work.)
- Install the LaTeX snippets plugin by adding the following code in the
lua/plugins/latexsnips.luafile:
return {
"evesdropper/luasnip-latex-snippets.nvim",
}- After this, when you load a
.texfile, you will have all the LaTeX snippets available.
- Add the following configuration at the start of your
init.luafile to require LuaSnip and set up key mappings:
-- Require LuaSnip
local luasnip = require("luasnip")
-- Configure key mappings
vim.keymap.set({"i", "s"}, "<Tab>", function()
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
return "<Tab>"
end
end, {silent = true, expr = true})
vim.keymap.set({"i", "s"}, "<S-Tab>", function()
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
return "<S-Tab>"
end
end, {silent = true, expr = true})- Add the following snippet under the previous set up
nvim-cmpto use<Tab>for expanding LuaSnip snippets and<S-Tab>for jumping backward:
-- Setup nvim-cmp.
local cmp = require'cmp'
local luasnip = require'luasnip'
cmp.setup({
mapping = {
-- Use <Tab> to expand snippets
['<Tab>'] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback() -- fall back to normal tab functionality
end
end, { 'i', 's' }),
-- Use <S-Tab> to jump backward in snippets
['<S-Tab>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
},
})- This configuration allows you to use
<Tab>as the expander for LuaSnip snippets. However, it does not provide partial snippet completion. - For example, to expand a LaTeX matrix snippet, you must type the entire trigger (e.g.,
mat) and then press<Tab>. It will not complete with a partial trigger likemafollowed by<Tab>.