mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Fixed #38
Added a mapping `<Plug>(table-mode-sort)` which is mapped by default to `<Leader>ts` that sorts the current table by the column in which the cursor is currently. Also added `TableSort` command that gives you a little more control over the sorting, you can pass in additional :sort flags like u, i, n etc and also use it with a `!` to sort in reverse order.
This commit is contained in:
@@ -43,6 +43,7 @@ function! s:ToggleMapping() "{{{2
|
|||||||
call s:Map('<Plug>(table-mode-add-formula)', '<Leader>tfa', 'n')
|
call s:Map('<Plug>(table-mode-add-formula)', '<Leader>tfa', 'n')
|
||||||
call s:Map('<Plug>(table-mode-eval-formula)', '<Leader>tfe', 'n')
|
call s:Map('<Plug>(table-mode-eval-formula)', '<Leader>tfe', 'n')
|
||||||
call s:Map('<Plug>(table-mode-echo-cell)', '<Leader>t?', 'n')
|
call s:Map('<Plug>(table-mode-echo-cell)', '<Leader>t?', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-sort)', '<Leader>ts', 'n')
|
||||||
else
|
else
|
||||||
call s:UnMap(separator_map, 'i')
|
call s:UnMap(separator_map, 'i')
|
||||||
call s:UnMap('{<Bar>', 'n')
|
call s:UnMap('{<Bar>', 'n')
|
||||||
@@ -56,6 +57,7 @@ function! s:ToggleMapping() "{{{2
|
|||||||
call s:UnMap('<Leader>tfa', 'n')
|
call s:UnMap('<Leader>tfa', 'n')
|
||||||
call s:UnMap('<Leader>tfe', 'n')
|
call s:UnMap('<Leader>tfe', 'n')
|
||||||
call s:UnMap('<Leader>t?', 'n')
|
call s:UnMap('<Leader>t?', 'n')
|
||||||
|
call s:UnMap('<Leader>ts', 'n')
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -179,3 +179,11 @@ function! tablemode#spreadsheet#Average(range, ...) abort "{{{2
|
|||||||
call insert(args, a:range)
|
call insert(args, a:range)
|
||||||
return s:Average(call('tablemode#spreadsheet#cell#GetCellRange', args))
|
return s:Average(call('tablemode#spreadsheet#cell#GetCellRange', args))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! tablemode#spreadsheet#Sort(bang, ...) "{{{2
|
||||||
|
let opts = a:0 ? a:1 : ''
|
||||||
|
let bang = a:bang ? '!' : ''
|
||||||
|
let [firstRow, lastRow] = [tablemode#spreadsheet#GetFirstRow('.'), tablemode#spreadsheet#GetLastRow('.')]
|
||||||
|
call tablemode#spreadsheet#MoveToStartOfCell()
|
||||||
|
exec ':'.firstRow.','.lastRow . 'sort'.bang opts '/.*\%'.col('.').'v/'
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ endif
|
|||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
command! -nargs=? -range Tableize <line1>,<line2>call tablemode#TableizeRange(<q-args>)
|
command! -nargs=? -range Tableize <line1>,<line2>call tablemode#TableizeRange(<q-args>)
|
||||||
|
command! -nargs=? -bang TableSort call tablemode#spreadsheet#Sort(<bang>0, <q-args>)
|
||||||
command! TableAddFormula call tablemode#spreadsheet#formula#Add()
|
command! TableAddFormula call tablemode#spreadsheet#formula#Add()
|
||||||
command! TableModeRealign call tablemode#table#Realign('.')
|
command! TableModeRealign call tablemode#table#Realign('.')
|
||||||
command! TableEvalFormulaLine call tablemode#spreadsheet#formula#EvaluateFormulaLine()
|
command! TableEvalFormulaLine call tablemode#spreadsheet#formula#EvaluateFormulaLine()
|
||||||
@@ -89,6 +90,8 @@ nnoremap <silent> <Plug>(table-mode-eval-formula) :call tablemode#spreadsheet#fo
|
|||||||
|
|
||||||
nnoremap <silent> <Plug>(table-mode-echo-cell) :call <SID>TableEchoCell()<CR>
|
nnoremap <silent> <Plug>(table-mode-echo-cell) :call <SID>TableEchoCell()<CR>
|
||||||
|
|
||||||
|
nnoremap <silent> <Plug>(table-mode-sort) :call tablemode#spreadsheet#Sort()<CR>
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-tableize)')
|
if !hasmapto('<Plug>(table-mode-tableize)')
|
||||||
nmap <Leader>tt <Plug>(table-mode-tableize)
|
nmap <Leader>tt <Plug>(table-mode-tableize)
|
||||||
xmap <Leader>tt <Plug>(table-mode-tableize)
|
xmap <Leader>tt <Plug>(table-mode-tableize)
|
||||||
|
|||||||
Reference in New Issue
Block a user