+ csv.vim
This commit is contained in:
parent
0827c421ce
commit
e10d5d74a2
1707
vimfiles/doc/ft-csv.txt
Normal file
1707
vimfiles/doc/ft-csv.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,35 @@
|
|||||||
:Align Align.txt /*:Align*
|
:Align Align.txt /*:Align*
|
||||||
:AlignCtrl Align.txt /*:AlignCtrl*
|
:AlignCtrl Align.txt /*:AlignCtrl*
|
||||||
:AlignMapsClean Align.txt /*:AlignMapsClean*
|
:AlignMapsClean Align.txt /*:AlignMapsClean*
|
||||||
|
:ArrangeColumn ft-csv.txt /*:ArrangeColumn*
|
||||||
|
:CSVAddColumn ft-csv.txt /*:CSVAddColumn*
|
||||||
|
:CSVAnalyze ft-csv.txt /*:CSVAnalyze*
|
||||||
|
:CSVArrangeColumn ft-csv.txt /*:CSVArrangeColumn*
|
||||||
|
:CSVColumn ft-csv.txt /*:CSVColumn*
|
||||||
|
:CSVConvertData ft-csv.txt /*:CSVConvertData*
|
||||||
|
:CSVDeleteColumn ft-csv.txt /*:CSVDeleteColumn*
|
||||||
|
:CSVDuplicate ft-csv.txt /*:CSVDuplicate*
|
||||||
|
:CSVFilter ft-csv.txt /*:CSVFilter*
|
||||||
|
:CSVHeader ft-csv.txt /*:CSVHeader*
|
||||||
|
:CSVHeaderToggle ft-csv.txt /*:CSVHeaderToggle*
|
||||||
|
:CSVHiColumn ft-csv.txt /*:CSVHiColumn*
|
||||||
|
:CSVInitCSV ft-csv.txt /*:CSVInitCSV*
|
||||||
|
:CSVMoveCol ft-csv.txt /*:CSVMoveCol*
|
||||||
|
:CSVNewDelimiter ft-csv.txt /*:CSVNewDelimiter*
|
||||||
|
:CSVNewRecord ft-csv.txt /*:CSVNewRecord*
|
||||||
|
:CSVNrColumns ft-csv.txt /*:CSVNrColumns*
|
||||||
|
:CSVSearchInColumn ft-csv.txt /*:CSVSearchInColumn*
|
||||||
|
:CSVSort ft-csv.txt /*:CSVSort*
|
||||||
|
:CSVSubstitute ft-csv.txt /*:CSVSubstitute*
|
||||||
|
:CSVSumCol ft-csv.txt /*:CSVSumCol*
|
||||||
|
:CSVTable ft-csv.txt /*:CSVTable*
|
||||||
|
:CSVTabularize ft-csv.txt /*:CSVTabularize*
|
||||||
|
:CSVTranspose ft-csv.txt /*:CSVTranspose*
|
||||||
|
:CSVUnArrangeColumn ft-csv.txt /*:CSVUnArrangeColumn*
|
||||||
|
:CSVVHeader ft-csv.txt /*:CSVVHeader*
|
||||||
|
:CSVVHeaderToggle ft-csv.txt /*:CSVVHeaderToggle*
|
||||||
|
:CSVVertFold ft-csv.txt /*:CSVVertFold*
|
||||||
|
:CSVWhatColumn ft-csv.txt /*:CSVWhatColumn*
|
||||||
:CVSEdit vcscommand.txt /*:CVSEdit*
|
:CVSEdit vcscommand.txt /*:CVSEdit*
|
||||||
:CVSEditors vcscommand.txt /*:CVSEditors*
|
:CVSEditors vcscommand.txt /*:CVSEditors*
|
||||||
:CVSUnedit vcscommand.txt /*:CVSUnedit*
|
:CVSUnedit vcscommand.txt /*:CVSUnedit*
|
||||||
@ -13,6 +42,7 @@
|
|||||||
:DirDiff dirdiff.txt /*:DirDiff*
|
:DirDiff dirdiff.txt /*:DirDiff*
|
||||||
:ELP LogiPat.txt /*:ELP*
|
:ELP LogiPat.txt /*:ELP*
|
||||||
:Explore pi_netrw.txt /*:Explore*
|
:Explore pi_netrw.txt /*:Explore*
|
||||||
|
:Filter ft-csv.txt /*:Filter*
|
||||||
:GLVS pi_getscript.txt /*:GLVS*
|
:GLVS pi_getscript.txt /*:GLVS*
|
||||||
:GetLatestVimScripts_dat pi_getscript.txt /*:GetLatestVimScripts_dat*
|
:GetLatestVimScripts_dat pi_getscript.txt /*:GetLatestVimScripts_dat*
|
||||||
:Hexplore pi_netrw.txt /*:Hexplore*
|
:Hexplore pi_netrw.txt /*:Hexplore*
|
||||||
@ -105,9 +135,24 @@
|
|||||||
<Plug>TComment-<c-_>r tcomment.txt /*<Plug>TComment-<c-_>r*
|
<Plug>TComment-<c-_>r tcomment.txt /*<Plug>TComment-<c-_>r*
|
||||||
<Plug>TComment-<c-_>s tcomment.txt /*<Plug>TComment-<c-_>s*
|
<Plug>TComment-<c-_>s tcomment.txt /*<Plug>TComment-<c-_>s*
|
||||||
<Plug>TComment-ic tcomment.txt /*<Plug>TComment-ic*
|
<Plug>TComment-ic tcomment.txt /*<Plug>TComment-ic*
|
||||||
|
AddColumn_CSV ft-csv.txt /*AddColumn_CSV*
|
||||||
Align-copyright Align.txt /*Align-copyright*
|
Align-copyright Align.txt /*Align-copyright*
|
||||||
|
Analyze_CSV ft-csv.txt /*Analyze_CSV*
|
||||||
|
ArrangeColumn_CSV ft-csv.txt /*ArrangeColumn_CSV*
|
||||||
C-Reference crefvim.txt /*C-Reference*
|
C-Reference crefvim.txt /*C-Reference*
|
||||||
|
CSV-Functions ft-csv.txt /*CSV-Functions*
|
||||||
|
CSVCol() ft-csv.txt /*CSVCol()*
|
||||||
|
CSVField() ft-csv.txt /*CSVField()*
|
||||||
|
CSVFixed ft-csv.txt /*CSVFixed*
|
||||||
|
CSVPat() ft-csv.txt /*CSVPat()*
|
||||||
|
CSVSum() ft-csv.txt /*CSVSum()*
|
||||||
|
CSV_WCol() ft-csv.txt /*CSV_WCol()*
|
||||||
|
ConvertData_CSV ft-csv.txt /*ConvertData_CSV*
|
||||||
|
Copy_CSV ft-csv.txt /*Copy_CSV*
|
||||||
|
DeleteColumn_CSV ft-csv.txt /*DeleteColumn_CSV*
|
||||||
DirDiff dirdiff.txt /*DirDiff*
|
DirDiff dirdiff.txt /*DirDiff*
|
||||||
|
Duplicate_CSV ft-csv.txt /*Duplicate_CSV*
|
||||||
|
Filter_CSV ft-csv.txt /*Filter_CSV*
|
||||||
GetLatestVimScripts pi_getscript.txt /*GetLatestVimScripts*
|
GetLatestVimScripts pi_getscript.txt /*GetLatestVimScripts*
|
||||||
GetLatestVimScripts-copyright pi_getscript.txt /*GetLatestVimScripts-copyright*
|
GetLatestVimScripts-copyright pi_getscript.txt /*GetLatestVimScripts-copyright*
|
||||||
GetLatestVimScripts_dat pi_getscript.txt /*GetLatestVimScripts_dat*
|
GetLatestVimScripts_dat pi_getscript.txt /*GetLatestVimScripts_dat*
|
||||||
@ -120,24 +165,38 @@ GundoCredits gundo.txt /*GundoCredits*
|
|||||||
GundoIntro gundo.txt /*GundoIntro*
|
GundoIntro gundo.txt /*GundoIntro*
|
||||||
GundoLicense gundo.txt /*GundoLicense*
|
GundoLicense gundo.txt /*GundoLicense*
|
||||||
GundoUsage gundo.txt /*GundoUsage*
|
GundoUsage gundo.txt /*GundoUsage*
|
||||||
|
HeaderToggle_CSV ft-csv.txt /*HeaderToggle_CSV*
|
||||||
|
Header_CSV ft-csv.txt /*Header_CSV*
|
||||||
|
HiColumn_CSV ft-csv.txt /*HiColumn_CSV*
|
||||||
IDMY visincr.txt /*IDMY*
|
IDMY visincr.txt /*IDMY*
|
||||||
IMDY visincr.txt /*IMDY*
|
IMDY visincr.txt /*IMDY*
|
||||||
IYMD visincr.txt /*IYMD*
|
IYMD visincr.txt /*IYMD*
|
||||||
|
InitCSV ft-csv.txt /*InitCSV*
|
||||||
LogiPat() LogiPat.txt /*LogiPat()*
|
LogiPat() LogiPat.txt /*LogiPat()*
|
||||||
LogiPat-flags LogiPat.txt /*LogiPat-flags*
|
LogiPat-flags LogiPat.txt /*LogiPat-flags*
|
||||||
MatchError matchit.txt /*MatchError*
|
MatchError matchit.txt /*MatchError*
|
||||||
|
MoveCol_CSV ft-csv.txt /*MoveCol_CSV*
|
||||||
MultipleSearch MultipleSearch.txt /*MultipleSearch*
|
MultipleSearch MultipleSearch.txt /*MultipleSearch*
|
||||||
MultipleSearch-commands MultipleSearch.txt /*MultipleSearch-commands*
|
MultipleSearch-commands MultipleSearch.txt /*MultipleSearch-commands*
|
||||||
MultipleSearch-mappings MultipleSearch.txt /*MultipleSearch-mappings*
|
MultipleSearch-mappings MultipleSearch.txt /*MultipleSearch-mappings*
|
||||||
MultipleSearch-settings MultipleSearch.txt /*MultipleSearch-settings*
|
MultipleSearch-settings MultipleSearch.txt /*MultipleSearch-settings*
|
||||||
MultipleSearch.txt MultipleSearch.txt /*MultipleSearch.txt*
|
MultipleSearch.txt MultipleSearch.txt /*MultipleSearch.txt*
|
||||||
NetUserPass() pi_netrw.txt /*NetUserPass()*
|
NetUserPass() pi_netrw.txt /*NetUserPass()*
|
||||||
|
NewDelimiter_CSV ft-csv.txt /*NewDelimiter_CSV*
|
||||||
|
NewRecord_CSV ft-csv.txt /*NewRecord_CSV*
|
||||||
|
NrColumns_CSV ft-csv.txt /*NrColumns_CSV*
|
||||||
SR SrchRplcHiGrp.txt /*SR*
|
SR SrchRplcHiGrp.txt /*SR*
|
||||||
SRChooseHiGrp SrchRplcHiGrp.txt /*SRChooseHiGrp*
|
SRChooseHiGrp SrchRplcHiGrp.txt /*SRChooseHiGrp*
|
||||||
SRDispHiGrp SrchRplcHiGrp.txt /*SRDispHiGrp*
|
SRDispHiGrp SrchRplcHiGrp.txt /*SRDispHiGrp*
|
||||||
SRHiGrp SrchRplcHiGrp.txt /*SRHiGrp*
|
SRHiGrp SrchRplcHiGrp.txt /*SRHiGrp*
|
||||||
SRSearch SrchRplcHiGrp.txt /*SRSearch*
|
SRSearch SrchRplcHiGrp.txt /*SRSearch*
|
||||||
|
SearchInColumn_CSV ft-csv.txt /*SearchInColumn_CSV*
|
||||||
|
Sort_CSV ft-csv.txt /*Sort_CSV*
|
||||||
SrchRplcHiGrp.txt SrchRplcHiGrp.txt /*SrchRplcHiGrp.txt*
|
SrchRplcHiGrp.txt SrchRplcHiGrp.txt /*SrchRplcHiGrp.txt*
|
||||||
|
Substitute_CSV ft-csv.txt /*Substitute_CSV*
|
||||||
|
SumCol_CSV ft-csv.txt /*SumCol_CSV*
|
||||||
|
Transpose_CSV ft-csv.txt /*Transpose_CSV*
|
||||||
|
UnArrangeColumn_CSV ft-csv.txt /*UnArrangeColumn_CSV*
|
||||||
VCSCommandCVSDiffOpt vcscommand.txt /*VCSCommandCVSDiffOpt*
|
VCSCommandCVSDiffOpt vcscommand.txt /*VCSCommandCVSDiffOpt*
|
||||||
VCSCommandCVSExec vcscommand.txt /*VCSCommandCVSExec*
|
VCSCommandCVSExec vcscommand.txt /*VCSCommandCVSExec*
|
||||||
VCSCommandCommitOnWrite vcscommand.txt /*VCSCommandCommitOnWrite*
|
VCSCommandCommitOnWrite vcscommand.txt /*VCSCommandCommitOnWrite*
|
||||||
@ -162,8 +221,12 @@ VCSCommandSVNExec vcscommand.txt /*VCSCommandSVNExec*
|
|||||||
VCSCommandSplit vcscommand.txt /*VCSCommandSplit*
|
VCSCommandSplit vcscommand.txt /*VCSCommandSplit*
|
||||||
VCSCommandVCSTypeOverride vcscommand.txt /*VCSCommandVCSTypeOverride*
|
VCSCommandVCSTypeOverride vcscommand.txt /*VCSCommandVCSTypeOverride*
|
||||||
VCSCommandVCSTypePreference vcscommand.txt /*VCSCommandVCSTypePreference*
|
VCSCommandVCSTypePreference vcscommand.txt /*VCSCommandVCSTypePreference*
|
||||||
|
VHeaderToggle_CSV ft-csv.txt /*VHeaderToggle_CSV*
|
||||||
|
VHeader_CSV ft-csv.txt /*VHeader_CSV*
|
||||||
|
VertFold_CSV ft-csv.txt /*VertFold_CSV*
|
||||||
VimPdb.txt VimPdb.txt /*VimPdb.txt*
|
VimPdb.txt VimPdb.txt /*VimPdb.txt*
|
||||||
Vimball-copyright pi_vimball.txt /*Vimball-copyright*
|
Vimball-copyright pi_vimball.txt /*Vimball-copyright*
|
||||||
|
WhatColumn_CSV ft-csv.txt /*WhatColumn_CSV*
|
||||||
[% matchit.txt /*[%*
|
[% matchit.txt /*[%*
|
||||||
]% matchit.txt /*]%*
|
]% matchit.txt /*]%*
|
||||||
align Align.txt /*align*
|
align Align.txt /*align*
|
||||||
@ -1513,6 +1576,41 @@ crvdoc-licGPL crefvimdoc.txt /*crvdoc-licGPL*
|
|||||||
crvdoc-licLGPL crefvimdoc.txt /*crvdoc-licLGPL*
|
crvdoc-licLGPL crefvimdoc.txt /*crvdoc-licLGPL*
|
||||||
crvdoc-limbugs crefvimdoc.txt /*crvdoc-limbugs*
|
crvdoc-limbugs crefvimdoc.txt /*crvdoc-limbugs*
|
||||||
crvdoc-usage crefvimdoc.txt /*crvdoc-usage*
|
crvdoc-usage crefvimdoc.txt /*crvdoc-usage*
|
||||||
|
csv-aggregate-functions ft-csv.txt /*csv-aggregate-functions*
|
||||||
|
csv-analyze ft-csv.txt /*csv-analyze*
|
||||||
|
csv-arrange-autocmd ft-csv.txt /*csv-arrange-autocmd*
|
||||||
|
csv-calculate-column ft-csv.txt /*csv-calculate-column*
|
||||||
|
csv-changelog ft-csv.txt /*csv-changelog*
|
||||||
|
csv-column ft-csv.txt /*csv-column*
|
||||||
|
csv-commands ft-csv.txt /*csv-commands*
|
||||||
|
csv-comments ft-csv.txt /*csv-comments*
|
||||||
|
csv-conceal ft-csv.txt /*csv-conceal*
|
||||||
|
csv-configuration ft-csv.txt /*csv-configuration*
|
||||||
|
csv-convert ft-csv.txt /*csv-convert*
|
||||||
|
csv-delimiter ft-csv.txt /*csv-delimiter*
|
||||||
|
csv-filter ft-csv.txt /*csv-filter*
|
||||||
|
csv-fixedwidth ft-csv.txt /*csv-fixedwidth*
|
||||||
|
csv-foldtext ft-csv.txt /*csv-foldtext*
|
||||||
|
csv-header ft-csv.txt /*csv-header*
|
||||||
|
csv-hicol ft-csv.txt /*csv-hicol*
|
||||||
|
csv-higroup ft-csv.txt /*csv-higroup*
|
||||||
|
csv-installation ft-csv.txt /*csv-installation*
|
||||||
|
csv-intro ft-csv.txt /*csv-intro*
|
||||||
|
csv-mapping ft-csv.txt /*csv-mapping*
|
||||||
|
csv-mapping-H ft-csv.txt /*csv-mapping-H*
|
||||||
|
csv-move-folds ft-csv.txt /*csv-move-folds*
|
||||||
|
csv-newline ft-csv.txt /*csv-newline*
|
||||||
|
csv-nrformat ft-csv.txt /*csv-nrformat*
|
||||||
|
csv-slow ft-csv.txt /*csv-slow*
|
||||||
|
csv-stl ft-csv.txt /*csv-stl*
|
||||||
|
csv-strict ft-csv.txt /*csv-strict*
|
||||||
|
csv-syntax ft-csv.txt /*csv-syntax*
|
||||||
|
csv-syntax-error ft-csv.txt /*csv-syntax-error*
|
||||||
|
csv-tabularize ft-csv.txt /*csv-tabularize*
|
||||||
|
csv-tips ft-csv.txt /*csv-tips*
|
||||||
|
csv-toc ft-csv.txt /*csv-toc*
|
||||||
|
csv-transpose ft-csv.txt /*csv-transpose*
|
||||||
|
csv-vertfold ft-csv.txt /*csv-vertfold*
|
||||||
cvscommand-changes vcscommand.txt /*cvscommand-changes*
|
cvscommand-changes vcscommand.txt /*cvscommand-changes*
|
||||||
dav pi_netrw.txt /*dav*
|
dav pi_netrw.txt /*dav*
|
||||||
davs pi_netrw.txt /*davs*
|
davs pi_netrw.txt /*davs*
|
||||||
@ -1552,6 +1650,7 @@ ex-visincr-IM visincr.txt /*ex-visincr-IM*
|
|||||||
ex-visincr-IMDY visincr.txt /*ex-visincr-IMDY*
|
ex-visincr-IMDY visincr.txt /*ex-visincr-IMDY*
|
||||||
ex-visincr-IYMD visincr.txt /*ex-visincr-IYMD*
|
ex-visincr-IYMD visincr.txt /*ex-visincr-IYMD*
|
||||||
fetch pi_netrw.txt /*fetch*
|
fetch pi_netrw.txt /*fetch*
|
||||||
|
ft-csv.txt ft-csv.txt /*ft-csv.txt*
|
||||||
ftp pi_netrw.txt /*ftp*
|
ftp pi_netrw.txt /*ftp*
|
||||||
fugitive fugitive.txt /*fugitive*
|
fugitive fugitive.txt /*fugitive*
|
||||||
fugitive#head(...) fugitive.txt /*fugitive#head(...)*
|
fugitive#head(...) fugitive.txt /*fugitive#head(...)*
|
||||||
|
3
vimfiles/ftdetect/csv.vim
Normal file
3
vimfiles/ftdetect/csv.vim
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
" Install Filetype detection for CSV files
|
||||||
|
au BufRead,BufNewFile *.csv,*.dat,*.tsv,*.tab set filetype=csv
|
||||||
|
|
2572
vimfiles/ftplugin/csv.vim
Normal file
2572
vimfiles/ftplugin/csv.vim
Normal file
File diff suppressed because it is too large
Load Diff
86
vimfiles/plugin/csv.vim
Normal file
86
vimfiles/plugin/csv.vim
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
if exists('g:loaded_csv') && g:loaded_csv
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let g:loaded_csv = 1
|
||||||
|
|
||||||
|
let s:cpo_save = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
|
if exists("g:csv_autocmd_arrange")
|
||||||
|
if !exists("*CSVDoBufLoadAutocmd")
|
||||||
|
fu! CSVDoBufLoadAutocmd()
|
||||||
|
" Visually arrange columns when opening a csv file
|
||||||
|
aug CSV_Edit
|
||||||
|
au!
|
||||||
|
au BufReadPost,BufWritePost *.csv,*.dat,*.tsv,*.tab :exe
|
||||||
|
\ printf(":call CSVArrangeCol(1, %d, 0, %d)",
|
||||||
|
\ line('$'), get(g:, 'csv_autocmd_arrange_size', -1))
|
||||||
|
au BufWritePre *.csv,*.dat,*.tsv,*.tab :sil %UnArrangeColumn
|
||||||
|
aug end
|
||||||
|
endfu
|
||||||
|
call CSVDoBufLoadAutocmd()
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
com! -range -bang -nargs=? CSVTable call <sid>Table(<bang>0, <line1>, <line2>, <q-args>)
|
||||||
|
|
||||||
|
fu! <sid>Table(bang, line1, line2, delim)
|
||||||
|
" save and restore some options
|
||||||
|
if has("conceal")
|
||||||
|
let _a = [ &l:lz, &l:syntax, &l:ft, &l:sol, &l:tw, &l:wrap, &l:cole, &l:cocu, &l:fen, &l:fdm, &l:fdl, &l:fdc, &l:fml, &l:fdt, &l:ma, &l:ml]
|
||||||
|
else
|
||||||
|
let _a = [ &l:lz, &l:syntax, &l:ft, &l:sol, &l:tw, &l:wrap, &l:fen, &l:fdm, &l:fdl, &l:fdc, &l:fml, &l:fdt, &l:ma, &l:ml]
|
||||||
|
endif
|
||||||
|
let _b = winsaveview()
|
||||||
|
let line1 = a:line1
|
||||||
|
let line2 = a:line2
|
||||||
|
|
||||||
|
if line1 == line2
|
||||||
|
" use the current paragraph
|
||||||
|
let line1 = line("'{") + 1
|
||||||
|
let line2 = line("'}") - 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !empty(a:delim)
|
||||||
|
let g:csv_delim = (a:delim ==# '\t' ? "\t" : a:delim)
|
||||||
|
endif
|
||||||
|
" try to guess the delimiter from the specified region, therefore, we need
|
||||||
|
" to initialize the plugin to inspect only those lines
|
||||||
|
let [ b:csv_start, b:csv_end ] = [ line1, line2 ]
|
||||||
|
" Reset b:did_ftplugin just to be sure
|
||||||
|
unlet! b:did_ftplugin
|
||||||
|
setl noml ft=csv lz ma
|
||||||
|
" get indent
|
||||||
|
let indent = matchstr(getline(a:line1), '^\s\+')
|
||||||
|
exe printf(':sil %d,%ds/^\s\+//e', line1, line2)
|
||||||
|
let last = line('$')
|
||||||
|
try
|
||||||
|
let b:csv_list=getline(line1, line2)
|
||||||
|
call filter(b:csv_list, '!empty(v:val)')
|
||||||
|
call map(b:csv_list, 'split(v:val, b:col.''\zs'')')
|
||||||
|
if exists(":CSVTabularize")
|
||||||
|
exe printf("%d,%dCSVTabularize%s", line1, line2, empty(a:bang) ? '' : '!')
|
||||||
|
else
|
||||||
|
echoerr "Not possible to call :CSVTabularize"
|
||||||
|
endif
|
||||||
|
unlet! b:col_width b:csv_list
|
||||||
|
catch
|
||||||
|
finally
|
||||||
|
if !empty(indent)
|
||||||
|
" Added one line above a:line1 and several lines below, so need to
|
||||||
|
" correct the range
|
||||||
|
exe printf(':sil %d,%ds/^/%s/e', (line1 - 1), (line2 + line('$') - last), indent)
|
||||||
|
endif
|
||||||
|
if has("conceal")
|
||||||
|
let [ &l:lz, &l:syntax, &l:ft, &l:sol, &l:tw, &l:wrap, &l:cole, &l:cocu, &l:fen, &l:fdm, &l:fdl, &l:fdc, &l:fml, &l:fdt, &l:ma, &l:ml] = _a
|
||||||
|
else
|
||||||
|
let [ &l:lz, &l:syntax, &l:ft, &l:sol, &l:tw, &l:wrap, &l:fen, &l:fdm, &l:fdl, &l:fdc, &l:fml, &l:fdt, &l:ma, &l:ml] = _a
|
||||||
|
endif
|
||||||
|
unlet! g:csv_delim
|
||||||
|
call winrestview(_b)
|
||||||
|
endtry
|
||||||
|
endfu
|
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:cpo_save
|
||||||
|
unlet s:cpo_save
|
158
vimfiles/syntax/csv.vim
Normal file
158
vimfiles/syntax/csv.vim
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
" A simple syntax highlighting, simply alternate colors between two
|
||||||
|
" adjacent columns
|
||||||
|
" Init {{{2
|
||||||
|
let s:cpo_save = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
|
scriptencoding utf8
|
||||||
|
if version < 600
|
||||||
|
syn clear
|
||||||
|
elseif exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Helper functions "{{{2
|
||||||
|
fu! <sid>Warning(msg) "{{{3
|
||||||
|
" Don't redraw, so we are not overwriting messages from the ftplugin
|
||||||
|
" script
|
||||||
|
"redraw!
|
||||||
|
echohl WarningMsg
|
||||||
|
echomsg "CSV Syntax:" . a:msg
|
||||||
|
echohl Normal
|
||||||
|
endfu
|
||||||
|
|
||||||
|
fu! <sid>Esc(val, char) "{{2
|
||||||
|
return '\V'.escape(a:val, '\\'.a:char).'\m'
|
||||||
|
endfu
|
||||||
|
|
||||||
|
fu! <sid>CheckSaneSearchPattern() "{{{3
|
||||||
|
let s:del_def = ','
|
||||||
|
let s:col_def = '\%([^' . s:del_def . ']*' . s:del_def . '\|$\)'
|
||||||
|
let s:col_def_end = '\%([^' . s:del_def . ']*' . s:del_def . '\)'
|
||||||
|
|
||||||
|
" First:
|
||||||
|
" Check for filetype plugin. This syntax script relies on the filetype
|
||||||
|
" plugin, else, it won't work properly.
|
||||||
|
redir => s:a |sil filetype | redir end
|
||||||
|
let s:a=split(s:a, "\n")[0]
|
||||||
|
if match(s:a, '\cplugin:off') > 0
|
||||||
|
call <sid>Warning("No filetype support, only simple highlighting using"
|
||||||
|
\ . s:del_def . " as delimiter! See :h csv-installation")
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Check Comment setting
|
||||||
|
if !exists("g:csv_comment")
|
||||||
|
let b:csv_cmt = split(&cms, '%s')
|
||||||
|
else
|
||||||
|
let b:csv_cmt = split(g:csv_comment, '%s')
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
" Second: Check for sane defaults for the column pattern
|
||||||
|
" Not necessary to check for fixed width columns
|
||||||
|
if exists("b:csv_fixed_width_cols")
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
" Try a simple highlighting, if the defaults from the ftplugin
|
||||||
|
" don't exist
|
||||||
|
let s:col = exists("b:col") && !empty(b:col) ? b:col
|
||||||
|
\ : s:col_def
|
||||||
|
let s:col_end = exists("b:col_end") && !empty(b:col_end) ? b:col_end
|
||||||
|
\ : s:col_def_end
|
||||||
|
let s:del = exists("b:delimiter") && !empty(b:delimiter) ? b:delimiter
|
||||||
|
\ : s:del_def
|
||||||
|
let s:cmts = exists("b:csv_cmt") ? b:csv_cmt[0] : split(&cms, '&s')[0]
|
||||||
|
let s:cmte = exists("b:csv_cmt") && len(b:csv_cmt) == 2 ? b:csv_cmt[1]
|
||||||
|
\ : ''
|
||||||
|
|
||||||
|
if line('$') > 1 && (!exists("b:col") || empty(b:col))
|
||||||
|
" check for invalid pattern, ftplugin hasn't been loaded yet
|
||||||
|
call <sid>Warning("Invalid column pattern, using default pattern " . s:col_def)
|
||||||
|
endif
|
||||||
|
endfu
|
||||||
|
|
||||||
|
" Syntax rules {{{2
|
||||||
|
fu! <sid>DoHighlight() "{{{3
|
||||||
|
if has("conceal") && !exists("g:csv_no_conceal") &&
|
||||||
|
\ !exists("b:csv_fixed_width_cols")
|
||||||
|
" old val
|
||||||
|
"\ '\%(.\)\@=/ms=e,me=e contained conceal cchar=' .
|
||||||
|
" Has a problem with the last line!
|
||||||
|
exe "syn match CSVDelimiter /" . s:col_end .
|
||||||
|
\ '/ms=e,me=e contained conceal cchar=' .
|
||||||
|
\ (&enc == "utf-8" ? "│" : '|')
|
||||||
|
"exe "syn match CSVDelimiterEOL /" . s:del .
|
||||||
|
" \ '\?$/ contained conceal cchar=' .
|
||||||
|
" \ (&enc == "utf-8" ? "│" : '|')
|
||||||
|
hi def link CSVDelimiter Conceal
|
||||||
|
elseif !exists("b:csv_fixed_width_cols")
|
||||||
|
" The \%(.\)\@<= makes sure, the last char won't be concealed,
|
||||||
|
" if it isn't a delimiter
|
||||||
|
"exe "syn match CSVDelimiter /" . s:col . '\%(.\)\@<=/ms=e,me=e contained'
|
||||||
|
exe "syn match CSVDelimiter /" . s:col_end . '/ms=e,me=e contained'
|
||||||
|
"exe "syn match CSVDelimiterEOL /" . s:del . '\?$/ contained'
|
||||||
|
if has("conceal")
|
||||||
|
hi def link CSVDelimiter Conceal
|
||||||
|
else
|
||||||
|
hi def link CSVDelimiter Ignore
|
||||||
|
endif
|
||||||
|
endif " There is no delimiter for csv fixed width columns
|
||||||
|
|
||||||
|
|
||||||
|
if !exists("b:csv_fixed_width_cols")
|
||||||
|
exe 'syn match CSVColumnEven nextgroup=CSVColumnOdd /'
|
||||||
|
\ . s:col . '/ contains=CSVDelimiter'
|
||||||
|
exe 'syn match CSVColumnOdd nextgroup=CSVColumnEven /'
|
||||||
|
\ . s:col . '/ contains=CSVDelimiter'
|
||||||
|
exe 'syn match CSVColumnHeaderEven nextgroup=CSVColumnHeaderOdd /\%<'. (get(b:, 'csv_headerline', 1)+1).'l'
|
||||||
|
\. s:col . '/ contains=CSVDelimiter'
|
||||||
|
exe 'syn match CSVColumnHeaderOdd nextgroup=CSVColumnHeaderEven /\%<'. (get(b:, 'csv_headerline', 1)+1).'l'
|
||||||
|
\. s:col . '/ contains=CSVDelimiter'
|
||||||
|
else
|
||||||
|
for i in range(len(b:csv_fixed_width_cols))
|
||||||
|
let pat = '/\%' . b:csv_fixed_width_cols[i] . 'v.*' .
|
||||||
|
\ ((i == len(b:csv_fixed_width_cols)-1) ? '/' :
|
||||||
|
\ '\%' . b:csv_fixed_width_cols[i+1] . 'v/')
|
||||||
|
|
||||||
|
let group = "CSVColumn" . (i%2 ? "Odd" : "Even" )
|
||||||
|
let ngroup = "CSVColumn" . (i%2 ? "Even" : "Odd" )
|
||||||
|
exe "syn match " group pat " nextgroup=" . ngroup
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
" Comment regions
|
||||||
|
exe 'syn match CSVComment /'. <sid>Esc(s:cmts, '/'). '.*'.
|
||||||
|
\ (!empty(s:cmte) ? '\%('. <sid>Esc(s:cmte, '/'). '\)\?'
|
||||||
|
\: ''). '/'
|
||||||
|
hi def link CSVComment Comment
|
||||||
|
endfun
|
||||||
|
|
||||||
|
fu! <sid>DoSyntaxDefinitions() "{{{3
|
||||||
|
syn spell toplevel
|
||||||
|
|
||||||
|
" Not really needed
|
||||||
|
syn case ignore
|
||||||
|
|
||||||
|
hi def link CSVColumnHeaderOdd WarningMsg
|
||||||
|
hi def link CSVColumnHeaderEven WarningMsg
|
||||||
|
hi def link CSVColumnOdd DiffAdd
|
||||||
|
hi def link CSVColumnEven DiffChange
|
||||||
|
endfun
|
||||||
|
|
||||||
|
" Main: {{{2
|
||||||
|
" Make sure, we are using a sane, valid pattern for syntax
|
||||||
|
" highlighting
|
||||||
|
call <sid>CheckSaneSearchPattern()
|
||||||
|
|
||||||
|
" Define all necessary syntax groups
|
||||||
|
call <sid>DoSyntaxDefinitions()
|
||||||
|
|
||||||
|
" Highlight the file
|
||||||
|
call <sid>DoHighlight()
|
||||||
|
|
||||||
|
" Set the syntax variable {{{2
|
||||||
|
let b:current_syntax="csv"
|
||||||
|
|
||||||
|
let &cpo = s:cpo_save
|
||||||
|
unlet s:cpo_save
|
Loading…
x
Reference in New Issue
Block a user