mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a6a9b3473 | ||
|
|
aa8817621c | ||
|
|
54187d0be1 | ||
|
|
3e2eaeee5c |
@@ -124,7 +124,11 @@ function! s:EndExpr() "{{{2
|
||||
endfunction
|
||||
|
||||
function! s:HeaderBorderExpr() "{{{2
|
||||
return s:StartExpr() . g:table_mode_corner . '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' . g:table_mode_corner . s:EndExpr()
|
||||
return s:StartExpr() .
|
||||
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
||||
\ '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' .
|
||||
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
||||
\ s:EndExpr()
|
||||
endfunction
|
||||
|
||||
function! s:StartCommentExpr() "{{{2
|
||||
@@ -166,12 +170,12 @@ function! s:ToggleMapping() "{{{2
|
||||
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
||||
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||
|
||||
execute "inoreabbrev <silent> <buffer> " . g:table_mode_corner .
|
||||
execute "inoremap <silent> <buffer> " . g:table_mode_corner .
|
||||
\ g:table_mode_fillchar . " <Esc>:call tablemode#AddHeaderBorder('.')<CR>A"
|
||||
else
|
||||
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
||||
|
||||
execute "iunabbrev <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
||||
execute "iunmap <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -186,6 +190,7 @@ function! s:GenerateHeaderBorder(line) "{{{2
|
||||
let line_val = getline(line - s:RowGap())
|
||||
let border = substitute(line_val[stridx(line_val, g:table_mode_separator):strridx(line_val, g:table_mode_separator)], g:table_mode_separator, g:table_mode_corner, 'g')
|
||||
let border = substitute(border, '[^' . g:table_mode_corner . ']', g:table_mode_fillchar, 'g')
|
||||
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_separator . '\1' . g:table_mode_separator , '')
|
||||
|
||||
let cstartexpr = s:StartCommentExpr()
|
||||
if s:Strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
||||
@@ -687,9 +692,13 @@ function! tablemode#TableRealign(line) "{{{2
|
||||
endfunction
|
||||
|
||||
function! tablemode#IsATableRow(line) "{{{2
|
||||
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator)
|
||||
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator . '[^' .
|
||||
\ g:table_mode_fillchar . ']*[^' . g:table_mode_corner . ']*$')
|
||||
endfunction
|
||||
|
||||
function! tablemode#IsATableHeader(line) "{{{2
|
||||
return getline(a:line) =~# s:HeaderBorderExpr()
|
||||
endfunction
|
||||
|
||||
function! tablemode#LineNr(row) "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
@@ -755,7 +764,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
if a:direction ==# 'l'
|
||||
if s:IsLastCell()
|
||||
if !tablemode#IsATableRow(line('.') + s:RowGap()) | return | endif
|
||||
if !tablemode#IsATableHeader(line('.') + s:RowGap()) && !tablemode#IsATableRow(line('.') + s:RowGap())
|
||||
return
|
||||
endif
|
||||
call tablemode#TableMotion('j')
|
||||
normal! 0
|
||||
endif
|
||||
@@ -768,7 +779,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
endif
|
||||
elseif a:direction ==# 'h'
|
||||
if s:IsFirstCell()
|
||||
if !tablemode#IsATableRow(line('.') - s:RowGap()) | return | endif
|
||||
if !tablemode#IsATableHeader(line('.') - s:RowGap()) && !tablemode#IsATableRow(line('.') - s:RowGap())
|
||||
return
|
||||
endif
|
||||
call tablemode#TableMotion('k')
|
||||
normal! $
|
||||
endif
|
||||
@@ -780,9 +793,17 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
||||
endif
|
||||
elseif a:direction ==# 'j'
|
||||
if tablemode#IsATableRow(line('.') + s:RowGap()) | execute 'normal ' . s:RowGap() . 'j' | endif
|
||||
if tablemode#IsATableRow(line('.') + s:RowGap())
|
||||
execute 'normal ' . s:RowGap() . 'j'
|
||||
elseif tablemode#IsATableHeader(line('.') + s:RowGap())
|
||||
execute 'normal ' . (s:RowGap() + 1) . 'j'
|
||||
endif
|
||||
elseif a:direction ==# 'k'
|
||||
if tablemode#IsATableRow(line('.') - s:RowGap()) | execute 'normal ' . s:RowGap() . 'k' | endif
|
||||
if tablemode#IsATableRow(line('.') - s:RowGap())
|
||||
execute 'normal ' . s:RowGap() . 'k'
|
||||
elseif tablemode#IsATableHeader(line('.') - s:RowGap())
|
||||
execute 'normal ' . (s:RowGap() + 1) . 'k'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
@@ -803,7 +824,21 @@ endfunction
|
||||
function! tablemode#DeleteColumn() "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
for i in range(v:count1)
|
||||
call s:MoveToFirstRow()
|
||||
call s:MoveToStartOfCell()
|
||||
|
||||
if tablemode#IsATableRow(line('.') + 1)
|
||||
call s:MoveToFirstRow()
|
||||
" If we have a header delete it first
|
||||
if tablemode#IsATableRow(line('.')-2)
|
||||
call cursor(line('.')-2, col('.'))
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
normal! jdjj
|
||||
endif
|
||||
else " We're already on the header
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
normal! jdjj
|
||||
endif
|
||||
|
||||
call s:MoveToStartOfCell()
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
call s:MoveToLastRow()
|
||||
@@ -817,15 +852,11 @@ endfunction
|
||||
function! tablemode#DeleteRow() "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
for i in range(v:count1)
|
||||
if tablemode#RowCount('.') ==# 1
|
||||
normal! kVjjd
|
||||
else
|
||||
normal! kVjd
|
||||
if tablemode#IsATableRow('.')
|
||||
normal! dd
|
||||
endif
|
||||
|
||||
if tablemode#IsATableRow(line('.')+1)
|
||||
normal! j
|
||||
else
|
||||
if !tablemode#IsATableRow('.')
|
||||
normal! k
|
||||
endif
|
||||
endfor
|
||||
|
||||
@@ -29,7 +29,7 @@ GETTING STARTED *table-mode-getting-started*
|
||||
|
||||
Create Table on the fly:
|
||||
Using Table Mode is dead simple. You simply start typing on a new line
|
||||
with the table separator - |g:table-mode-separator|, and you just type
|
||||
with the table separator - |table-mode-separator|, and you just type
|
||||
away! The plugin does the rest automatically for you as you type. With
|
||||
each additional separator you add, it aligns the table properly,
|
||||
without having to do anything else.
|
||||
|
||||
Reference in New Issue
Block a user