mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 19:13:46 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87a713efb7 | ||
|
|
272bef4ce0 | ||
|
|
7c4039e5e1 | ||
|
|
28b13a32ab | ||
|
|
599a39c28d |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,4 +1,16 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
## Version 2.4.0
|
||||||
|
* Added Table Cell text object.
|
||||||
|
* Added api to delete entire table row.
|
||||||
|
* Added api to delete entire table column.
|
||||||
|
|
||||||
|
## Version 2.3.0
|
||||||
|
* Refactored realignment logic. Generating borders by hand.
|
||||||
|
|
||||||
|
## Version 2.2.2
|
||||||
|
* Added mapping for realigning table columns.
|
||||||
|
* Added table motions to move around in the table.
|
||||||
|
|
||||||
## Version 2.2.1
|
## Version 2.2.1
|
||||||
* Added feature to allow Table-Mode to work within comments. Uses
|
* Added feature to allow Table-Mode to work within comments. Uses
|
||||||
'commentstring' option of vim to identify comments, so it should work for
|
'commentstring' option of vim to identify comments, so it should work for
|
||||||
@@ -17,7 +29,7 @@
|
|||||||
* Bug Fixes #2, #3 & #4
|
* 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.
|
||||||
|
|
||||||
## Version 2.1 :
|
## Version 2.1 :
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ sure Tabular is installed and loaded into your runtime to ensure this works.
|
|||||||
`:line1,line2Tableize`, but this is not that intuitive. You can also use
|
`:line1,line2Tableize`, but this is not that intuitive. You can also use
|
||||||
the mapping `<Leader>T` with a `[count]` to apply it to the next `[count]`
|
the mapping `<Leader>T` with a `[count]` to apply it to the next `[count]`
|
||||||
lines in usual vim style.
|
lines in usual vim style.
|
||||||
|
- Move between cells :
|
||||||
|
|
||||||
|
Now you can move between cells using table mode motions. Check `:h
|
||||||
|
table-mode-motion-prefix` for more details.
|
||||||
|
|
||||||
### Demo
|
### Demo
|
||||||
|
|
||||||
|
|||||||
@@ -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.2.2
|
" Version: 2.4.0
|
||||||
" 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.
|
||||||
@@ -56,9 +56,11 @@ call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
|||||||
call s:SetGlobalOptDefault('table_mode_tableize_map', '<Leader>tt')
|
call s:SetGlobalOptDefault('table_mode_tableize_map', '<Leader>tt')
|
||||||
call s:SetGlobalOptDefault('table_mode_tableize_op_map', '<Leader>T')
|
call s:SetGlobalOptDefault('table_mode_tableize_op_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')
|
|
||||||
call s:SetGlobalOptDefault('table_mode_realign_map', '<Leader>tr')
|
call s:SetGlobalOptDefault('table_mode_realign_map', '<Leader>tr')
|
||||||
call s:SetGlobalOptDefault('table_mode_motion_prefix', '<Leader>t')
|
call s:SetGlobalOptDefault('table_mode_motion_prefix', '<Leader>t')
|
||||||
|
call s:SetGlobalOptDefault('table_mode_cell_text_object', 'tc')
|
||||||
|
call s:SetGlobalOptDefault('table_mode_delete_row_map', '<Leader>tdd')
|
||||||
|
call s:SetGlobalOptDefault('table_mode_delete_column_map', '<Leader>tdc')
|
||||||
"}}}1
|
"}}}1
|
||||||
|
|
||||||
function! s:TableMotion() "{{{1
|
function! s:TableMotion() "{{{1
|
||||||
@@ -70,7 +72,7 @@ endfunction
|
|||||||
" }}}1
|
" }}}1
|
||||||
|
|
||||||
" Define Commands & Mappings {{{1
|
" Define Commands & Mappings {{{1
|
||||||
if !g:table_mode_always_active
|
if !g:table_mode_always_active "{{{2
|
||||||
exec "nnoremap <silent> " . g:table_mode_toggle_map .
|
exec "nnoremap <silent> " . g:table_mode_toggle_map .
|
||||||
\ " <Esc>:call tablemode#TableModeToggle()<CR>"
|
\ " <Esc>:call tablemode#TableModeToggle()<CR>"
|
||||||
command! -nargs=0 TableModeToggle call tablemode#TableModeToggle()
|
command! -nargs=0 TableModeToggle call tablemode#TableModeToggle()
|
||||||
@@ -85,14 +87,21 @@ else
|
|||||||
\ table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
\ table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||||
unlet table_mode_separator_map
|
unlet table_mode_separator_map
|
||||||
endif
|
endif
|
||||||
|
" }}}2
|
||||||
|
|
||||||
command! -nargs=? -range Tableize <line1>,<line2>call tablemode#TableizeRange(<q-args>)
|
command! -nargs=? -range Tableize <line1>,<line2>call tablemode#TableizeRange(<q-args>)
|
||||||
|
|
||||||
execute "xnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
execute "xnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
||||||
execute "nnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
execute "nnoremap <silent> " . g:table_mode_tableize_map . " :Tableize<CR>"
|
||||||
execute "xnoremap <silent> " . g:table_mode_tableize_op_map . " :<C-U>call tablemode#TableizeByDelimiter()<CR>"
|
execute "xnoremap <silent> " . g:table_mode_tableize_op_map . " :<C-U>call tablemode#TableizeByDelimiter()<CR>"
|
||||||
|
|
||||||
execute "nnoremap <silent> " . g:table_mode_realign_map . " :<C-U>call tablemode#TableRealign()<CR>"
|
execute "nnoremap <silent> " . g:table_mode_realign_map . " :<C-U>call tablemode#TableRealign('.')<CR>"
|
||||||
execute "nnoremap <silent> " . g:table_mode_motion_prefix . " :<C-U>call <SID>TableMotion()<CR>"
|
execute "nnoremap <silent> " . g:table_mode_motion_prefix . " :<C-U>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_delete_row_map . " :<C-U>call tablemode#DeleteRow()<CR>"
|
||||||
|
execute "nnoremap <silent> " . g:table_mode_delete_column_map . " :<C-U>call tablemode#DeleteColumn()<CR>"
|
||||||
"}}}1
|
"}}}1
|
||||||
|
|
||||||
" Avoiding side effects {{{1
|
" Avoiding side effects {{{1
|
||||||
|
|||||||
@@ -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.2.2
|
" Version: 2.4.0
|
||||||
" 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.
|
||||||
@@ -35,11 +35,6 @@ function! s:Strlen(text)
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:CountSeparator(line, separator) "{{{2
|
|
||||||
return s:Strlen(substitute(getline(a:line), '[^' . a:separator . ']', '', 'g'))
|
|
||||||
endfunction
|
|
||||||
" }}}2
|
|
||||||
|
|
||||||
function! s:GetCommentStart() "{{{2
|
function! s:GetCommentStart() "{{{2
|
||||||
let cstring = &commentstring
|
let cstring = &commentstring
|
||||||
if s:Strlen(cstring) > 0
|
if s:Strlen(cstring) > 0
|
||||||
@@ -98,57 +93,58 @@ function! s:SetActive(bool) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:UpdateLineBorder(line) "{{{2
|
function! s:Line(line) "{{{2
|
||||||
let cline = a:line
|
if type(a:line) == type('')
|
||||||
let hf = s:StartExpr() . g:table_mode_corner . '[' . g:table_mode_corner . ' ' .
|
return line(a:line)
|
||||||
\ g:table_mode_fillchar . ']*' . g:table_mode_corner . '\?\s*$'
|
|
||||||
let curr_line_count = s:CountSeparator(cline, g:table_mode_separator)
|
|
||||||
|
|
||||||
if getline(cline-1) =~# hf
|
|
||||||
let prev_line_count = s:CountSeparator(cline-1, g:table_mode_corner)
|
|
||||||
if curr_line_count > prev_line_count
|
|
||||||
silent! execute 'normal! kA' . repeat(g:table_mode_corner, curr_line_count - prev_line_count) . "\<Esc>j"
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
let cstartexpr = s:StartCommentExpr()
|
return a:line
|
||||||
if s:Strlen(cstartexpr) > 0 && getline(cline) =~# cstartexpr
|
|
||||||
let indent = matchstr(getline(cline), s:StartCommentExpr())
|
|
||||||
call append(cline-1, indent . repeat(g:table_mode_corner, curr_line_count))
|
|
||||||
else
|
|
||||||
call append(cline-1, repeat(g:table_mode_corner, curr_line_count))
|
|
||||||
endif
|
|
||||||
let cline = a:line + 1 " because of the append, the current line moved down
|
|
||||||
endif
|
|
||||||
|
|
||||||
if getline(cline+1) =~# hf
|
|
||||||
let next_line_count = s:CountSeparator(cline+1, g:table_mode_corner)
|
|
||||||
if curr_line_count > next_line_count
|
|
||||||
silent! execute 'normal! jA' . repeat(g:table_mode_corner, curr_line_count - next_line_count) . "\<Esc>k"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
let cstartexpr = s:StartCommentExpr()
|
|
||||||
if s:Strlen(cstartexpr) > 0 && getline(cline) =~# cstartexpr
|
|
||||||
let indent = matchstr(getline(cline), s:StartCommentExpr())
|
|
||||||
call append(cline, indent . repeat(g:table_mode_corner, curr_line_count))
|
|
||||||
else
|
|
||||||
call append(cline, repeat(g:table_mode_corner, curr_line_count))
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:FillTableBorder() "{{{2
|
function! s:GenerateBorder(line) "{{{2
|
||||||
let [ current_col, current_line ] = [ col('.'), line('.') ]
|
let line = s:Line(a:line)
|
||||||
if g:table_mode_no_border_padding
|
|
||||||
silent! execute '%s/' . g:table_mode_corner . '\zs\([' .
|
let border = substitute(getline(line)[stridx(getline(line), g:table_mode_separator):-1], g:table_mode_separator, g:table_mode_corner, 'g')
|
||||||
\ g:table_mode_fillchar . ' ]*\)\ze' . g:table_mode_corner .
|
let border = substitute(border, '[^' . g:table_mode_corner . ']', g:table_mode_fillchar, 'g')
|
||||||
\ '/\=repeat("' . g:table_mode_fillchar . '", s:Strlen(submatch(0)))/g'
|
|
||||||
|
let cstartexpr = s:StartCommentExpr()
|
||||||
|
if s:Strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
||||||
|
let indent = matchstr(getline(line), s:StartCommentExpr())
|
||||||
|
return indent . border
|
||||||
|
elseif getline(line) =~# s:StartExpr()
|
||||||
|
let indent = matchstr(getline(line), s:StartExpr())
|
||||||
|
return indent . border
|
||||||
else
|
else
|
||||||
silent! execute '%s/' . g:table_mode_corner . ' \zs\([' .
|
return border
|
||||||
\ g:table_mode_fillchar . ' ]*\)\ze ' . g:table_mode_corner .
|
endif
|
||||||
\ '/\=repeat("' . g:table_mode_fillchar . '", s:Strlen(submatch(0)))/g'
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! s:UpdateLineBorder(line) "{{{2
|
||||||
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
|
let hf = s:StartExpr() . g:table_mode_corner . '[' . g:table_mode_corner .
|
||||||
|
\ g:table_mode_fillchar . ']*' . g:table_mode_corner . '\?\s*$'
|
||||||
|
|
||||||
|
let border = s:GenerateBorder(line)
|
||||||
|
|
||||||
|
let [prev_line, next_line] = [getline(line-1), getline(line+1)]
|
||||||
|
if next_line =~# hf
|
||||||
|
if s:Strlen(border) > s:Strlen(s:GenerateBorder(line + s:RowGap())) || !tablemode#IsATableRow(line + s:RowGap())
|
||||||
|
call setline(line+1, border)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
call append(line, border)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if prev_line =~# hf
|
||||||
|
if s:Strlen(border) > s:Strlen(s:GenerateBorder(line - s:RowGap())) || !tablemode#IsATableRow(line - s:RowGap())
|
||||||
|
call setline(line-1, border)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
call append(line-1, border)
|
||||||
endif
|
endif
|
||||||
call cursor(current_line, current_col)
|
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
@@ -171,22 +167,62 @@ function! s:Tableizeline(line, ...) "{{{2
|
|||||||
if a:0 && type(a:1) == type('') && !empty(a:1) | let delim = a:1[1:-1] | endif
|
if a:0 && type(a:1) == type('') && !empty(a:1) | let delim = a:1[1:-1] | endif
|
||||||
call s:ConvertDelimiterToSeparator(a:line, delim)
|
call s:ConvertDelimiterToSeparator(a:line, delim)
|
||||||
if g:table_mode_border | call s:UpdateLineBorder(a:line) | endif
|
if g:table_mode_border | call s:UpdateLineBorder(a:line) | endif
|
||||||
call tablemode#TableRealign()
|
|
||||||
endfunction
|
|
||||||
" }}}2
|
|
||||||
|
|
||||||
function! s:ColumnCount(line) "{{{2
|
|
||||||
return s:Strlen(substitute(getline(a:line), '[^' . g:table_mode_separator . ']', '', 'g'))-1
|
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:IsFirstCell() "{{{2
|
function! s:IsFirstCell() "{{{2
|
||||||
return tablemode#TableColumnNr('.') ==# 1
|
return tablemode#ColumnNr('.') ==# 1
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:IsLastCell() "{{{2
|
function! s:IsLastCell() "{{{2
|
||||||
return tablemode#TableColumnNr('.') ==# s:ColumnCount('.')
|
return tablemode#ColumnNr('.') ==# tablemode#ColumnCount('.')
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! s:MoveToFirstRow() "{{{2
|
||||||
|
if tablemode#IsATableRow('.')
|
||||||
|
let line = s:Line('.')
|
||||||
|
while line > 0
|
||||||
|
if !tablemode#IsATableRow(line)
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let line = line - s:RowGap()
|
||||||
|
endwhile
|
||||||
|
call cursor(line + s:RowGap(), col('.'))
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! s:MoveToLastRow() "{{{2
|
||||||
|
if tablemode#IsATableRow('.')
|
||||||
|
let line = s:Line('.')
|
||||||
|
while line <= line('$')
|
||||||
|
if !tablemode#IsATableRow(line)
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let line = line + s:RowGap()
|
||||||
|
endwhile
|
||||||
|
call cursor(line - s:RowGap(), col('.'))
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! s:MoveToStartOfCell() "{{{2
|
||||||
|
if getline('.')[col('.')-1] ==# g:table_mode_separator && !s:IsLastCell()
|
||||||
|
normal! 2l
|
||||||
|
else
|
||||||
|
execute 'normal! F' . g:table_mode_separator . '2l'
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! s:RowGap() "{{{2
|
||||||
|
if g:table_mode_border
|
||||||
|
return 2
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
@@ -198,10 +234,7 @@ function! tablemode#TableizeInsertMode() "{{{2
|
|||||||
if s:IsTableModeActive() && getline('.') =~# (s:StartExpr() . g:table_mode_separator)
|
if s:IsTableModeActive() && getline('.') =~# (s:StartExpr() . g:table_mode_separator)
|
||||||
let column = s:Strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
|
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.*'))
|
let position = s:Strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
|
||||||
if g:table_mode_border | call s:UpdateLineBorder(line('.')) | endif
|
call tablemode#TableRealign('.')
|
||||||
if g:table_mode_no_border_padding && g:table_mode_align !=# 'c0' | let g:table_mode_align = 'c0' | endif
|
|
||||||
call tablemode#TableRealign()
|
|
||||||
if g:table_mode_border | call s:FillTableBorder() | endif
|
|
||||||
normal! 0
|
normal! 0
|
||||||
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
||||||
endif
|
endif
|
||||||
@@ -241,7 +274,8 @@ function! tablemode#TableizeRange(...) range "{{{2
|
|||||||
undojoin
|
undojoin
|
||||||
let lnum = lnum + shift
|
let lnum = lnum + shift
|
||||||
endwhile
|
endwhile
|
||||||
if g:table_mode_border | call s:FillTableBorder() | endif
|
|
||||||
|
if g:table_mode_border | call tablemode#TableRealign(lnum - shift) | endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
@@ -255,8 +289,45 @@ function! tablemode#TableizeByDelimiter() "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableRealign() "{{{2
|
function! tablemode#TableRealign(line) "{{{2
|
||||||
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
|
let line = 0
|
||||||
|
if type(a:line) == type('')
|
||||||
|
let line = line(a:line)
|
||||||
|
else
|
||||||
|
let line = a:line
|
||||||
|
endif
|
||||||
|
|
||||||
|
let [lnums, lines] = [[], []]
|
||||||
|
let tline = line
|
||||||
|
while tline > 0
|
||||||
|
if tablemode#IsATableRow(tline)
|
||||||
|
call insert(lnums, tline)
|
||||||
|
call insert(lines, getline(tline))
|
||||||
|
else
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let tline = tline - s:RowGap()
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
let tline = line + s:RowGap()
|
||||||
|
while tline <= line('$')
|
||||||
|
if tablemode#IsATableRow(tline)
|
||||||
|
call add(lnums, tline)
|
||||||
|
call add(lines, getline(tline))
|
||||||
|
else
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let tline = tline + s:RowGap()
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
call tabular#TabularizeStrings(lines, g:table_mode_separator)
|
||||||
|
|
||||||
|
for lnum in lnums
|
||||||
|
let index = index(lnums, lnum)
|
||||||
|
call setline(lnum, lines[index])
|
||||||
|
undojoin
|
||||||
|
call s:UpdateLineBorder(lnum)
|
||||||
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
@@ -265,13 +336,35 @@ function! tablemode#IsATableRow(line) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableRowNr(pos) "{{{2
|
function! tablemode#RowCount(line) "{{{2
|
||||||
let line = 0
|
let line = s:Line(a:line)
|
||||||
if type(a:pos) == type('')
|
|
||||||
let line = line(a:pos)
|
let [tline, totalRowCount] = [line, 0]
|
||||||
elseif type(a:pos) == type(1)
|
while tline > 0
|
||||||
let line = a:pos
|
if tablemode#IsATableRow(tline)
|
||||||
|
let totalRowCount = totalRowCount + 1
|
||||||
|
else
|
||||||
|
break
|
||||||
endif
|
endif
|
||||||
|
let tline = tline - s:RowGap()
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
let tline = line + s:RowGap()
|
||||||
|
while tline <= line('$')
|
||||||
|
if tablemode#IsATableRow(tline)
|
||||||
|
let totalRowCount = totalRowCount + 1
|
||||||
|
else
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let tline = tline + s:RowGap()
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
return totalRowCount
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! tablemode#RowNr(line) "{{{2
|
||||||
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
let rowNr = 0
|
let rowNr = 0
|
||||||
while line > 0
|
while line > 0
|
||||||
@@ -280,13 +373,21 @@ function! tablemode#TableRowNr(pos) "{{{2
|
|||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
let line = line - 2
|
let line = line - s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return rowNr
|
return rowNr
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableColumnNr(pos) "{{{2
|
function! tablemode#ColumnCount(line) "{{{2
|
||||||
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
|
return s:Strlen(substitute(getline(line), '[^' . g:table_mode_separator . ']', '', 'g'))-1
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! tablemode#ColumnNr(pos) "{{{2
|
||||||
let pos = []
|
let pos = []
|
||||||
if type(a:pos) == type('')
|
if type(a:pos) == type('')
|
||||||
let pos = [line(a:pos), col(a:pos)]
|
let pos = [line(a:pos), col(a:pos)]
|
||||||
@@ -295,31 +396,29 @@ function! tablemode#TableColumnNr(pos) "{{{2
|
|||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return s:Strlen(substitute(getline(pos[0])[0:pos[1]-2], '[^' . g:table_mode_separator . ']', '', 'g'))
|
return s:Strlen(substitute(getline(pos[0])[0:pos[1]-2], '[^' . g:table_mode_separator . ']', '', 'g'))
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableMotion(direction) "{{{2
|
function! tablemode#TableMotion(direction) "{{{2
|
||||||
if tablemode#IsATableRow('.')
|
if tablemode#IsATableRow('.')
|
||||||
let rowCount = 1
|
|
||||||
if g:table_mode_border | let rowCount = 2 | endif
|
|
||||||
|
|
||||||
if a:direction ==# 'l'
|
if a:direction ==# 'l'
|
||||||
if s:IsLastCell()
|
if s:IsLastCell()
|
||||||
if !tablemode#IsATableRow(line('.') + rowCount) | return | endif
|
if !tablemode#IsATableRow(line('.') + s:RowGap()) | return | endif
|
||||||
call tablemode#TableMotion('j')
|
call tablemode#TableMotion('j')
|
||||||
normal! 0
|
normal! 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If line starts with g:table_mode_separator
|
" If line starts with g:table_mode_separator
|
||||||
if getline('.')[col('.')-1] ==# g:table_mode_separator
|
if getline('.')[col('.')-1] ==# g:table_mode_separator
|
||||||
execute 'normal! 2l'
|
normal! 2l
|
||||||
else
|
else
|
||||||
execute 'normal! f' . g:table_mode_separator . '2l'
|
execute 'normal! f' . g:table_mode_separator . '2l'
|
||||||
endif
|
endif
|
||||||
elseif a:direction ==# 'h'
|
elseif a:direction ==# 'h'
|
||||||
if s:IsFirstCell()
|
if s:IsFirstCell()
|
||||||
if !tablemode#IsATableRow(line('.') - rowCount) | return | endif
|
if !tablemode#IsATableRow(line('.') - s:RowGap()) | return | endif
|
||||||
call tablemode#TableMotion('k')
|
call tablemode#TableMotion('k')
|
||||||
normal! $
|
normal! $
|
||||||
endif
|
endif
|
||||||
@@ -331,12 +430,62 @@ function! tablemode#TableMotion(direction) "{{{2
|
|||||||
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
||||||
endif
|
endif
|
||||||
elseif a:direction ==# 'j'
|
elseif a:direction ==# 'j'
|
||||||
if tablemode#IsATableRow(line('.') + rowCount) | execute 'normal ' . rowCount . 'j' | endif
|
if tablemode#IsATableRow(line('.') + s:RowGap()) | execute 'normal ' . s:RowGap() . 'j' | endif
|
||||||
elseif a:direction ==# 'k'
|
elseif a:direction ==# 'k'
|
||||||
if tablemode#IsATableRow(line('.') - rowCount) | execute 'normal ' . rowCount . 'k' | endif
|
if tablemode#IsATableRow(line('.') - s:RowGap()) | execute 'normal ' . s:RowGap() . 'k' | endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
|
function! tablemode#CellTextObject() "{{{2
|
||||||
|
if tablemode#IsATableRow('.')
|
||||||
|
call s:MoveToStartOfCell()
|
||||||
|
|
||||||
|
if v:operator ==# 'y'
|
||||||
|
normal! v
|
||||||
|
call search('[^' . g:table_mode_separator . ']\ze\s*' . g:table_mode_separator)
|
||||||
|
else
|
||||||
|
execute 'normal! vf' . g:table_mode_separator
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! tablemode#DeleteColumn() "{{{2
|
||||||
|
if tablemode#IsATableRow('.')
|
||||||
|
for i in range(v:count1)
|
||||||
|
call s:MoveToFirstRow()
|
||||||
|
call s:MoveToStartOfCell()
|
||||||
|
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||||
|
call s:MoveToLastRow()
|
||||||
|
normal! d
|
||||||
|
endfor
|
||||||
|
|
||||||
|
call tablemode#TableRealign('.')
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! tablemode#DeleteRow() "{{{2
|
||||||
|
if tablemode#IsATableRow('.')
|
||||||
|
for i in range(v:count1)
|
||||||
|
if tablemode#RowCount('.') ==# 1
|
||||||
|
normal! kVjjd
|
||||||
|
else
|
||||||
|
normal! kVjd
|
||||||
|
endif
|
||||||
|
|
||||||
|
if tablemode#IsATableRow(line('.')+1)
|
||||||
|
normal! j
|
||||||
|
else
|
||||||
|
normal! k
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
call tablemode#TableRealign('.')
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
*table-mode.txt* Table Mode for easy table formatting. v2.2.2
|
*table-mode.txt* Table Mode for easy table formatting. v2.4.0
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||||
VERSION 2.2.2
|
VERSION 2.4.0
|
||||||
|
|
||||||
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/>
|
||||||
@@ -34,15 +34,40 @@ make sure it is installed and loaded.
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
GETTING STARTED *table-mode-getting-started*
|
GETTING STARTED *table-mode-getting-started*
|
||||||
|
|
||||||
Using Table Mode is dead simple. You simply start typing on a new line with
|
Create Table on the fly:
|
||||||
the table separator - |g:table-mode-separator|, and you just type away! The
|
Using Table Mode is dead simple. You simply start typing on a new line
|
||||||
plugin does the rest automatically for you as you type. With each additional
|
with the table separator - |g:table-mode-separator|, and you just type
|
||||||
separator you add, it aligns the table properly, without having to do
|
away! The plugin does the rest automatically for you as you type. With
|
||||||
anything else.
|
each additional separator you add, it aligns the table properly,
|
||||||
|
without having to do anything else.
|
||||||
|
|
||||||
The table mode is disabled by default and you can enter table mode using
|
The table mode is disabled by default and you can enter table mode
|
||||||
|table-mode-toggle-map| or you can also enable it permanently using
|
using |table-mode-toggle-map| or you can also enable it permanently
|
||||||
|g:table-mode-always-active| if you wish.
|
using |g:table-mode-always-active| if you wish.
|
||||||
|
|
||||||
|
Table Mode allows for creation of tables within comments, it looks at
|
||||||
|
the 'commentstring' setting to identify whether the current line is
|
||||||
|
commented.
|
||||||
|
|
||||||
|
Tableize content:
|
||||||
|
Table Mode enables conversion of delimited text into tables. Again
|
||||||
|
like table creation, this is also applicable within comments.
|
||||||
|
|
||||||
|
Manipulation of tables:
|
||||||
|
Tableize provides 3 easy ways to quickly manipulate tables.
|
||||||
|
|
||||||
|
1. Cell Text Object : A text object for table cell
|
||||||
|
defined by |table-mode-cell-text-object|. You can use it with an
|
||||||
|
operator (d,c,y) to manipulate it easily. If you delete the cell using
|
||||||
|
this, it will delete the table separator along with it so if you type
|
||||||
|
out some new stuff, you will have to re-add it, which triggers a
|
||||||
|
re-alignment and the table would be formatted again.
|
||||||
|
|
||||||
|
2. Delete Column : Delete an entire table column using
|
||||||
|
|table-mode-delete-column-map| .
|
||||||
|
|
||||||
|
3. Delete Row : Delete an entire table row using
|
||||||
|
|table-mode-delete-row-map|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
OPTIONS *table-mode-options*
|
OPTIONS *table-mode-options*
|
||||||
@@ -63,6 +88,10 @@ Overview:
|
|||||||
|table-mode-no-border-padding| .. Set for no border padding.
|
|table-mode-no-border-padding| .. Set for no border padding.
|
||||||
|table-mode-realign-map| ........ Set mapping for table realigning.
|
|table-mode-realign-map| ........ Set mapping for table realigning.
|
||||||
|table-mode-motion-prefix| ...... Set prefix for table mode motions.
|
|table-mode-motion-prefix| ...... Set prefix for table mode motions.
|
||||||
|
|table-mode-cell-text-object| ... Set mapping for table cell object.
|
||||||
|
|table-mode-delete-row-map| ..... Set mapping for deleting table row.
|
||||||
|
|table-mode-delete-column-map| .. Set mapping for deleting table
|
||||||
|
column.
|
||||||
|
|
||||||
g:table_mode_loaded *table-mode-loaded*
|
g:table_mode_loaded *table-mode-loaded*
|
||||||
Use this option to disable the plugin: >
|
Use this option to disable the plugin: >
|
||||||
@@ -154,7 +183,39 @@ g:table_mode_motion_prefix *table-mode-motion-prefix*
|
|||||||
You can move to the next / previous row / column using the motion
|
You can move to the next / previous row / column using the motion
|
||||||
commands. The motions 'hjkl' follow the prefix are in accordance to
|
commands. The motions 'hjkl' follow the prefix are in accordance to
|
||||||
standard vim character motions to make them easier to remember. They
|
standard vim character motions to make them easier to remember. They
|
||||||
may also be preceeded with a [count].
|
may also be preceeded with a [count]. The 'h', 'l' (left and right
|
||||||
|
motions) wrap around the table row and move to the previous rows last
|
||||||
|
column, next rows first column respectively if one exists.
|
||||||
|
|
||||||
|
g:table_mode_cell_text_object *table-mode-cell-text-object*
|
||||||
|
Use this option to define the table mode cell text object. >
|
||||||
|
let g:table_mode_cell_text_object = 'tc'
|
||||||
|
<
|
||||||
|
This text object automatically selects different text depending on the
|
||||||
|
context.
|
||||||
|
|
||||||
|
If you delete the cell using either the 'd' or the 'c'
|
||||||
|
operator, it will delete cell contents along with the table separator.
|
||||||
|
In case you do it with 'c' while you add new content for the cell, you
|
||||||
|
will have to re-add the |table-mode-separator|, which will trigger the
|
||||||
|
re-alignment of the table again and format it correctly.
|
||||||
|
|
||||||
|
If you simply want to yank the table content, this text object will
|
||||||
|
select only the table cell contents, without the padding (extra space
|
||||||
|
around the text) or the |table-mode-separator|.
|
||||||
|
|
||||||
|
g:table_mode_delete_row_map *table-mode-delete-row-map*
|
||||||
|
Use this option to define the mapping for deletion of the entire table
|
||||||
|
row. You can delete multiple rows by preceeding this with a [count]. >
|
||||||
|
let g:table_mode_delete_column_map = '<Leader>tdd'
|
||||||
|
|
||||||
|
g:table_mode_delete_column_map *table-mode-delete-column-map*
|
||||||
|
USe this option to define the mapping for deletion of the entire table
|
||||||
|
column. You can delete multiple columns to the right by preceeding
|
||||||
|
this with a [count] >
|
||||||
|
let g:table_mode_delete_column_map = '<Leader>tdc'
|
||||||
|
<
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
MAPPINGS *table-mode-mappings*
|
MAPPINGS *table-mode-mappings*
|
||||||
|
|
||||||
@@ -178,6 +239,20 @@ MAPPINGS *table-mode-mappings*
|
|||||||
|
|
||||||
*table-mode-mappings-realign*
|
*table-mode-mappings-realign*
|
||||||
<Leader>tr Realigns table columns
|
<Leader>tr Realigns table columns
|
||||||
|
|
||||||
|
*table-mode-mappings-motions*
|
||||||
|
<Leader>t[hjkl] Move to previous | below | above | right cell in the table.
|
||||||
|
|
||||||
|
*table-mode-mappings-delete-row*
|
||||||
|
<Leader>tdd Delete the entire table row you are on or multiple rows using
|
||||||
|
a [count]. You can change this using |table-mode-delete-row-map|
|
||||||
|
option.
|
||||||
|
|
||||||
|
*table-mode-mappings-delete-column*
|
||||||
|
<Leader>tdc Delete entire table column you are within. You can preceed it
|
||||||
|
with a [count] to delete multiple columns to the right. You
|
||||||
|
can change this using |table-mode-delete-column-map| option.
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
COMMANDS *table-mode-commands*
|
COMMANDS *table-mode-commands*
|
||||||
|
|
||||||
@@ -233,4 +308,4 @@ REPORT ISSUES *table-mode-report-issues*
|
|||||||
If you discover any issues, please report them at
|
If you discover any issues, please report them at
|
||||||
http://github.com/dhruvasagar/table-mode/issues.
|
http://github.com/dhruvasagar/table-mode/issues.
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:
|
vim:tw=78:ts=8:ft=help:norl:ai
|
||||||
|
|||||||
Reference in New Issue
Block a user