A guide to features and configuration options.
- Display Configuration
- Delimiter Configuration & Auto-Detection
- Header Configuration & Sticky Headers
- Navigation & Text Objects
- Quote Character Configuration
- Multi-line Field Configuration
- Comment Line Handling
- Buffer Statistics
- API Reference
csvview.nvim supports two display modes for better visualization of your CSV data.
Highlights delimiter characters in place, maintaining the original file structure:
{
view = {
display_mode = "highlight",
},
}Replaces delimiters with vertical borders (│) for a cleaner table appearance:
{
view = {
display_mode = "border",
},
}Switch between display modes on the fly:
:CsvViewEnable display_mode=highlight
:CsvViewEnable display_mode=borderCustomize the appearance of your table columns:
{
view = {
min_column_width = 5, -- Minimum width for each column
spacing = 2, -- Space between columns
},
}csvview.nvim provides intelligent delimiter detection and flexible configuration options.
The plugin automatically detects the most appropriate delimiter by analyzing your file content:
-- Default configuration with auto-detection
{
parser = {
delimiter = {
ft = {
csv = ",", -- Always use comma for .csv files
tsv = "\t", -- Always use tab for .tsv files
},
fallbacks = { -- Try these delimiters in order for other files
",", -- Comma (most common)
"\t", -- Tab
";", -- Semicolon
"|", -- Pipe
":", -- Colon
" ", -- Space
},
},
},
}- If the file type matches
ftrules (e.g.,.csv→ comma), use that delimiter - Otherwise, test each delimiter in
fallbacksorder - Score each delimiter based on field consistency across lines
- Select the delimiter with the highest score
{
parser = {
delimiter = ",", -- Always use comma
},
}{
parser = {
delimiter = function(bufnr)
local filename = vim.api.nvim_buf_get_name(bufnr)
if filename:match("%.tsv$") then
return "\t"
end
return ","
end,
},
}" For unknown file formats, let auto-detection work
:CsvViewEnable
" Specific delimiters
:CsvViewEnable delimiter=,
:CsvViewEnable delimiter=\t
" Special characters (use escape sequences)
:CsvViewEnable delimiter=\ " Space
:CsvViewEnable delimiter=\t " TabNote: Multi-character delimiters are supported (e.g., ||, ::, <>), but regular expression patterns are not supported (e.g., \s+).
Keep header rows visible while scrolling through large CSV files with intelligent header detection.
The plugin automatically detects header rows by analyzing file content:
-- Default configuration with auto-detection
{
view = {
header_lnum = true, -- Auto-detect header (default)
sticky_header = {
enabled = true,
separator = "─", -- Separator line character
},
},
}- Find the first non-comment line as header candidate
- Analyze each column independently using two heuristics:
- Type Mismatch: If the first row contains text while data rows are numeric, it's likely a header
- Length Deviation: If the first row's text length differs significantly from data rows, it's likely a header
- Combine evidence from all columns to make the final decision
{
view = {
header_lnum = 1, -- Use line 1 as header
-- header_lnum = 3, -- Use line 3 as header
},
}{
view = {
header_lnum = false, -- No header line
},
}:CsvViewEnable header_lnum=auto " Auto-detect header (default)
:CsvViewEnable header_lnum=1 " First line as header
:CsvViewEnable header_lnum=none " No header line{
view = {
sticky_header = {
separator = "═", -- Double line
-- separator = false, -- No separator
},
},
}Navigate between fields and rows with familiar keyboard shortcuts:
{
keymaps = {
-- Horizontal navigation
jump_next_field_end = { "<Tab>", mode = { "n", "v" } },
jump_prev_field_end = { "<S-Tab>", mode = { "n", "v" } },
-- Vertical navigation
jump_next_row = { "<Enter>", mode = { "n", "v" } },
jump_prev_row = { "<S-Enter>", mode = { "n", "v" } },
},
}{
keymaps = {
-- Select field content (inner)
textobject_field_inner = { "if", mode = { "o", "x" } },
-- Select field including delimiter (outer)
textobject_field_outer = { "af", mode = { "o", "x" } },
},
}vif- Select current field contentvaf- Select current field including delimiterdif- Delete field contentcaf- Change entire field
-- Jump to specific field position
require("csvview.jump").field(0, {
pos = { 2, 3 }, -- Row 2, Column 3
mode = "absolute",
anchor = "start", -- Place cursor at field start
})Handle quoted fields that contain delimiters or special characters.
{
parser = {
quote_char = '"', -- Standard double quotes (default)
-- quote_char = "'", -- Single quotes
},
}When a field is enclosed in quote characters, the delimiter inside is ignored:
name,description,value
John,"Smith, Jr.",100
Jane,"O'Connor ""Jane""",200In this example:
"Smith, Jr."contains a comma but is treated as one field"O'Connor ""Jane"""contains escaped quotes within the field
" Use double quotes (default)
:CsvViewEnable quote_char="
" Use single quotes
:CsvViewEnable quote_char='
" Disable quote handling (not recommended)
:CsvViewEnable quote_char=Handle CSV fields that span multiple lines when properly quoted.
{
parser = {
max_lookahead = 50, -- Maximum lines to search for closing quotes
},
}When a field starts with a quote character but doesn't end on the same line, the parser will search ahead for the closing quote:
id,description,notes
1,"This field contains
multiple lines of text
with embedded newlines",Short note
2,"Another multi-line field
that spans several lines",Another noteAdjust max_lookahead based on your data:
- Increase for files with long multi-line fields (e.g.,
max_lookahead = 200) - Decrease for simple CSV files to improve performance (e.g.,
max_lookahead = 10)
Skip comment lines from the table display to focus on data rows.
{
parser = {
comments = { "#", "//", "--" }, -- Lines starting with these are ignored
},
}# This is a comment line
// Another comment style
-- SQL-style comment
name,age,city
John,25,NYC
# Comments can appear anywhere
Jane,30,LAOnly the data rows (name,age,city, John,25,NYC, Jane,30,LA) will be displayed in the table format.
For files with a fixed number of metadata lines at the top, use comment_lines:
{
parser = {
comment_lines = 2, -- First 2 lines are always treated as comments
},
}This is useful for files like:
Generated: 2024-01-15
Source: database_export
name,age,city
John,25,NYC
Jane,30,LAThe first 2 lines will be treated as comments regardless of their content.
" Enable hash comments
:CsvViewEnable comment=#
" Enable C++ style comments
:CsvViewEnable comment=//
" Enable SQL style comments
:CsvViewEnable comment=--
" Treat first N lines as comments
:CsvViewEnable comment_lines=2
" Multiple comment types (requires Lua configuration)Display detailed information about the current CSV buffer using the :CsvViewInfo command.
" Show buffer statistics
:CsvViewInfo
" Show with debug information
:CsvViewInfo!Press q or <Esc> to close the info window.
local csvview = require('csvview')
-- Buffer management
csvview.enable(bufnr?, opts?) -- Enable for specific buffer
csvview.disable(bufnr?) -- Disable for specific buffer
csvview.toggle(bufnr?, opts?) -- Toggle with options
csvview.is_enabled(bufnr?) -- Check status
-- Buffer information
csvview.info(bufnr?, show_debug?) -- Show buffer statisticslocal jump = require("csvview.jump")
-- Precise field navigation
jump.field(bufnr, {
pos = { row, col }, -- Target position (1-based)
mode = "absolute", -- "absolute" or "relative"
anchor = "start", -- "start" or "end"
col_wrap = true, -- Wrap at row boundaries
})
-- Convenience functions
jump.next_field_start(bufnr?) -- Like 'w' motion
jump.prev_field_start(bufnr?) -- Like 'b' motion
jump.next_field_end(bufnr?) -- Like 'e' motion
jump.prev_field_end(bufnr?) -- Like 'ge' motionlocal textobj = require("csvview.textobject")
-- Select current field
textobj.field(bufnr, {
include_delimiter = false, -- Include surrounding delimiter
})local util = require("csvview.util")
-- Get detailed cursor information
local info = util.get_cursor(bufnr)
-- Returns:
-- {
-- kind = "field" | "comment" | "empty_line",
-- pos = { row, col }, -- 1-based CSV coordinates
-- anchor = "start" | "end" | "inside" | "delimiter",
-- text = "field content"
-- }