mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
* Removed table border and related options. You can now optionally have a header instead, simply add a table header and add a border to it triggered by the vim iabbrev '+-' on the line immidiately after the header and it will expand to the correct border. It will auto update as the table realigns with changes. Similar approach as followed by tables in org-mode. * Fixed bug of incorrect indentation of a newly added formula line. * Fixed bug in ConvertDelimiterToSeparator causing incorrect tableization of commented blocks of delimited content.
111 lines
4.8 KiB
VimL
111 lines
4.8 KiB
VimL
" =============================================================================
|
|
" File: plugin/table-mode.vim
|
|
" Description: Table mode for vim for creating neat tables.
|
|
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
|
" License: MIT (http://www.opensource.org/licenses/MIT)
|
|
" Website: http://github.com/dhruvasagar/vim-table-mode
|
|
" Version: 3.1
|
|
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
|
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
|
" uses a small amount of code from it.
|
|
"
|
|
" Copyright Notice:
|
|
" Permission is hereby granted to use and distribute this code,
|
|
" with or without modifications, provided that this copyright
|
|
" notice is copied with it. Like anything else that's free,
|
|
" table-mode.vim is provided *as is* and comes with no warranty
|
|
" of any kind, either expressed or implied. In no event will
|
|
" the copyright holder be liable for any damamges resulting
|
|
" from the use of this software.
|
|
" =============================================================================
|
|
|
|
" Finish if already loaded {{{1
|
|
if exists('g:loaded_table_mode')
|
|
finish
|
|
endif
|
|
let g:loaded_table_mode = 1
|
|
|
|
" Avoiding side effects {{{1
|
|
let s:save_cpo = &cpo
|
|
set cpo&vim
|
|
|
|
function! s:SetGlobalOptDefault(opt, val) "{{{1
|
|
if !exists('g:' . a:opt)
|
|
let g:{a:opt} = a:val
|
|
endif
|
|
endfunction
|
|
|
|
" Set Global Defaults {{{1
|
|
call s:SetGlobalOptDefault('table_mode_corner', '+')
|
|
call s:SetGlobalOptDefault('table_mode_separator', '|')
|
|
call s:SetGlobalOptDefault('table_mode_fillchar', '-')
|
|
call s:SetGlobalOptDefault('table_mode_map_prefix', '<Leader>t')
|
|
call s:SetGlobalOptDefault('table_mode_toggle_map', 'm')
|
|
call s:SetGlobalOptDefault('table_mode_always_active', 0)
|
|
call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
|
call s:SetGlobalOptDefault('table_mode_tableize_map', 't')
|
|
call s:SetGlobalOptDefault('table_mode_tableize_op_map', '<Leader>T')
|
|
call s:SetGlobalOptDefault('table_mode_realign_map', 'r')
|
|
call s:SetGlobalOptDefault('table_mode_cell_text_object', 'tc')
|
|
call s:SetGlobalOptDefault('table_mode_delete_row_map', 'dd')
|
|
call s:SetGlobalOptDefault('table_mode_delete_column_map', 'dc')
|
|
call s:SetGlobalOptDefault('table_mode_add_formula_map', 'fa')
|
|
call s:SetGlobalOptDefault('table_mode_eval_expr_map', 'fe')
|
|
|
|
function! s:TableMotion() "{{{1
|
|
let direction = nr2char(getchar())
|
|
for i in range(v:count1)
|
|
call tablemode#TableMotion(direction)
|
|
endfor
|
|
endfunction
|
|
|
|
" Define Commands & Mappings {{{1
|
|
if !g:table_mode_always_active "{{{2
|
|
exec "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_toggle_map .
|
|
\ " <Esc>:call tablemode#TableModeToggle()<CR>"
|
|
command! -nargs=0 TableModeToggle call tablemode#TableModeToggle()
|
|
command! -nargs=0 TableModeEnable call tablemode#TableModeEnable()
|
|
command! -nargs=0 TableModeDisable call tablemode#TableModeDisable()
|
|
else
|
|
let table_mode_separator_map = g:table_mode_separator
|
|
" '|' is a special character, we need to map <Bar> instead
|
|
if g:table_mode_separator ==# '|' | let table_mode_separator_map = '<Bar>' | endif
|
|
|
|
execute "inoremap <silent> " . table_mode_separator_map . ' ' .
|
|
\ table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
|
unlet table_mode_separator_map
|
|
endif
|
|
" }}}2
|
|
|
|
command! -nargs=? -range Tableize <line1>,<line2>call tablemode#TableizeRange(<q-args>)
|
|
|
|
command! TableAddFormula call tablemode#AddFormula()
|
|
command! TableEvalFormulaLine call tablemode#EvaluateFormulaLine()
|
|
|
|
execute "xnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_tableize_map .
|
|
\ " :Tableize<CR>"
|
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_tableize_map .
|
|
\ " :Tableize<CR>"
|
|
execute "xnoremap <silent> " . g:table_mode_tableize_op_map .
|
|
\ " :<C-U>call tablemode#TableizeByDelimiter()<CR>"
|
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_realign_map .
|
|
\ " :call tablemode#TableRealign('.')<CR>"
|
|
execute "nnoremap <silent> " . g:table_mode_map_prefix .
|
|
\ " :call <SID>TableMotion()<CR>"
|
|
execute "onoremap <silent> " . g:table_mode_cell_text_object .
|
|
\ " :<C-U>call tablemode#CellTextObject()<CR>"
|
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_delete_row_map .
|
|
\ " :call tablemode#DeleteRow()<CR>"
|
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_delete_column_map .
|
|
\ " :call tablemode#DeleteColumn()<CR>"
|
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_add_formula_map .
|
|
\ " :TableAddFormula<CR>"
|
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_eval_expr_map .
|
|
\ " :TableEvalFormulaLine<CR>"
|
|
|
|
" Avoiding side effects {{{1
|
|
let &cpo = s:save_cpo
|
|
|
|
" ModeLine {{{
|
|
" vim: sw=2 sts=2 fdl=0 fdm=marker
|