summaryrefslogtreecommitdiffstats
path: root/ftplugin/csv.vim
diff options
context:
space:
mode:
Diffstat (limited to 'ftplugin/csv.vim')
-rw-r--r--ftplugin/csv.vim23
1 files changed, 21 insertions, 2 deletions
diff --git a/ftplugin/csv.vim b/ftplugin/csv.vim
index 9d8df120..19f649cc 100644
--- a/ftplugin/csv.vim
+++ b/ftplugin/csv.vim
@@ -517,7 +517,13 @@ fu! <sid>WColumn(...) "{{{3
" Return on which column the cursor is
let _cur = getpos('.')
if !exists("b:csv_fixed_width_cols")
- let line=getline('.')
+ if line('.') > 1 && mode('') != 'n'
+ " in insert mode, get line from above, just in case the current
+ " line is empty
+ let line = getline(line('.')-1)
+ else
+ let line=getline('.')
+ endif
" move cursor to end of field
"call search(b:col, 'ec', line('.'))
call search(b:col, 'ec')
@@ -2398,6 +2404,9 @@ fu! csv#EvalColumn(nr, func, first, last) range "{{{3
call <sid>CheckHeaderLine()
let nr = matchstr(a:nr, '^\-\?\d\+')
let col = (empty(nr) ? <sid>WColumn() : nr)
+ if col == 0
+ let col = 1
+ endif
" don't take the header line into consideration
let start = a:first - 1 + s:csv_fold_headerline
let stop = a:last - 1 + s:csv_fold_headerline
@@ -2516,8 +2525,18 @@ fu! CSV_CloseBuffer(buffer) "{{{3
augroup! CSV_QuitPre
endtry
endfu
-
+fu! CSVSum(col, fmt, first, last) "{{{3
+ let first = a:first
+ let last = a:last
+ if empty(first)
+ let first = 1
+ endif
+ if empty(last)
+ let last = line('$')
+ endif
+ return csv#EvalColumn(a:col, '<sid>SumColumn', first, last)
+endfu
" Initialize Plugin "{{{2
let b:csv_start = exists("b:csv_start") ? b:csv_start : 1
let b:csv_end = exists("b:csv_end") ? b:csv_end : line('$')