Skip to content
项目

关于

CSS Intellisense for HTML

网站与应用开发

这些数字如何统计

可以做什么

  • Completion for class and id attributes, with the CSS rule shown as documentation
  • Picks up stylesheets linked or written inline in the current file, local or remote
  • Global stylesheets and CSS frameworks via style_sheets
  • Hover, go to definition, and peek (open the CSS rule in a floating window)

实测星标增长

24小时
0
7天
0
15天
-1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

☕ Neovim HTML & CSS Support

CSS IntelliSense for HTML

image

✨ Features

  • Completion for class and id attributes, with the CSS rule shown as documentation
  • Picks up stylesheets linked or written inline in the current file, local or remote
  • Global stylesheets and CSS frameworks via style_sheets
  • Hover, go to definition, and peek (open the CSS rule in a floating window)
  • Per-project config through .nvim.lua

Works with any completion engine that reads LSP results (nvim-cmp with cmp-nvim-lsp, blink.cmp's lsp source, built-in completion). The plugin runs a small in-process LSP called html-css-lsp.

⚡️ Requirements

  • Neovim 0.10+
  • curl (for remote stylesheets)
  • Treesitter parsers: html and css, plus tsx / javascript if you use JSX

📦 Installation

vim.pack

vim.pack.add({ "https://github.com/Jezda1337/nvim-html-css" })

require("html-css").setup({
  enable_on = { "html" }, -- file extensions
})

lazy.nvim

{
  "Jezda1337/nvim-html-css",
  dependencies = { "nvim-treesitter/nvim-treesitter" },
  main = "html-css",
  opts = {
    enable_on = { "html" }, -- file extensions
  },
}

Don't lazy-load it with ft or event: the file that triggers loading won't get completion until you reopen it.

enable_on takes file extensions, not filetypes. For example: "html", "vue", "svelte", "astro", "tsx", "jsx", "php" (includes Blade), "erb", "templ", "tmpl", "gohtml". Django templates are usually .html.

🎨 Where styles come from

  • Automatically: stylesheets linked or written inline in the file you're editing. These only apply to that file.
  • style_sheets: anything else, such as a global main.css or a framework your bundler includes. These apply to every enabled file.
style_sheets = {
  "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
  "./src/styles/main.css", -- relative to the folder you started nvim in
}

@imports inside local stylesheets are followed.

🔧 Per-project config

Put a .nvim.lua in the folder you start nvim from:

vim.g.html_css = {
  style_sheets = { "./src/styles/main.css" },
}

The first time, Neovim asks whether to trust the file (:trust to allow it). Values here override your global setup.

⌨️ Hover, definition and peek

The plugin doesn't map any keys itself, but some things work out of the box through Neovim's LSP defaults (0.10+):

  • Hover: K
  • Go to definition: <C-]> gd is not an LSP default in Neovim (it's Vim's built-in "go to local declaration"). To use gd, or to set your own hover key, use handlers:
handlers = {
  hover = { bind = "K" },
  definition = { bind = "gd" },
}

These keymaps only apply in enabled files. If the word under the cursor isn't a known class or id, they fall back to your other LSP servers' hover and definition.

Peek opens the CSS rule in an editable floating window. It has no default key, so map the :HtmlCssPeek command yourself:

vim.keymap.set("n", "<leader>cp", "<cmd>HtmlCssPeek<CR>", { desc = "Peek CSS" })

Close it with q or <Esc>. It won't close while it has unsaved changes.

⚙️ All options

require("html-css").setup({
  enable_on = { "html" },  -- file extensions
  style_sheets = {},       -- extra stylesheets (URLs or paths)
  handlers = {},           -- e.g. { hover = { bind = "K" }, definition = { bind = "gd" } }
                           -- hover also takes: wrap, border, position ("cursor" | "editor")
  peek = {
    enabled = true,        -- creates :HtmlCssPeek
    border = "rounded",
    position = "center",   -- "center" | "cursor"
    width = 0.5,           -- fraction of the editor
    height = 0.5,
    focus = true,          -- move the cursor into the float
    style = "minimal",
  },
  notify = false,          -- log fetches (debugging)
})

Run :checkhealth html-css if something doesn't work.

探索相关项目

加载中…