Skip to content

Instantly share code, notes, and snippets.

@erlangparasu
Created May 26, 2024 03:52
Show Gist options
  • Save erlangparasu/ed0308ac684fc0cc3056011eef031418 to your computer and use it in GitHub Desktop.
Save erlangparasu/ed0308ac684fc0cc3056011eef031418 to your computer and use it in GitHub Desktop.
my-neovim-example-init.lua
-- Reference: https://templ.guide/commands-and-tools/ide-support/
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct
require("lazy").setup({
'neovim/nvim-lspconfig',
{
-- Autocompletion
'hrsh7th/nvim-cmp',
dependencies = {
'hrsh7th/cmp-nvim-lsp',
},
},
{
-- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
dependencies = {
'vrischmann/tree-sitter-templ',
},
build = ':TSUpdate',
},
})
vim.filetype.add({ extension = { templ = "templ" } })
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
local lspconfig = require("lspconfig")
lspconfig.templ.setup{
on_attach = on_attach,
capabilities = capabilities,
}
lspconfig.tailwindcss.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "templ", "astro", "javascript", "typescript", "react" },
init_options = { userLanguages = { templ = "html" } },
})
lspconfig.html.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "html", "templ" },
})
lspconfig.htmx.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "html", "templ" },
})
local cmp = require 'cmp'
cmp.setup({
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
})
})
require'nvim-treesitter.configs'.setup {
ensure_installed = { "templ" },
sync_install = false,
auto_install = true,
ignore_install = { "javascript" },
highlight = {
enable = true,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment