CosmicNvim/CosmicNvim

website github github
pre-made-configuration
stars 1,164
issues 0
subscribers 18
forks 63
CREATED

UPDATED


CosmicNvim is a lightweight and opinionated Neovim config for web development, specifically designed to provide a 💫 COSMIC programming experience!

🚀 Stellar Features

Native LSP

Full featured native LSP functionality!

  • 📘 Go-to definition
  • 🔍 Find references/type def/declaration
  • 💡 Code actions
  • 🚨 Statusline diagnostics
  • 🔧 Formatting thanks to conform.nvim

Additional features

While CosmicNvim is geared specifically toward TypeScript/JavaScript development, it should be able to provide a great experience with any LSP supported language.

🛠 Installation

Quick guide

Prerequisites

  • Neovim 0.13.0+ (Nightly)
  • Git to clone CosmicNvim and install plugins
  • Node.js with npm for JS/TS tooling
  • External formatters for the languages you use, listed below

Install

# Create and enter Neovim's config parent directory.
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}" && cd "${XDG_CONFIG_HOME:-$HOME/.config}" || exit 1
# Move an existing config or symlink into a unique backup directory.
if [ -e nvim ] || [ -L nvim ]; then
  backup_dir=$(mktemp -d "$PWD/nvim.backup.XXXXXX") || exit 1
  mv nvim "$backup_dir/nvim" || exit 1
  printf 'Previous config saved to %s/nvim\n' "$backup_dir"
fi
# Clone into the now-empty destination, then install plugins on first launch.
git clone https://github.com/CosmicNvim/CosmicNvim.git nvim && nvim

By default, this will assume the Cosmic git directory is placed at vim.fn.stdpath('config'), i.e. ~/.config/nvim. If you are symlinking your pulled repo to ~/.config/nvim, you must define the shell environment variable COSMICNVIM_INSTALL_DIR that points to your installation.

After plugins finish installing, run :checkhealth cosmic to check the installation and external tools.

Formatters

Conform uses the following tools from lua/cosmic/plugins/conform/init.lua. Install the tools for your filetypes and make sure Neovim can find their executables on PATH. LSP server installation through Mason does not install all of these formatters.

Filetypes Configured formatters, in order
JavaScript, TypeScript, JSX, TSX eslint_d, oxlint, oxfmt
CSS, SCSS, HTML, JSON, Markdown oxfmt
Lua stylua
Go goimports, gofmt
Python ruff_fix, ruff_format, ruff_organize_imports, all using the ruff executable

For web tooling, install Node.js and npm, then run:

npm install -g eslint_d oxlint oxfmt

Use your project's ESLint dependency and configuration with eslint_d. prettierd is not part of the default formatter configuration.

For other languages, install only what you need:

  • Lua: install Rust/Cargo, then run cargo install stylua --locked. Put ~/.cargo/bin on PATH.
  • Go: install Go, which includes gofmt, then run go install golang.org/x/tools/cmd/goimports@latest. Add $(go env GOPATH)/bin to PATH, or your GOBIN directory if you set one.
  • Python: install pipx, then run pipx install ruff and pipx ensurepath.

Restart your shell and Neovim after changing PATH. Open a source file and run :ConformInfo to see which formatters are available and inspect the formatter log. Use :checkhealth cosmic for broader setup checks.

Additional CosmicNvim installation details.

Additional LSP server installation details.

CosmicNvim uninstallation details.

⚙️ Configuration

General Info

Cosmic configurations

Add additional vim options

LSP config merging

Plugin customization in lua/cosmic/config/config.lua uses:

  • plugins = { ... } for direct lazy.nvim specs
  • { 'repo/name', enabled = false } to disable a built-in plugin
  • another spec with the same repository ID to override a built-in plugin
  • lsp.servers.NAME = true | false | { ... } to enable, disable, or override an LSP server

Built-in LSP defaults come from nvim-lspconfig and are extended by after/lsp/*.lua. User config under lsp.servers.NAME is merged on top of those defaults when the server is enabled.

Enabled servers are installed through Mason automatically. Enabled servers are enabled by Cosmic with vim.lsp.enable().

disable_builtin_plugins, plugins.add, plugins.disable, plugins.opts, plugins.override, and lsp.servers.NAME.opts have been removed.

✨ Cosmic Commands

Update CosmicNvim

Updates CosmicNvim to the latest version

:CosmicUpdate

📷 Screenshots

See more