chrisbra / csv.vim

A Filetype plugin for csv files
http://www.vim.org/scripts/script.php?script_id=2830
Vim License
1.27k stars 62 forks source link

Setting tab as delimiter based on .tsv extension #214

Closed bpj closed 1 year ago

bpj commented 1 year ago

Is it possible to have the delimiter automatically set to "\t" when the file extension is .tsv?

I'm (of course) asking because I have some TSV files where the values contain commas, and the plugin is guessing wrong about the delimiter.

I suppose that it could be done via an autocommand, but it is not clear to me how, so any help would be appreciated! This said it would be great if the plugin could do this based on a .tsv file extension.

chrisbra commented 1 year ago

Hm, how about:

diff --git a/ftdetect/csv.vim b/ftdetect/csv.vim
index 4a8b0cc..7adacb8 100644
--- a/ftdetect/csv.vim
+++ b/ftdetect/csv.vim
@@ -1,3 +1,4 @@
 " Install Filetype detection for CSV files
-au BufRead,BufNewFile *.csv,*.dat,*.tsv,*.tab set filetype=csv
+au BufRead,BufNewFile *.tsv,*.tab let b:delimiter="\t" | set filetype=csv
+au BufRead,BufNewFile *.csv,*.dat set filetype=csv