Home

Awesome

csvview.nvim

csvview.nvim is a lightweight CSV file viewer plugin for Neovim. With this plugin, you can easily view and edit CSV files within Neovim.

csvview

Features

<table> <tr> <th>display_mode = "highlight"</th> <th>display_mode = "border"</th> </tr> <td> <img src="https://github.com/user-attachments/assets/cb26e430-c3cb-407f-bb80-42c11ba7fa19" /> </td> <td> <img src="https://github.com/user-attachments/assets/17e5fc01-9a58-4801-b2a6-3d23ca48e26f" /> </td> </tr> </table>

Requirements

Neovim v0.10 or newer is required.

Installation

Install the plugin using your favorite package manager.

vim-plug

Plug 'hat0uma/csvview.nvim'
lua require('csvview').setup()

lazy.nvim

{
  'hat0uma/csvview.nvim',
  config = function()
    require('csvview').setup()
  end
}

Configuration

csvview.nvim works with default settings, but you can customize options as follows:

require('csvview').setup({
  -- Add your configuration here
})

The configuration options are as follows:

{
  parser = {
    --- The number of lines that the asynchronous parser processes per cycle.
    --- This setting is used to prevent monopolization of the main thread when displaying large files.
    --- If the UI freezes, try reducing this value.
    --- @type integer
    async_chunksize = 50,

    --- The delimiter character
    --- You can specify a string, a table of delimiter characters for each file type, or a function that returns a delimiter character.
    --- e.g:
    ---  delimiter = ","
    ---  delimiter = function(bufnr) return "," end
    ---  delimiter = {
    ---    default = ",",
    ---    ft = {
    ---      tsv = "\t",
    ---    },
    ---  }
    --- @type string | {default: string, ft: table<string,string>} | fun(bufnr:integer): string
    delimiter = {
      default = ",",
      ft = {
        tsv = "\t",
      },
    },

    --- The quote character
    --- If a field is enclosed in this character, it is treated as a single field and the delimiter in it will be ignored.
    --- e.g:
    ---  quote_char= "'"
    --- You can also specify it on the command line.
    --- e.g:
    --- :CsvViewEnable quote_char='
    --- @type string
    quote_char = '"',

    --- The comment prefix characters
    --- If the line starts with one of these characters, it is treated as a comment.
    --- Comment lines are not displayed in tabular format.
    --- You can also specify it on the command line.
    --- e.g:
    --- :CsvViewEnable comment=#
    --- @type string[]
    comments = {
      -- "#",
      -- "--",
      -- "//",
    },
  },
  view = {
    --- minimum width of a column
    --- @type integer
    min_column_width = 5,

    --- spacing between columns
    --- @type integer
    spacing = 2,

    --- The display method of the delimiter
    --- "highlight" highlights the delimiter
    --- "border" displays the delimiter with `│`
    --- see `Features` section of the README.
    ---@type "highlight" | "border"
    display_mode = "highlight",
  },
}

Usage

After opening a CSV file, use the following commands to interact with the plugin:

Commands

Example

To toggle CSV view, use the following command. By default, the delimiter is , for CSV files and \t for TSV files.

:CsvViewToggle

To toggle CSV view with a custom field delimiter, a custom string delimiter and comment, use the following command.

:CsvViewToggle delimiter=, quote_char=' comment=#

Lua API

Highlights

GroupDefaultDescription
CsvViewDelimiterlink to Commentused for ,
CsvViewCommentlink to Commentused for comment

License

This plugin is released under the MIT License