mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 19:13:46 -05:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e997144d2f | ||
|
|
554c57703f | ||
|
|
60ab92cd35 | ||
|
|
503271fca5 | ||
|
|
b789e2c86f | ||
|
|
7b89b6b50d | ||
|
|
28dc1626ab | ||
|
|
da871cac51 |
@@ -4,6 +4,13 @@ An awesome automatic table creator & formatter allowing one to create neat
|
|||||||
tables as you type.
|
tables as you type.
|
||||||
|
|
||||||
## Change Log
|
## Change Log
|
||||||
|
### Version 2.1.3 :
|
||||||
|
* Bug Fix #1, added new option `g:table_mode_no_border_padding` which removes
|
||||||
|
padding from the border.
|
||||||
|
|
||||||
|
### Version 2.1.2 :
|
||||||
|
* Bug Fixes #2, #3 & #4
|
||||||
|
|
||||||
### Version 2.1.1 :
|
### Version 2.1.1 :
|
||||||
* Added option g:table_mode_align to allow setting Tabular format option for
|
* Added option g:table_mode_align to allow setting Tabular format option for
|
||||||
more control on how Tabular aligns text.
|
more control on how Tabular aligns text.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||||
" License: MIT (http://www.opensource.org/licenses/MIT)
|
" License: MIT (http://www.opensource.org/licenses/MIT)
|
||||||
" Website: http://github.com/dhruvasagar/vim-table-mode
|
" Website: http://github.com/dhruvasagar/vim-table-mode
|
||||||
" Version: 2.1.1
|
" Version: 2.1.3
|
||||||
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
||||||
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
||||||
" uses a small amount of code from it.
|
" uses a small amount of code from it.
|
||||||
@@ -45,11 +45,12 @@ call s:SetGlobalOptDefault('table_mode_border', 1)
|
|||||||
call s:SetGlobalOptDefault('table_mode_corner', '+')
|
call s:SetGlobalOptDefault('table_mode_corner', '+')
|
||||||
call s:SetGlobalOptDefault('table_mode_separator', '|')
|
call s:SetGlobalOptDefault('table_mode_separator', '|')
|
||||||
call s:SetGlobalOptDefault('table_mode_fillchar', '-')
|
call s:SetGlobalOptDefault('table_mode_fillchar', '-')
|
||||||
call s:SetGlobalOptDefault('table_mode_toggle_map', '<Leader>tm')
|
call s:SetGlobalOptDefault('table_mode_toggle_map', '<LocalLeader>tm')
|
||||||
call s:SetGlobalOptDefault('table_mode_always_active', 0)
|
call s:SetGlobalOptDefault('table_mode_always_active', 0)
|
||||||
call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
||||||
call s:SetGlobalOptDefault('table_mode_tableize_map', '<Leader>T')
|
call s:SetGlobalOptDefault('table_mode_tableize_map', '<Leader>T')
|
||||||
call s:SetGlobalOptDefault('table_mode_align', 'l1')
|
call s:SetGlobalOptDefault('table_mode_align', 'l1')
|
||||||
|
call s:SetGlobalOptDefault('table_mode_no_border_padding', '0')
|
||||||
"}}}1
|
"}}}1
|
||||||
|
|
||||||
" Define Commands & Mappings {{{1
|
" Define Commands & Mappings {{{1
|
||||||
@@ -59,12 +60,20 @@ if !g:table_mode_always_active
|
|||||||
command! -nargs=0 TableModeToggle call tablemode#TableModeToggle()
|
command! -nargs=0 TableModeToggle call tablemode#TableModeToggle()
|
||||||
command! -nargs=0 TableModeEnable call tablemode#TableModeEnable()
|
command! -nargs=0 TableModeEnable call tablemode#TableModeEnable()
|
||||||
command! -nargs=0 TableModeDisable call tablemode#TableModeDisable()
|
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
|
endif
|
||||||
|
|
||||||
command! -nargs=0 -range Tableize <line1>,<line2>call tablemode#TableizeRange()
|
command! -nargs=0 -range Tableize <line1>,<line2>call tablemode#TableizeRange()
|
||||||
exec "xnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
execute "xnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
||||||
exec "nnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
execute "nnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
||||||
"}}}1
|
"}}}1
|
||||||
|
|
||||||
" ModeLine {{{
|
" ModeLine {{{
|
||||||
" vim:fdm=marker
|
" vim:fdl=0 fdm=marker
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||||
" License: MIT (http://www.opensource.org/licenses/MIT)
|
" License: MIT (http://www.opensource.org/licenses/MIT)
|
||||||
" Website: http://github.com/dhruvasagar/vim-table-mode
|
" Website: http://github.com/dhruvasagar/vim-table-mode
|
||||||
" Version: 2.1.1
|
" Version: 2.1.3
|
||||||
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
||||||
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
||||||
" uses a small amount of code from it.
|
" uses a small amount of code from it.
|
||||||
@@ -40,12 +40,6 @@ function! s:CountSeparator(line, separator) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:ConvertDelimiterToSeparator(line) "{{{2
|
|
||||||
execute 'silent! ' . a:line . 's/^\s*\zs\ze.\|' . g:table_mode_delimiter .
|
|
||||||
\ '\|$/' . g:table_mode_separator . '/g'
|
|
||||||
endfunction
|
|
||||||
" }}}2
|
|
||||||
|
|
||||||
function! s:IsTableModeActive() "{{{2
|
function! s:IsTableModeActive() "{{{2
|
||||||
if g:table_mode_always_active | return 1 | endif
|
if g:table_mode_always_active | return 1 | endif
|
||||||
|
|
||||||
@@ -54,21 +48,16 @@ function! s:IsTableModeActive() "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:TableModeSeparatorMap() "{{{2
|
|
||||||
if g:table_mode_separator ==# '|'
|
|
||||||
return '<Bar>'
|
|
||||||
else
|
|
||||||
return g:table_mode_separator
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
" }}}2
|
|
||||||
|
|
||||||
function! s:ToggleMapping() "{{{2
|
function! s:ToggleMapping() "{{{2
|
||||||
if exists('b:table_mode_active') && b:table_mode_active
|
if exists('b:table_mode_active') && b:table_mode_active
|
||||||
execute "inoremap <silent> " . s:TableModeSeparatorMap() . ' ' .
|
call s:SetBufferOptDefault('table_mode_separator_map', g:table_mode_separator)
|
||||||
\ s:TableModeSeparatorMap() . "<Esc>:call <SID>Tableize()<CR>a"
|
" '|' is a special character, we need to map <Bar> instead
|
||||||
|
if g:table_mode_separator ==# '|' | let b:table_mode_separator_map = '<Bar>' | endif
|
||||||
|
|
||||||
|
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
||||||
|
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||||
else
|
else
|
||||||
execute "iunmap <silent> " . s:TableModeSeparatorMap()
|
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
@@ -88,17 +77,17 @@ function! s:UpdateLineBorder(line) "{{{2
|
|||||||
if getline(cline-1) =~# hf
|
if getline(cline-1) =~# hf
|
||||||
let prev_line_count = s:CountSeparator(cline-1, g:table_mode_corner)
|
let prev_line_count = s:CountSeparator(cline-1, g:table_mode_corner)
|
||||||
if curr_line_count > prev_line_count
|
if curr_line_count > prev_line_count
|
||||||
execute 'normal! kA' . repeat(g:table_mode_corner, curr_line_count - prev_line_count) . "\<Esc>j"
|
silent! execute 'normal! kA' . repeat(g:table_mode_corner, curr_line_count - prev_line_count) . "\<Esc>j"
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
call append(cline-1, repeat(g:table_mode_corner, curr_line_count))
|
call append(cline-1, repeat(g:table_mode_corner, curr_line_count))
|
||||||
let cline = a:line + 1
|
let cline = a:line + 1 " because of the append, the current line moved down
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if getline(cline+1) =~# hf
|
if getline(cline+1) =~# hf
|
||||||
let next_line_count = s:CountSeparator(cline+1, g:table_mode_corner)
|
let next_line_count = s:CountSeparator(cline+1, g:table_mode_corner)
|
||||||
if curr_line_count > next_line_count
|
if curr_line_count > next_line_count
|
||||||
execute 'normal! jA' . repeat(g:table_mode_corner, curr_line_count - next_line_count) . "\<Esc>k"
|
silent! execute 'normal! jA' . repeat(g:table_mode_corner, curr_line_count - next_line_count) . "\<Esc>k"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
call append(cline, repeat(g:table_mode_corner, curr_line_count))
|
call append(cline, repeat(g:table_mode_corner, curr_line_count))
|
||||||
@@ -107,31 +96,29 @@ endfunction
|
|||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:FillTableBorder() "{{{2
|
function! s:FillTableBorder() "{{{2
|
||||||
let current_col = col('.')
|
let [ current_col, current_line ] = [ col('.'), line('.') ]
|
||||||
let current_line = line('.')
|
if g:table_mode_no_border_padding
|
||||||
execute 'silent! %s/' . g:table_mode_corner . ' \zs\([' .
|
silent! execute '%s/' . g:table_mode_corner . '\zs\([' .
|
||||||
\ g:table_mode_fillchar . ' ]*\)\ze ' . g:table_mode_corner . '/\=repeat("' .
|
\ g:table_mode_fillchar . ' ]*\)\ze' . g:table_mode_corner .
|
||||||
\ g:table_mode_fillchar . '", s:Strlen(submatch(0)))/g'
|
\ '/\=repeat("' . g:table_mode_fillchar . '", s:Strlen(submatch(0)))/g'
|
||||||
|
else
|
||||||
|
silent! execute '%s/' . g:table_mode_corner . ' \zs\([' .
|
||||||
|
\ g:table_mode_fillchar . ' ]*\)\ze ' . g:table_mode_corner .
|
||||||
|
\ '/\=repeat("' . g:table_mode_fillchar . '", s:Strlen(submatch(0)))/g'
|
||||||
|
endif
|
||||||
call cursor(current_line, current_col)
|
call cursor(current_line, current_col)
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:Tableize() "{{{2
|
function! s:ConvertDelimiterToSeparator(line) "{{{2
|
||||||
if s:IsTableModeActive() && getline('.') =~# ('^\s*' . g:table_mode_separator)
|
silent! execute a:line . 's/^\s*\zs\ze.\|' . g:table_mode_delimiter .
|
||||||
let column = s:Strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
|
\ '\|$/' . g:table_mode_separator . '/g'
|
||||||
let position = s:Strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
|
|
||||||
if g:table_mode_border | call s:UpdateLineBorder(line('.')) | endif
|
|
||||||
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
|
|
||||||
if g:table_mode_border | call s:FillTableBorder() | endif
|
|
||||||
normal! 0
|
|
||||||
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:Tableizeline(line) "{{{2
|
function! s:Tableizeline(line) "{{{2
|
||||||
call s:ConvertDelimiterToSeparator(a:line)
|
call s:ConvertDelimiterToSeparator(a:line)
|
||||||
call s:UpdateLineBorder(a:line)
|
if g:table_mode_border | call s:UpdateLineBorder(a:line) | endif
|
||||||
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
|
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
@@ -140,6 +127,20 @@ endfunction
|
|||||||
|
|
||||||
" Public API {{{1
|
" Public API {{{1
|
||||||
|
|
||||||
|
function! tablemode#TableizeInsertMode() "{{{2
|
||||||
|
if s:IsTableModeActive() && getline('.') =~# ('^\s*' . g:table_mode_separator)
|
||||||
|
let column = s:Strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
|
||||||
|
let position = s:Strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
|
||||||
|
if g:table_mode_border | call s:UpdateLineBorder(line('.')) | endif
|
||||||
|
if g:table_mode_no_border_padding && g:table_mode_align !=# 'c0' | let g:table_mode_align = 'c0' | endif
|
||||||
|
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
|
||||||
|
if g:table_mode_border | call s:FillTableBorder() | endif
|
||||||
|
normal! 0
|
||||||
|
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableModeEnable() "{{{2
|
function! tablemode#TableModeEnable() "{{{2
|
||||||
call s:SetActive(1)
|
call s:SetActive(1)
|
||||||
endfunction
|
endfunction
|
||||||
@@ -161,17 +162,19 @@ endfunction
|
|||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableizeRange() range "{{{2
|
function! tablemode#TableizeRange() range "{{{2
|
||||||
|
let shift = 1
|
||||||
|
if g:table_mode_border | let shift = shift + 1 | endif
|
||||||
call s:Tableizeline(a:firstline)
|
call s:Tableizeline(a:firstline)
|
||||||
undojoin
|
undojoin
|
||||||
" The first one causes 2 extra lines for top & bottom border while the
|
" The first one causes 2 extra lines for top & bottom border while the
|
||||||
" following lines cause only 1 for the bottom border.
|
" following lines cause only 1 for the bottom border.
|
||||||
let lnum = a:firstline+3
|
let lnum = a:firstline + shift + (g:table_mode_border > 0)
|
||||||
while lnum <= (a:firstline + (a:lastline - a:firstline+1)*2)
|
while lnum < (a:firstline + (a:lastline - a:firstline + 1)*shift)
|
||||||
call s:Tableizeline(lnum)
|
call s:Tableizeline(lnum)
|
||||||
undojoin
|
undojoin
|
||||||
let lnum = lnum + 2
|
let lnum = lnum + shift
|
||||||
endwhile
|
endwhile
|
||||||
call s:FillTableBorder()
|
if g:table_mode_border | call s:FillTableBorder() | endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
*table-mode.txt* Table Mode for easy table formatting. v2.1
|
*table-mode.txt* Table Mode for easy table formatting. v2.1.2
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||||
VERSION 2.1
|
VERSION 2.1.2
|
||||||
|
|
||||||
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||||
License: MIT <http://opensource.org/licenses/MIT/>
|
License: MIT <http://opensource.org/licenses/MIT/>
|
||||||
@@ -48,15 +48,17 @@ The table mode is disabled by default and you can enter table mode using
|
|||||||
OPTIONS *table-mode-options*
|
OPTIONS *table-mode-options*
|
||||||
|
|
||||||
Overview:
|
Overview:
|
||||||
|table-mode-options-loaded| .......... Disable the plugin
|
|table-mode-options-loaded| ............. Disable the plugin
|
||||||
|table-mode-options-border| .......... Enable border
|
|table-mode-options-border| ............. Enable border
|
||||||
|table-mode-options-corner| .......... Set corner character
|
|table-mode-options-corner| ............. Set corner character
|
||||||
|table-mode-options-separator| ....... Set separator character
|
|table-mode-options-separator| .......... Set separator character
|
||||||
|table-mode-options-fillchar| ........ Set table fillchar character
|
|table-mode-options-fillchar| ........... Set table fillchar character
|
||||||
|table-mode-options-toggle-map| ...... Set table mode toggle mapping
|
|table-mode-options-toggle-map| ......... Set table mode toggle mapping
|
||||||
|table-mode-options-always-active| ... Set table mode to always enabled
|
|table-mode-options-always-active| ...... Set table mode to always enabled
|
||||||
|table-mode-options-delimiter| ....... Set the delimiter for Tableize
|
|table-mode-options-delimiter| .......... Set the delimiter for Tableize
|
||||||
|table-mode-options-align| ........... Set the text alignment for Tableize
|
|table-mode-options-align| .............. Set the text alignment for
|
||||||
|
Tableize
|
||||||
|
|table-mode-options-no-border-padding| .. Set for no border padding.
|
||||||
|
|
||||||
g:table_mode_loaded *table-mode-options-loaded*
|
g:table_mode_loaded *table-mode-options-loaded*
|
||||||
Use this option to disable the plugin: >
|
Use this option to disable the plugin: >
|
||||||
@@ -110,6 +112,15 @@ g:table_mode_align *table-mode-options-align*
|
|||||||
the tables. Go through |tabular-walkthrough| for details on how to set
|
the tables. Go through |tabular-walkthrough| for details on how to set
|
||||||
the format options for alignment. >
|
the format options for alignment. >
|
||||||
let g:table_mode_align = 'l1'
|
let g:table_mode_align = 'l1'
|
||||||
|
<
|
||||||
|
|
||||||
|
g:table_mode_no_border_padding *table-mode-options-no-border-padding*
|
||||||
|
Use this option to remove the border padding (extra spaces around the
|
||||||
|
|table-mode-options-fillchar|). >
|
||||||
|
let g:table_mode_no_border_padding = 0
|
||||||
|
<
|
||||||
|
NOTE this option changes |table-mode-options-align| to 'c0', so that
|
||||||
|
there is no extra padding around the contents.
|
||||||
===============================================================================
|
===============================================================================
|
||||||
MAPPINGS *table-mode-mappings*
|
MAPPINGS *table-mode-mappings*
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user