Home

Awesome

VIM Table Mode v4.8.1 Build

An awesome automatic table creator & formatter allowing one to create neat tables as you type.

Getting Started

Installation

<a href="https://www.danielfranklin.id.au/vim-8-package-management/">Vim 8+ native package manager</a>

clone into .vim/pack/plugins/start (the plugins folder can have any name)

Add packloadall in your ~/.vimrc.

<a href="https://github.com/Shougo/neobundle.vim">NeoBundle</a>

Add NeoBundle 'dhruvasagar/vim-table-mode' to your ~/.vimrc.

<a href="https://github.com/tpope/vim-pathogen">pathogen.vim</a>

Add a git submodule for your plugin:

$ cd ~/.vim
$ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-mode

Copy all files under autoload/, plugin/, and doc/ to respective ~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX, or vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and restart Vim.

<a href="https://github.com/junegunn/vim-plug">vim-plug</a>

Add Plug 'dhruvasagar/vim-table-mode' to your ~/.vimrc.

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>).

Tip: You can use the following to quickly enable / disable table mode in insert mode by using || or __:

function! s:isAtStartOfLine(mapping)
  let text_before_cursor = getline('.')[0 : col('.')-1]
  let mapping_pattern = '\V' . escape(a:mapping, '\')
  let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
  return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
endfunction

inoreabbrev <expr> <bar><bar>
          \ <SID>isAtStartOfLine('\|\|') ?
          \ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
inoreabbrev <expr> __
          \ <SID>isAtStartOfLine('__') ?
          \ '<c-o>:silent! TableModeDisable<cr>' : '__'

Enter the first line, delimiting columns by the | symbol. The plugin reacts by inserting spaces between the text and the separator if you omit them:

| name | address | phone |

In the second line (without leaving Insert mode), enter | twice. The plugin will write a properly formatted horizontal line:

| name | address | phone |
|------+---------+-------|

When you enter the subsequent lines, the plugin will automatically adjust the formatting to match the text you’re entering every time you press |:

| name       | address | phone |
|------------+---------+-------|
| John Adams |

Go on until the table is ready:

| name            | address                  | phone      |
|-----------------+--------------------------+------------|
| John Adams      | 1600 Pennsylvania Avenue | 0123456789 |
|-----------------+--------------------------+------------|
| Sherlock Holmes | 221B Baker Street        | 0987654321 |
|-----------------+--------------------------+------------|

Then you can return to the first line and above it enter ||:

|-----------------+--------------------------+------------|
| name            | address                  | phone      |
|-----------------+--------------------------+------------|
| John Adams      | 1600 Pennsylvania Avenue | 0123456789 |
|-----------------+--------------------------+------------|
| Sherlock Holmes | 221B Baker Street        | 0987654321 |
|-----------------+--------------------------+------------|

Corner separators are adjustable:

For Markdown-compatible tables use

let g:table_mode_corner='|'


|-----------------|--------------------------|------------|
| name            | address                  | phone      |
|-----------------|--------------------------|------------|
| John Adams      | 1600 Pennsylvania Avenue | 0123456789 |
|-----------------|--------------------------|------------|
| Sherlock Holmes | 221B Baker Street        | 0987654321 |
|-----------------|--------------------------|------------|

To get ReST-compatible tables use

let g:table_mode_corner_corner='+'
let g:table_mode_header_fillchar='='


+-----------------+--------------------------+------------+
| name            | address                  | phone      |
+=================+==========================+============+
| John Adams      | 1600 Pennsylvania Avenue | 0123456789 |
+-----------------+--------------------------+------------+
| Sherlock Holmes | 221B Baker Street        | 0987654321 |
+-----------------+--------------------------+------------+

Markdown and ReST filetypes have automatically configured corners.

If you wish to override their configurations, it should be done in an after plugin, for example :

In a $VIM/after/ftplugin/markdown/custom.vim you can add the following :

let b:table_mode_corner='+'

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 g:table_mode_align_char option.

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 it using :TableModeRealign or using the default mapping <kbd><Leader>tr</kbd> (defined by the option g:table_mode_relign_map).

Formatting existing content into a table

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 typing on the fly, formatting existing content into a table is equally simple. You can visually select multiple lines and call :Tableize on it. Alternatively, the mapping <kbd><Leader>tt</kbd> can be used (defined by the option g:table_mode_tableize_map). This converts CSV (Comma-separated Values) data into a table.

If however you wish to use a different delimiter, you can use the command :Tableize/{pattern} in a similar fashion as you tabulate (e.g. :Tableize/; uses ';' as the delimiter) or use the mapping <kbd><Leader>T</kbd> (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.

:Tableize also accepts a range. Call it by giving 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 next [count] lines in standard vim style.

Moving around

Now you can move between cells using table mode motions <kbd>[|</kbd>, <kbd>]|</kbd>, <kbd>{|</kbd> & <kbd>}|</kbd> to move left | right | up | down cells respectively. The left | right motions wrap around the table and move to the next | previous row after the last | first cell in the current row if one exists.

Manipulating Table

Highlight cells based on content

You can highlight cells based on content by setting let g:table_mode_color_cells : - cells starting with yes will use the yesCell highlight group. - cells starting with no will use the noCell highlight group. - cells starting with ? will use the maybeCell hightlight group.

You can overwrite any highlight group. For exemple use hi yesCell ctermfg=2 to remove the background color.

Advanced Usage: Spreadsheet Capabilities

Table Formulas

Table Mode now has support for formulas like a spreadsheet. There are 2 ways of defining formulas :

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) from anywhere inside the table or while on the formula line.

NOTE: You can now use the mapping <kbd><Leader>t?</kbd>

Formula Expressions

Expressions are of the format $target = formula.

Demo

<a href="http://www.youtube.com/watch?v=9lVQ0VJY3ps"><img src="https://raw.github.com/axil/vim-table-mode/master/youtube.png"/></a>

Change Log

See <a href="https://github.com/dhruvasagar/vim-table-mode/blob/master/CHANGELOG.md"> CHANGELOG.md </a>

Contributing

Reporting an Issue :

Contributing to code :

Credit

I must thank Tim Pope for inspiration. The initial concept was created by him named <a href="https://gist.github.com/tpope/287147">cucumbertables.vim</a>.

Also a shout out to godlygeek who developed the incredible <a href="http://github.com/godlygeek/tabular">Tabular</a> plugin.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute]. <a href="https://github.com/dhruvasagar/vim-table-mode/graphs/contributors"><img src="https://opencollective.com/vim-table-mode/contributors.svg?width=890&button=false" /></a>

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

<a href="https://opencollective.com/vim-table-mode"><img src="https://opencollective.com/vim-table-mode/individuals.svg?width=890"></a>

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

<a href="https://opencollective.com/vim-table-mode/organization/0/website"><img src="https://opencollective.com/vim-table-mode/organization/0/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/1/website"><img src="https://opencollective.com/vim-table-mode/organization/1/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/2/website"><img src="https://opencollective.com/vim-table-mode/organization/2/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/3/website"><img src="https://opencollective.com/vim-table-mode/organization/3/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/4/website"><img src="https://opencollective.com/vim-table-mode/organization/4/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/5/website"><img src="https://opencollective.com/vim-table-mode/organization/5/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/6/website"><img src="https://opencollective.com/vim-table-mode/organization/6/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/7/website"><img src="https://opencollective.com/vim-table-mode/organization/7/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/8/website"><img src="https://opencollective.com/vim-table-mode/organization/8/avatar.svg"></a> <a href="https://opencollective.com/vim-table-mode/organization/9/website"><img src="https://opencollective.com/vim-table-mode/organization/9/avatar.svg"></a>