From b7d2fdea3d1775cd6d1adf420f6802cffc2ade1a Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 11 Dec 2025 18:09:54 +0100 Subject: [PATCH] nvim: Add csvview for tablelike csv files Gives a very nice viewing and editing experience for csv files. Not sure what the performance impact is for bigger files, but certainly is worth it for the smaller ones. Automatically switches on the view for `.csv` and `.tsv` files. Additionally, adds some keymaps whenever a csv-like file is loaded (i.e. when the `CsvViewEnable` mode is on): and to traverse up and down rows, and to traverse columns left and right. Adds a 'field' textobject (`if` and `af`), though only a single field can currently be changed at once. --- nvim/.config/nvim/after/ftplugin/csv.lua | 4 ++++ nvim/.config/nvim/after/ftplugin/tsv.lua | 4 ++++ nvim/.config/nvim/lazy-lock.json | 1 + .../nvim/lua/modules/data_analysis.lua | 20 +++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 nvim/.config/nvim/after/ftplugin/csv.lua create mode 100644 nvim/.config/nvim/after/ftplugin/tsv.lua diff --git a/nvim/.config/nvim/after/ftplugin/csv.lua b/nvim/.config/nvim/after/ftplugin/csv.lua new file mode 100644 index 0000000..80ea44c --- /dev/null +++ b/nvim/.config/nvim/after/ftplugin/csv.lua @@ -0,0 +1,4 @@ +-- turn on a nice table view if we have it +if require("core.util").is_available("csvview") then + require("csvview").enable() +end diff --git a/nvim/.config/nvim/after/ftplugin/tsv.lua b/nvim/.config/nvim/after/ftplugin/tsv.lua new file mode 100644 index 0000000..80ea44c --- /dev/null +++ b/nvim/.config/nvim/after/ftplugin/tsv.lua @@ -0,0 +1,4 @@ +-- turn on a nice table view if we have it +if require("core.util").is_available("csvview") then + require("csvview").enable() +end diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 588fa04..ec5a304 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -16,6 +16,7 @@ "conform.nvim": { "branch": "master", "commit": "a6f5bdb78caa305496357d17e962bbc4c0b392e2" }, "copilot-lualine": { "branch": "main", "commit": "6bc29ba1fcf8f0f9ba1f0eacec2f178d9be49333" }, "copilot.lua": { "branch": "master", "commit": "c1bb86abbed1a52a11ab3944ef00c8410520543d" }, + "csvview.nvim": { "branch": "main", "commit": "a4c45eadb03a462a80dd1a545d0f9cb636b73664" }, "dial.nvim": { "branch": "master", "commit": "2c7e2750372918f072a20f3cf754d845e143d7c9" }, "dressing.nvim": { "branch": "master", "commit": "3a45525bb182730fe462325c99395529308f431e" }, "fidget.nvim": { "branch": "main", "commit": "b61e8af9b8b68ee0ec7da5fb7a8c203aae854f2e" }, diff --git a/nvim/.config/nvim/lua/modules/data_analysis.lua b/nvim/.config/nvim/lua/modules/data_analysis.lua index 008218c..0050da3 100644 --- a/nvim/.config/nvim/lua/modules/data_analysis.lua +++ b/nvim/.config/nvim/lua/modules/data_analysis.lua @@ -1,4 +1,24 @@ return { + { + -- pretty table-view and movement for CSV-like files + "hat0uma/csvview.nvim", + opts = { + view = { + display_mode = "border", + spacing = 1, + }, + keymaps = { + jump_next_field_end = { "", mode = { "n", "v" } }, + jump_prev_field_end = { "", mode = { "n", "v" } }, + jump_next_row = { "", mode = { "n", "v" } }, + jump_prev_row = { "", mode = { "n", "v" } }, + textobject_field_inner = { "if", mode = { "o", "x" } }, + textobject_field_outer = { "af", mode = { "o", "x" } }, + }, + }, + cmd = { "CsvViewEnable", "CsvViewDisable", "CsvViewToggle" }, + ft = { "csv", "tsv", "dsv", "psv", "ssv", "scsv" }, + }, { "jmbuhr/otter.nvim", config = function()