mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3476c4e517 | ||
|
|
88cb2e44b6 | ||
|
|
336262d04f | ||
|
|
5c489b57e8 | ||
|
|
436e7d6c21 | ||
|
|
1ea7960834 | ||
|
|
ff38f4451b | ||
|
|
d5b9ce4d9e | ||
|
|
6404009080 | ||
|
|
c9b13e5d30 |
62
README.md
62
README.md
@@ -1,4 +1,4 @@
|
|||||||
# VIM Table Mode v4.7.0 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
# VIM Table Mode v4.7.3 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
||||||
|
|
||||||
An awesome automatic table creator & formatter allowing one to create neat
|
An awesome automatic table creator & formatter allowing one to create neat
|
||||||
tables as you type.
|
tables as you type.
|
||||||
@@ -26,14 +26,15 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
|||||||
~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX or
|
~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX or
|
||||||
vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and
|
vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and
|
||||||
restart VIM
|
restart VIM
|
||||||
|
|
||||||
|
4. Alternatively, if using <a href="https://github.com/junegunn/vim-plug">vim-plug</a>, then add `Plug 'dhruvasagar/vim-table-mode'` to your ~/.vimrc.
|
||||||
|
|
||||||
### Creating table on-the-fly
|
### Creating table on-the-fly
|
||||||
|
|
||||||
To start using the plugin in the on-the-fly mode use `:TableModeToggle` mapped to <kbd>\<Leader\>tm</kbd> by default (which means <kbd>\\</kbd> <kbd>t</kbd> <kbd>m</kbd> if you didn't override the <Leader> by `:let mapleader = ','` to have <kbd>,</kbd> <kbd>t</kbd> <kbd>m</kbd>).
|
To start using the plugin in the on-the-fly mode use `:TableModeToggle` mapped to <kbd>\<Leader\>tm</kbd> by default (which means <kbd>\\</kbd> <kbd>t</kbd> <kbd>m</kbd> if you didn't override the <Leader> by `:let mapleader = ','` to have <kbd>,</kbd> <kbd>t</kbd> <kbd>m</kbd>).
|
||||||
|
|
||||||
> Tip :
|
Tip:
|
||||||
> You can use the following to quickly enable / disable table mode in insert
|
You can use the following to quickly enable / disable table mode in insert mode by using `||` or `__`:
|
||||||
> mode by using `||` or `__` :
|
|
||||||
> ```vim
|
> ```vim
|
||||||
> function! s:isAtStartOfLine(mapping)
|
> function! s:isAtStartOfLine(mapping)
|
||||||
> let text_before_cursor = getline('.')[0 : col('.')-1]
|
> let text_before_cursor = getline('.')[0 : col('.')-1]
|
||||||
@@ -115,34 +116,33 @@ To get ReST-compatible tables use
|
|||||||
|
|
||||||
Markdown and ReST filetypes have automatically configured corners.
|
Markdown and ReST filetypes have automatically configured corners.
|
||||||
|
|
||||||
You can also define in a table header border how it's content should be
|
You can also define in a table header border how its content should be
|
||||||
aligned, whether center, right or left by using a `:` character defined by
|
aligned, whether center, right or left by using a `:` character defined by
|
||||||
`g:table_mode_align_char` option.
|
`g:table_mode_align_char` option.
|
||||||
|
|
||||||
If you manipulate the table when table mode is disabled or copy paste a table
|
If you manipulate the table when table mode is disabled or copy paste a table
|
||||||
from clipboard from outside and it ends up being misaligned, you can realign
|
from clipboard from outside and it ends up being misaligned, you can realign
|
||||||
it using `:TableModeRealign` or using the default mapping
|
it using `:TableModeRealign` or using the default mapping
|
||||||
<kbd>\<Leader\>tr</kbd> defined by `g:table_mode_relign_map` option.
|
<kbd>\<Leader\>tr</kbd> (defined by the option `g:table_mode_relign_map`).
|
||||||
|
|
||||||
### Formatting existing content into a table
|
### Formatting existing content into a table
|
||||||
|
|
||||||
Table Mode wouldn't justify it's name if it didn't allow formatting
|
Table Mode wouldn't justify its name if it didn't allow formatting
|
||||||
existing content into a table. And it does as promised. Like table creation
|
existing content into a table. And it does as promised. Like table creation typing on the fly,
|
||||||
on the fly as you type, formatting existing content into a table is equally
|
formatting existing content into a table is equally
|
||||||
simple. You can visually select multiple lines and call `:Tableize` on it,
|
simple. You can visually select multiple lines and call `:Tableize` on it.
|
||||||
or alternatively use the mapping <kbd>\<Leader\>tt</kbd> defined by the
|
Alternatively, the mapping <kbd>\<Leader\>tt</kbd> can be used (defined by the
|
||||||
`g:table_mode_tableize_map` option which would convert CSV (Comma Separated
|
option `g:table_mode_tableize_map`). This converts CSV (Comma-separated
|
||||||
Value) data into a table and use `,` defined by `g:table_mode_delimiter`
|
Values) data into a table.
|
||||||
option as the delimiter.
|
|
||||||
|
|
||||||
If however you wish to use a different delimiter, you can use the command
|
If however you wish to use a different delimiter, you can use the command
|
||||||
`:Tableize/{pattern}` in a similar fashion as you use tabular (eg.
|
`:Tableize/{pattern}` in a similar fashion as you tabulate (e.g.
|
||||||
`:Tableize/;` uses ';' as the delimiter) or use the mapping <kbd>\<Leader\>T</kbd>
|
`:Tableize/;` uses ';' as the delimiter) or use the mapping <kbd>\<Leader\>T</kbd>
|
||||||
defined by `g:table_mode_tableize_op_map` option which takes input in the
|
(defined by the option `g:table_mode_tableize_op_map`) which takes input in the
|
||||||
cmd-line and uses the `{pattern}` input as the delimiter.
|
cmd-line and uses the `{pattern}` input as the delimiter.
|
||||||
|
|
||||||
`:Tableize` also accepts a range and so you can also call it by giving
|
`:Tableize` also accepts a range. Call it by giving
|
||||||
lines manually like `:line1,line2Tableize`, but this is not very intuitive.
|
lines manually like `:line1,line2Tableize`. However this may not be intuitive.
|
||||||
You can use the mapping <kbd>\<Leader\>T</kbd> with a `[count]` to apply it to the
|
You can use the mapping <kbd>\<Leader\>T</kbd> with a `[count]` to apply it to the
|
||||||
next `[count]` lines in standard vim style.
|
next `[count]` lines in standard vim style.
|
||||||
|
|
||||||
@@ -160,27 +160,27 @@ it using `:TableModeRealign` or using the default mapping
|
|||||||
|
|
||||||
Tableize provides a text object for manipulating table cells. Following
|
Tableize provides a text object for manipulating table cells. Following
|
||||||
the vim philosophy the you have <kbd>i|</kbd> & <kbd>a|</kbd> for the
|
the vim philosophy the you have <kbd>i|</kbd> & <kbd>a|</kbd> for the
|
||||||
inner and around (including the immidiate right table separator) the
|
inner and around (including the immediate right table separator) the
|
||||||
table cell.
|
table cell.
|
||||||
|
|
||||||
- **Delete Row** :
|
- **Delete Row** :
|
||||||
|
|
||||||
You can use the <kbd>\<Leader\>tdd</kbd> mapping defined by the option
|
You can use the <kbd>\<Leader\>tdd</kbd> mapping (defined by the option
|
||||||
`g:table_mode_delete_row_map` to delete the current table row (provided
|
`g:table_mode_delete_row_map`) to delete the current table row (provided
|
||||||
you are within a table row), this can be preceeded with a [count] to
|
you are within a table row). This can be preceeded with a `[count]` to
|
||||||
delete multiple rows just like you would with 'dd'.
|
delete multiple rows as per Vim command grammar.
|
||||||
|
|
||||||
- **Delete Column** :
|
- **Delete Column** :
|
||||||
|
|
||||||
You can use the <kbd>\<Leader\>tdc</kbd> mapping defined by the option
|
You can use the <kbd>\<Leader\>tdc</kbd> mapping (defined by the option
|
||||||
`g:table_mode_delete_column_map` to delete the entire current column
|
`g:table_mode_delete_column_map`) to delete the entire current column
|
||||||
(provided you are within a table row), this can also be preceeded with a
|
(provided you are within a table row), this can also be preceeded with a
|
||||||
[count] to delete multiple columns.
|
`[count]` to delete multiple columns.
|
||||||
|
|
||||||
- **Insert Column** :
|
- **Insert Column** :
|
||||||
|
|
||||||
You can use the <kbd>\<Leader\>tic</kbd> mapping defined by the option
|
You can use the <kbd>\<Leader\>tic</kbd> mapping (defined by the option
|
||||||
`g:table_mode_insert_column_after_map` to insert a column after the
|
`g:table_mode_insert_column_after_map`) to insert a column after the
|
||||||
cursor (provided you are within a table row). Of course you can use the
|
cursor (provided you are within a table row). Of course you can use the
|
||||||
<kbd>\<Leader\>tiC</kbd> mapping defined by
|
<kbd>\<Leader\>tiC</kbd> mapping defined by
|
||||||
`g:table_mode_insert_column_before_map` to insert a column before the
|
`g:table_mode_insert_column_before_map` to insert a column before the
|
||||||
@@ -195,7 +195,7 @@ it using `:TableModeRealign` or using the default mapping
|
|||||||
of defining formulas :
|
of defining formulas :
|
||||||
|
|
||||||
- You can add formulas using `:TableAddFormula` or the mapping <kbd>\<Leader\>tfa</kbd>
|
- You can add formulas using `:TableAddFormula` or the mapping <kbd>\<Leader\>tfa</kbd>
|
||||||
defined by the option `g:table_mode_add_formula_map` from within a table
|
(defined by the option `g:table_mode_add_formula_map`) from within a table
|
||||||
cell, which will ask for input on the cmd-line with a `f=` prompt. The
|
cell, which will ask for input on the cmd-line with a `f=` prompt. The
|
||||||
input formula will be appended to the formula line if one exists or a new
|
input formula will be appended to the formula line if one exists or a new
|
||||||
one will be created with the input formula taking the current cell as the
|
one will be created with the input formula taking the current cell as the
|
||||||
@@ -208,7 +208,7 @@ it using `:TableModeRealign` or using the default mapping
|
|||||||
formulas on the line separated with a ';' eg) `# tmf: $3=$2*$1;$4=$3/3.14`
|
formulas on the line separated with a ';' eg) `# tmf: $3=$2*$1;$4=$3/3.14`
|
||||||
|
|
||||||
You can evaluate the formula line using `:TableEvalFormulaLine` or the
|
You can evaluate the formula line using `:TableEvalFormulaLine` or the
|
||||||
mapping <kbd>\<Leader\>tfe</kbd> defined by the option `g:table_mode_eval_expr_map`
|
mapping <kbd>\<Leader\>tfe</kbd> (defined by the option `g:table_mode_eval_expr_map`)
|
||||||
from anywhere inside the table or while on the formula line.
|
from anywhere inside the table or while on the formula line.
|
||||||
|
|
||||||
NOTE: You can now use the mapping <kbd>\<Leader\>t?</kbd>
|
NOTE: You can now use the mapping <kbd>\<Leader\>t?</kbd>
|
||||||
@@ -233,7 +233,7 @@ it using `:TableModeRealign` or using the default mapping
|
|||||||
which are also defined by the same format as that of the target cell. You
|
which are also defined by the same format as that of the target cell. You
|
||||||
can use all native vim functions within the formula. Apart from that table
|
can use all native vim functions within the formula. Apart from that table
|
||||||
mode also provides 2 special functions `Sum` and `Average`. Both these
|
mode also provides 2 special functions `Sum` and `Average`. Both these
|
||||||
functions take a range as input. A range can be of two forms :
|
functions take a range as input. A range can be of two forms:
|
||||||
|
|
||||||
- `r1:r2`: This represents cells in the current column from row `r1`
|
- `r1:r2`: This represents cells in the current column from row `r1`
|
||||||
through `r2`. If `r2` is negative it represents `r2` rows above the
|
through `r2`. If `r2` is negative it represents `r2` rows above the
|
||||||
|
|||||||
@@ -206,9 +206,24 @@ endfunction
|
|||||||
|
|
||||||
function! tablemode#TableizeRange(...) range "{{{2
|
function! tablemode#TableizeRange(...) range "{{{2
|
||||||
let lnum = a:firstline
|
let lnum = a:firstline
|
||||||
while lnum < (a:firstline + (a:lastline - a:firstline + 1))
|
let total = (a:lastline - a:firstline + 1)
|
||||||
|
echom total
|
||||||
|
let cntr = 1
|
||||||
|
while cntr <= total
|
||||||
call s:Tableizeline(lnum, a:1)
|
call s:Tableizeline(lnum, a:1)
|
||||||
undojoin
|
undojoin
|
||||||
|
if g:table_mode_tableize_auto_border
|
||||||
|
if cntr == 1
|
||||||
|
normal! O
|
||||||
|
call tablemode#table#AddBorder('.')
|
||||||
|
normal! j
|
||||||
|
let lnum += 1
|
||||||
|
endif
|
||||||
|
normal! o
|
||||||
|
call tablemode#table#AddBorder('.')
|
||||||
|
let lnum += 1
|
||||||
|
endif
|
||||||
|
let cntr += 1
|
||||||
let lnum += 1
|
let lnum += 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
|
|||||||
@@ -109,15 +109,17 @@ function! tablemode#spreadsheet#formula#EvaluateExpr(expr, line) abort "{{{2
|
|||||||
call tablemode#spreadsheet#cell#SetCell(eval(expr), line, row, colm)
|
call tablemode#spreadsheet#cell#SetCell(eval(expr), line, row, colm)
|
||||||
else
|
else
|
||||||
let [row, line] = [1, tablemode#spreadsheet#GetFirstRow(line)]
|
let [row, line] = [1, tablemode#spreadsheet#GetFirstRow(line)]
|
||||||
while tablemode#table#IsRow(line)
|
while !s:IsFormulaLine(line)
|
||||||
let texpr = expr
|
if !tablemode#table#IsBorder(line)
|
||||||
if expr =~# '\$'
|
let texpr = expr
|
||||||
let texpr = substitute(texpr, '\$\(\d\+\)',
|
if expr =~# '\$'
|
||||||
\ '\=str2float(tablemode#spreadsheet#cell#GetCells(line, row, submatch(1)))', 'g')
|
let texpr = substitute(texpr, '\$\(\d\+\)',
|
||||||
endif
|
\ '\=str2float(tablemode#spreadsheet#cell#GetCells(line, row, submatch(1)))', 'g')
|
||||||
|
endif
|
||||||
|
|
||||||
call tablemode#spreadsheet#cell#SetCell(eval(texpr), line, row, colm)
|
call tablemode#spreadsheet#cell#SetCell(eval(texpr), line, row, colm)
|
||||||
let row += 1
|
let row += 1
|
||||||
|
endif
|
||||||
let line += 1
|
let line += 1
|
||||||
endwhile
|
endwhile
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
*table-mode.txt* Table Mode for easy table formatting
|
*table-mode.txt* Table Mode for easy table formatting
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||||
VERSION 4.7.0
|
VERSION 4.7.3
|
||||||
|
|
||||||
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/>
|
||||||
@@ -53,11 +53,10 @@ Tableize content:
|
|||||||
|
|
||||||
Move between cells :
|
Move between cells :
|
||||||
Now you can move between cells using table mode motions
|
Now you can move between cells using table mode motions
|
||||||
'<Leader>t[hjkl]' to move left | down | up | right cells respectively.
|
'[|, ]|, {|, }|' to move left | down | up | right cells respectively.
|
||||||
You can use |table-mode-map-prefix| option to define the prefix
|
The left | right motions wrap around the table and move to the next
|
||||||
mapping to be used before 'hjkl'. The left | right motions wrap around
|
| previous row after the last | first cell in the current row if one
|
||||||
the table and move to the next | previous row after the last | first
|
exists.
|
||||||
cell in the current row if one exists.
|
|
||||||
|
|
||||||
Manipulation of tables:
|
Manipulation of tables:
|
||||||
Tableize provides 3 easy ways to quickly manipulate tables.
|
Tableize provides 3 easy ways to quickly manipulate tables.
|
||||||
@@ -185,6 +184,7 @@ Overview:
|
|||||||
|table-mode-syntax| ............. Control table mode syntax
|
|table-mode-syntax| ............. Control table mode syntax
|
||||||
|table-mode-auto-align| ......... Set if the table mode should auto
|
|table-mode-auto-align| ......... Set if the table mode should auto
|
||||||
align as you type
|
align as you type
|
||||||
|
|table-mode-tableize-auto-border| Set if tableize adds row borders
|
||||||
|
|
||||||
g:loaded_table_mode *table-mode-loaded*
|
g:loaded_table_mode *table-mode-loaded*
|
||||||
Use this option to disable the plugin: >
|
Use this option to disable the plugin: >
|
||||||
@@ -355,6 +355,16 @@ g:table_mode_update_time *table-mode-update-time*
|
|||||||
let g:table_mode_update_time = 500
|
let g:table_mode_update_time = 500
|
||||||
<
|
<
|
||||||
|
|
||||||
|
g:table_mode_disable_tableize_mappings *table-mode-disable-tableize-mappings*
|
||||||
|
Disables mappings for tableize. >
|
||||||
|
let g:table_mode_disable_tableize_mappings = 0
|
||||||
|
<
|
||||||
|
*table-mode-tableize-auto-border*
|
||||||
|
g:table_mode_tableize_auto_border
|
||||||
|
Enables adding row borders to tables when created using tableize. >
|
||||||
|
let g:table_mode_tableize_auto_border = 0
|
||||||
|
<
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
MAPPINGS *table-mode-mappings*
|
MAPPINGS *table-mode-mappings*
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
|||||||
call s:SetGlobalOptDefault('table_mode_corner_corner', '|')
|
call s:SetGlobalOptDefault('table_mode_corner_corner', '|')
|
||||||
call s:SetGlobalOptDefault('table_mode_align_char', ':')
|
call s:SetGlobalOptDefault('table_mode_align_char', ':')
|
||||||
call s:SetGlobalOptDefault('table_mode_disable_mappings', 0)
|
call s:SetGlobalOptDefault('table_mode_disable_mappings', 0)
|
||||||
|
call s:SetGlobalOptDefault('table_mode_disable_tableize_mappings', 0)
|
||||||
|
|
||||||
call s:SetGlobalOptDefault('table_mode_motion_up_map', '{<Bar>')
|
call s:SetGlobalOptDefault('table_mode_motion_up_map', '{<Bar>')
|
||||||
call s:SetGlobalOptDefault('table_mode_motion_down_map', '}<Bar>')
|
call s:SetGlobalOptDefault('table_mode_motion_down_map', '}<Bar>')
|
||||||
@@ -52,6 +53,7 @@ call s:SetGlobalOptDefault('table_mode_tableize_d_map', '<Leader>T')
|
|||||||
call s:SetGlobalOptDefault('table_mode_syntax', 1)
|
call s:SetGlobalOptDefault('table_mode_syntax', 1)
|
||||||
call s:SetGlobalOptDefault('table_mode_auto_align', 1)
|
call s:SetGlobalOptDefault('table_mode_auto_align', 1)
|
||||||
call s:SetGlobalOptDefault('table_mode_update_time', 500)
|
call s:SetGlobalOptDefault('table_mode_update_time', 500)
|
||||||
|
call s:SetGlobalOptDefault('table_mode_tableize_auto_border', 0)
|
||||||
|
|
||||||
function! s:TableEchoCell() "{{{1
|
function! s:TableEchoCell() "{{{1
|
||||||
if tablemode#table#IsRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
@@ -114,13 +116,15 @@ nnoremap <silent> <Plug>(table-mode-echo-cell) :call <SID>TableEchoCell()<CR>
|
|||||||
|
|
||||||
nnoremap <silent> <Plug>(table-mode-sort) :call tablemode#spreadsheet#Sort('')<CR>
|
nnoremap <silent> <Plug>(table-mode-sort) :call tablemode#spreadsheet#Sort('')<CR>
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-tableize)')
|
if !g:table_mode_disable_tableize_mappings
|
||||||
exec "nmap" g:table_mode_tableize_map "<Plug>(table-mode-tableize)"
|
if !hasmapto('<Plug>(table-mode-tableize)')
|
||||||
exec "xmap" g:table_mode_tableize_map "<Plug>(table-mode-tableize)"
|
exec "nmap" g:table_mode_tableize_map "<Plug>(table-mode-tableize)"
|
||||||
endif
|
exec "xmap" g:table_mode_tableize_map "<Plug>(table-mode-tableize)"
|
||||||
|
endif
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-tableize-delimiter)')
|
if !hasmapto('<Plug>(table-mode-tableize-delimiter)')
|
||||||
exec "xmap" g:table_mode_tableize_d_map "<Plug>(table-mode-tableize-delimiter)"
|
exec "xmap" g:table_mode_tableize_d_map "<Plug>(table-mode-tableize-delimiter)"
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
augroup TableMode "{{{1
|
augroup TableMode "{{{1
|
||||||
|
|||||||
@@ -34,3 +34,4 @@ let g:table_mode_tableize_d_map = '<Leader>T'
|
|||||||
let g:table_mode_syntax = 1
|
let g:table_mode_syntax = 1
|
||||||
let g:table_mode_auto_align = 1
|
let g:table_mode_auto_align = 1
|
||||||
let g:table_mode_update_time = 500
|
let g:table_mode_update_time = 500
|
||||||
|
let g:table_mode_tableize_auto_border = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user