Skip to content

brianhuster/nvcat

Repository files navigation

nvcat

A command-line utility that displays files with Neovim's syntax highlighting in the terminal.

Overview

nvcat is a CLI tool similar to Unix's cat but with syntax highlighting powered by Neovim's syntax and treesitter engines. It leverages Neovim's capabilities to provide accurate syntax highlighting for a wide range of file formats directly in your terminal.

Features

  • Syntax highlighting using Neovim's highlighting engine
  • Support for treesitter-based highlighting
  • Optional line numbers
  • Can use your existing Neovim configuration or run with a clean instance
Viewing a Lua file with Tokyonight-night colorscheme
Nvcat as fzf's preview, with my custom colorscheme.

Installation

Prequisites:

  • Neovim 0.10+ (must be accessible via nvim)
  • A terminal that supports true color

Prebuilt binaries

See the releases page for prebuilt binaries for Linux, macOS, and Windows.

From source

Requires Go 1.22+

go install github.com/brianhuster/nvimcat@latest

Or clone and build manually:

git clone https://github.com/brianhuster/nvcat.git
cd nvcat
sudo make install

Usage

nvcat [options] <file>

Options

  • -n: Show line numbers
  • -clean: Don't load Neovim's config
  • -v: Show version information
  • -h: Show help information

Configuration

You can configure Nvcat using Vimscript or Lua just the same as you would with Neovim. However, it is recommended to start from a scratch config, because LSP, plugins can cause unnecessary long startup time and other unexpected behaviors. Generally you would only need to set colorscheme, tabstop, or enable Treesitter highlighting

There are 2 ways to configure Nvcat:

1. Use Nvcat's config directory: $XDG_CONFIG_HOME/nvcat/init.lua or $XDG_CONFIG_HOME/nvcat/init.vim.

With this method, your Nvcat configuration will be seperated from your Neovim configuration, and it can be loaded even when the flag -clean is given

Example:

--- ~/.config/nvcat/init.lua
vim.opt.rtp:append(path/to/your/colorscheme/runtimepath)
-- Add runtimepath directory containing 'parser/<your-treesitter-parsers>'
vim.opt.rtp:append("replace/with/your/actual/path")

vim.cmd.colorscheme("your-colorscheme")
vim.o.tabstop = 4

vim.api.nvim_create_autocmd("FileType", {
    callback = function()
        pcall(vim.treesitter.start)
    end
})

2. Use Neovim's config dictionary (:echo stdpath('config')).

Nvcat sets Vimscript variable g:nvcat on startup, so you can use it to control which parts of your Neovim configuration should not be used by Nvcat.

Example:

--- ~/.config/nvim/init.lua
if vim.g.nvcat then
    -- Nvcat configuration
else
    -- LSP, plugins, etc.
end

Limitationns

  • nvcat only supports legacy and Treesitter-based syntax highlighting engines. It does not support LSP-based highlighting.
  • nvcat doesn't change background colors, so you should use a color scheme that has a background color similar to your terminal's

Buy me a coffee

Paypal VietQR

Credits

About

`cat` but with syntax highlighting powered by Neovim

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published