table-mode.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. *table-mode.txt* Table Mode for easy table formatting
  2. ===============================================================================
  3. Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
  4. VERSION 4.8.0
  5. Author: Dhruva Sagar <http://dhruvasagar.com/>
  6. License: MIT <http://opensource.org/licenses/MIT/>
  7. ===============================================================================
  8. CONTENTS *table-mode-contents*
  9. 1. Introduction .................... |table-mode-introduction|
  10. 2. Getting Started ................. |table-mode-getting-started|
  11. 3. Options ......................... |table-mode-options|
  12. 4. Mappings ........................ |table-mode-mappings|
  13. 5. Commands ........................ |table-mode-commands|
  14. 6. Contributing .................... |table-mode-contributing|
  15. 7. Report Issues ................... |table-mode-report-issues|
  16. ===============================================================================
  17. INTRODUCTION *table-mode-introduction*
  18. Table Mode is simple plugin that makes building tables in vim a breeze. It is
  19. inspired from tpope's auto aligning script for creating tables in vim -
  20. https://gist.github.com/tpope/287147, which in turn utilizes the Tabular
  21. Plugin.
  22. ===============================================================================
  23. GETTING STARTED *table-mode-getting-started*
  24. Create Table on the fly:
  25. Using Table Mode is dead simple. You simply start typing on a new line
  26. with the table separator - |table-mode-separator|, and you just type
  27. away! The plugin does the rest automatically for you as you type. With
  28. each additional separator you add, it aligns the table properly,
  29. without having to do anything else.
  30. Table Mode now supports gfm style tables and allows to define column
  31. alignments with the aid of placing ':' (configured using
  32. |g:table_mode_align_char|) on the table header border appropriately to
  33. align content left or right.
  34. The table mode is disabled by default and you can enter table mode
  35. using |table-mode-toggle-map| or you can also enable it permanently
  36. using |table-mode-always-active| if you wish though not recommended.
  37. Table Mode allows for creation of tables within comments, it looks at
  38. the 'commentstring' setting to identify whether the current line is
  39. commented.
  40. Tableize content:
  41. Table Mode enables conversion of delimited text into tables. Again
  42. like table creation, this is also applicable within comments.
  43. Move between cells :
  44. Now you can move between cells using table mode motions
  45. '[|, ]|, {|, }|' to move left | down | up | right cells respectively.
  46. The left | right motions wrap around the table and move to the next
  47. | previous row after the last | first cell in the current row if one
  48. exists.
  49. Manipulation of tables:
  50. Tableize provides 3 easy ways to quickly manipulate tables.
  51. 1. Cell Text Object : A text object for table cell
  52. defined by |table-mode-cell-text-object|. You can use it with an
  53. operator (d,c,y) to manipulate it easily. If you delete the cell using
  54. this, it will delete the table separator along with it so if you type
  55. out some new stuff, you will have to re-add it, which triggers a
  56. re-alignment and the table would be formatted again.
  57. 2. Delete Column : Delete an entire table column using
  58. |table-mode-delete-column-map| .
  59. 3. Delete Row : Delete an entire table row using
  60. |table-mode-delete-row-map|
  61. 4. Insert Column : Insert a table column either before the cursor
  62. using |table-mode-insert-column-before-map| or after the cusor using
  63. |table-mode-insert-column-after-map|.
  64. *table-formulas*
  65. Table Formulas:
  66. Table Mode now has support for formulas like a spreadsheet. There
  67. are 2 ways of defining formulas :
  68. You can add formulas using |:TableAddFormula| or the mapping
  69. |<Leader>tfa| defined by the option
  70. |table-mode-add-formula-map| from within a table cell, which
  71. will ask for input on the cmd-line with a 'f=' prompt. The
  72. input formula will be appended to the formula line if one
  73. exists or a new one will be created with the input formula
  74. taking the current cell as the target cell. The formula line
  75. is evaluated immediately to reflect the results.
  76. You can directly also add / manipulate formula expressions in
  77. the formula line. The formula line is a commented line right
  78. after the table, beginning with 'tmf:' (table mode formula).
  79. eg) '# tmf: $3=$2*$1'. You can add multiple formulas on the
  80. line separated with a ';' eg) '# tmf: $3=$2*$1;$4=$3/3.14'
  81. You can evaluate the formula line using |:TableEvalFormulaLine| or the
  82. mapping |<Leader>tfe| defined by the option |table-mode-expr-calc-map|
  83. *formula-expressions*
  84. Formula Expressions :
  85. Expressions are of the format '$target = formula'.
  86. The target can be of 2 forms :
  87. '$n': This matches the table column number 'n'. So the formula
  88. would be evaluated for each cell in that column and the result
  89. would be placed in it. You can use negative indice to
  90. represent column relative to the last, -1 being the last.
  91. '$n,m': This matches the table cell n,m (row, column). So in
  92. this case the formula would be evaluated and the result will
  93. be placed in this cell. You can also use negative values to
  94. refer to cells relative to the size, -1 being the last (row or
  95. column).
  96. The formula can be a simple mathematical expression involving cells
  97. which are also defined by the same format as that of the target cell.
  98. Apart from basic mathematical expressions, table mode also provides
  99. special functions 'Min', 'Max', 'CountE' (number of empty cells),
  100. 'CountNE' (number of non-empty cells), 'PercentE' (percent of empty
  101. cells), 'PercentNE' (percent of non-empty cells), 'Sum', 'Average',
  102. and 'AverageNE' (average over non-empty cells). All these functions
  103. take a range as input. A range can be of two forms :
  104. 'n:m': This represents cells in the current column from row
  105. 'n' through 'm'. If 'm' is negative it represents 'm' row
  106. above the current row (of the target cell).
  107. 'r1,c1:r2,c2': This represents cells in the table from cell
  108. r1,c1 through cell r2,c2 (row, column).
  109. Examples :
  110. $2 = $1 * $1
  111. $2 = $1 / $1,3
  112. $1,2 = $1,1 * $1,1
  113. $5,1 = Sum(1:-1)
  114. $5,3 = Sum(1,2:5,2)
  115. ===============================================================================
  116. OPTIONS *table-mode-options*
  117. Overview:
  118. |table-mode-loaded| ............. Disable the plugin.
  119. |table-mode-verbose| ............ Notify when Enabled/Disabled.
  120. |table-mode-corner| ............. Set corner character.
  121. |table-mode-separator| .......... Set separator character.
  122. |table-mode-separator-map| ...... Set separator mapping.
  123. |table-mode-fillchar| ........... Set table border fillchar character.
  124. |table-mode-header-fillchar| .... Set table header border fillchar character.
  125. |table-mode-map-prefix| ......... Set prefix for table mode commands.
  126. |table-mode-toggle-map| ......... Set table mode toggle mapping.
  127. |table-mode-always-active| ...... Set table mode to always enabled.
  128. |table-mode-delimiter| .......... Set the delimiter for Tableize.
  129. |table-mode-corner-corner| ...... Set the character to be used for
  130. extreme corners of the table border.
  131. |table-mode-align-char|.......... Set the alignment character which
  132. can be added to the table header
  133. border to control alignment of that
  134. column.
  135. |table-mode-motion-up-map| ...... Set the table motion up mapping
  136. |table-mode-motion-down-map| .... Set the table motion down mapping
  137. |table-mode-motion-left-map| .... Set the table motion left mapping
  138. |table-mode-motion-right-map| ... Set the table motion right mapping
  139. |table-mode-cell-text-object-a-map|
  140. Set the 'a' cell text object
  141. mapping
  142. |table-mode-cell-text-object-i-map|
  143. Set the 'i' cell text object
  144. mapping
  145. |table-mode-realign-map| ........ Set the realign mapping
  146. |table-mode-delete-row-map| ..... Set the delete row mapping
  147. |table-mode-delete-column-map| .. Set the delete column mapping
  148. |table-mode-insert-column-before-map|
  149. Set the insert column before the
  150. cursor mapping
  151. |table-mode-insert-column-after-map|
  152. Set the insert column after the
  153. cursor mapping
  154. |table-mode-add-formula-map| .... Set the add formula mapping
  155. |table-mode-eval-formula-map| ... Set the eval formula mapping
  156. |table-mode-echo-cell-map| ...... Set the echo cell mapping
  157. |table-mode-sort-map| ........... Set the table sort mapping
  158. |table-mode-syntax| ............. Control table mode syntax
  159. |table-mode-auto-align| ......... Set if the table mode should auto
  160. align as you type
  161. |table-mode-tableize-auto-border| Set if tableize adds row borders
  162. |table-mode-ignore-align| ....... Set to ignore alignment characters
  163. g:loaded_table_mode *table-mode-loaded*
  164. Use this option to disable the plugin: >
  165. let g:loaded_table_mode = 1
  166. <
  167. g:table_mode_verbose *table-mode-verbose*
  168. Use this option to disable notifications: >
  169. let g:table_mode_verbose = 0
  170. <
  171. g:table_mode_corner *table-mode-corner*
  172. Use this option to define the table corner character: >
  173. let g:table_mode_corner = '+'
  174. <
  175. Or only in the current buffer: >
  176. let b:table_mode_corner = '+'
  177. <
  178. g:table_mode_separator *table-mode-separator*
  179. Use this option to define the table column separator character: >
  180. let g:table_mode_separator = '|'
  181. <
  182. This option also defines the trigger to be used to start creating a
  183. table row in insert mode.
  184. g:table_mode_separator_map *table-mode-separator-map*
  185. Use this option to define the mapping to be used for the table separator. >
  186. let g:table_mode_separator_map = '<Bar>'
  187. <
  188. g:table_mode_fillchar *table-mode-fillchar*
  189. Use this option to define the table border fill character: >
  190. let g:table_mode_fillchar = '-'
  191. <
  192. g:table_mode_header_fillchar *table-mode-header-fillchar*
  193. Use this option to define the table header border fill character: >
  194. let g:table_mode_fillchar = '-'
  195. <
  196. g:table_mode_map_prefix *table-mode-map-prefix*
  197. Use this option to define the table mode mapping prefix that will be
  198. prefixed for all other table mode mappings. >
  199. let g:table_mode_map_prefix = '<Leader>t'
  200. <
  201. g:table_mode_toggle_map *table-mode-toggle-map*
  202. Use this option to define the mapping for toggling the table mode: >
  203. let g:table_mode_toggle_map = 'm'
  204. <
  205. Read |table-mode-mappings-toggle| for more info.
  206. NOTE you will need to use the |table-mode-map-prefix| before this to
  207. get the desired effect.
  208. g:table_mode_always_active *table-mode-always-active*
  209. Use this option to permanently enable the table mode: >
  210. let g:table_mode_always_active = 0
  211. <
  212. This will trigger table creation once you type the
  213. |table-mode-separator| as long as it's the first character on
  214. the line, which can be annoying. I recommend you to instead use the
  215. |table-mode-mappings-toggle| or |table-mode-commands-toggle| to toggle
  216. the table mode or |table-mode-commands-enable| to enable and
  217. |table-mode-commands-disable| to disable mode when needed.
  218. g:table_mode_delimiter *table-mode-delimiter*
  219. Use this option to define the delimiter which used by
  220. |table-mode-commands-tableize| >
  221. let g:table_mode_delimiter = ','
  222. <
  223. g:table_mode_corner_corner *table-mode-corner-corner*
  224. Use this option to define the character to be used for the extreme
  225. corners of the table border. >
  226. let g:table_mode_corner_corner = '|'
  227. <
  228. Or only in the current buffer: >
  229. let b:table_mode_corner_corner = '|'
  230. <
  231. g:table_mode_align_char *table-mode-align-char*
  232. Use this option to define the character to be used for defining
  233. alignments for columns in the table header border. >
  234. let g:table_mode_align_char = ':'
  235. <
  236. g:table_mode_disable_mappings *table-mode-disable-mappings*
  237. Set this to true to disable all mappings. >
  238. let g:table_mode_disable_mappings = 1
  239. <
  240. g:table_mode_motion_up_map *table-mode-motion-up-map*
  241. Set this to configure the mapping to move up a cell vertically. >
  242. let g:table_mode_motion_up_map = '{<Bar>'
  243. <
  244. g:table_mode_motion_down_map *table-mode-motion-down-map*
  245. Set this to configure the mapping to move down a cell vertically. >
  246. let g:table_mode_motion_down_map = '}<Bar>'
  247. >
  248. g:table_mode_motion_left_map *table-mode-motion-left-map*
  249. Set this to configure the mapping to move to the left cell. >
  250. let g:table_mode_motion_left_map = '[<Bar>'
  251. >
  252. g:table_mode_motion_right_map *table-mode-motion-right-map*
  253. Set this to configure the mapping to move to the right cell. >
  254. let g:table_mode_motion_right_map = ']<Bar>'
  255. >
  256. g:table_mode_cell_text_object_a_map *table-mode-cell-text-object-a-map*
  257. Set this to configure the mapping to define the text object for around
  258. cell object. >
  259. let g:table_mode_cell_text_object_a_map = 'a<Bar>'
  260. >
  261. g:table_mode_cell_text_object_i_map *table-mode-cell-text-object-i-map*
  262. Set this to configure the mapping to define the text object for inner
  263. cell object. >
  264. let g:table_mode_cell_text_object_i_map = 'i<Bar>'
  265. >
  266. g:table_mode_realign_map *table-mode-realign-map*
  267. Set this to configure the mapping for table realign. >
  268. let g:table_mode_realign_map = '<Leader>tr'
  269. >
  270. g:table_mode_delete_row_map *table-mode-delete-row-map*
  271. Set this to configure the mapping for deleting a table row. >
  272. let g:table_mode_delete_row_map = '<Leader>tdd'
  273. >
  274. g:table_mode_delete_column_map *table-mode-delete-column-map*
  275. Set this to configure the mapping for deleting a table column. >
  276. let g:table_mode_delete_column_map = '<Leader>tdc'
  277. >
  278. g:table_mode_insert_column_before_map *table-mode-insert-column-before-map*
  279. Set this to configure the mapping for inserting a table column before
  280. the cursor. >
  281. let g:table_mode_insert_column_before_map = '<Leader>tiC'
  282. >
  283. g:table_mode_insert_column_after_map *table-mode-insert-column-after-map*
  284. Set this to configure the mapping for inserting a table column after
  285. the cursor. >
  286. let g:table_mode_insert_column_after_map = '<Leader>tic'
  287. >
  288. g:table_mode_add_formula_map *table-mode-add-formula-map*
  289. Set this to configure the mapping for adding a formula for a table
  290. cell. >
  291. let g:table_mode_add_formula_map = '<Leader>tfa'
  292. >
  293. g:table_mode_eval_formula_map *table-mode-eval-formula-map*
  294. Set this to configure the mapping for evaluating the formula line. >
  295. let g:table_mode_eval_formula_map = '<Leader>tfe'
  296. >
  297. g:table_mode_echo_cell_map *table-mode-echo-cell-map*
  298. Set this to configure the mapping for echoing the tablemode
  299. representation of the current cell. >
  300. let g:table_mode_echo_cell_map = '<Leader>t?'
  301. >
  302. g:table_mode_sort_map *table-mode-sort-map*
  303. Set this to configure the mapping for sorting the table mode by
  304. current column. >
  305. let g:table_mode_sort_map = '<Leader>ts'
  306. >
  307. g:table_mode_tableize_map *table-mode-tableize-map*
  308. Set this to configure the mapping for converting the visual selection
  309. to a table. >
  310. let g:table_mode_tableize_map = '<Leader>tt'
  311. >
  312. g:table_mode_tableize_d_map *table-mode-tableize-d-map*
  313. Set this to configure the mapping for converting the visual selection
  314. to a table, asking the user for a delimiter. >
  315. let g:table_mode_tableize_d_map = '<Leader>T'
  316. >
  317. g:table_mode_syntax *table-mode-syntax*
  318. Control whether table mode should define table syntax definitions or
  319. not. >
  320. let g:table_mode_syntax = 1
  321. <
  322. g:table_mode_auto_align *table-mode-auto-align*
  323. Set if the table mode should auto align as you type when table mode is
  324. active. >
  325. let g:table_mode_auto_align = 1
  326. <
  327. g:table_mode_update_time *table-mode-update-time*
  328. Set the value of updatetime to be used when table mode is active,
  329. used in combination with |table-mode-auto-align|. >
  330. let g:table_mode_update_time = 500
  331. <
  332. g:table_mode_disable_tableize_mappings *table-mode-disable-tableize-mappings*
  333. Disables mappings for tableize. >
  334. let g:table_mode_disable_tableize_mappings = 0
  335. <
  336. *table-mode-tableize-auto-border*
  337. g:table_mode_tableize_auto_border
  338. Enables adding row borders to tables when created using tableize. >
  339. let g:table_mode_tableize_auto_border = 0
  340. <
  341. *table-mode-ignore-align*
  342. g:table_mode_ignore_align
  343. If enabled, ignores alignment characters on the header border and always
  344. left aligns. >
  345. let g:table_mode_ignore_align = 0
  346. <
  347. ===============================================================================
  348. MAPPINGS *table-mode-mappings*
  349. *table-mode-mappings-prefix*
  350. <Leader>t This is a prefix defined by the option |table-mode-map-prefix|
  351. used before all other table mode commands.
  352. *table-mode-mappings-toggle*
  353. <Leader>tm Toggle table mode for the current buffer. You can change this
  354. using the |toggle-mode-options-toggle-map| option.
  355. NOTE This is applicable only if |table-mode-always-active| is
  356. not set.
  357. *table-mode-mappings-trigger*
  358. | Trigger table creation in table mode. You can change this
  359. using the |toggle-mode-options-separator| option.
  360. <Leader>tt Triggers |table-mode-commands-tableize| on the visually
  361. selected content.
  362. *table-mode-mappings-op-trigger*
  363. <Leader>T Triggers |table-mode-commands-tableize| on the visually
  364. selected asking for user to input the delimiter.
  365. *table-mode-mappings-realign*
  366. <Leader>tr Realigns table columns
  367. <Leader>t? Echo the current table cells representation for defining
  368. formulas.
  369. *table-mode-mappings-motions*
  370. [| Move to previous cell
  371. ]| Move to next cell
  372. {| Move to the cell above
  373. }| Move to the cell below
  374. *table-mode-mappings-delete-row*
  375. <Leader>tdd Delete the entire table row you are on or multiple rows using
  376. a [count]. You can change this using |table-mode-delete-row-map|
  377. option.
  378. *table-mode-mappings-delete-column*
  379. <Leader>tdc Delete entire table column you are within. You can preceed it
  380. with a [count] to delete multiple columns to the right. You
  381. can change this using |table-mode-delete-column-map| option.
  382. *table-mode-mappings-insert-column-before*
  383. <Leader>tiC Insert a table column before the column you are within. You can
  384. preceed it with a [count] to insert multiple columns. You can
  385. change this using |table-mode-insert-column-before-map| option.
  386. *table-mode-mappings-insert-column-after*
  387. <Leader>tic Insert a table column after the column you are within. You can
  388. preceed it with a [count] to insert multiple columns. You can
  389. change this using |table-mode-insert-column-after-map| option.
  390. *table-mode-mappings-add-formula*
  391. <Leader>tfa Add a fomula for the current table cell. This invokes
  392. |TableAddFormula| command.
  393. *table-mode-mappings-evaluate-formula-line*
  394. <Leader>tfe Evaluate the formula line which is a commented line right
  395. after the table beginning with 'tmf:'. If one exists this
  396. would evaluate the formula line and update the table
  397. accordingly. This invokes the |TableEvalFormulaLine| command.
  398. *table-mode-mappings-sort-column*
  399. <Leader>ts Sort a column under the cursor. This invokes |TableSort|
  400. || Expands to a header border. You can change this by changing
  401. |table-mode-separator| option. You can change the character to
  402. be used for the extreme corners of the border by changing
  403. |table-mode-corner-corner| option.
  404. ===============================================================================
  405. COMMANDS *table-mode-commands*
  406. *:TableModeToggle*
  407. *table-mode-:TableModeToggle*
  408. :TableModeToggle
  409. Toggles the table mode. Same effect as |toggle-mode-mappings-toggle|.
  410. NOTE this is applicable only if |table-mode-always-active| is
  411. not set.
  412. *:TableModeEnable*
  413. *table-mode-:TableModeEnable*
  414. :TableModeEnable
  415. Enables Table Mode.
  416. NOTE this is applicable only if |table-mode-always-active| is
  417. not set.
  418. *:TableModeDisable*
  419. *table-mode-:TableModeDisable*
  420. :TableModeDisable
  421. Disables Table Mode.
  422. NOTE this is applicable only if |table-mode-always-active| is
  423. not set.
  424. *:Tableize*
  425. *table-mode-:Tableize*
  426. :Tableize
  427. This converts the current line into a table if it consists of
  428. |table-mode-delimiter|. This accepts a range, without which it
  429. applies on the current line.
  430. This accepts a {pattern} similar to Tabular which defines the
  431. delimiter. eg.) >
  432. :Tableize/;
  433. <
  434. The above command will Tableize using ';' as the delimiter.
  435. NOTE this is optional, by default without the expression it will
  436. tableize the content using |table-mode-delimiter| as the delimiter.
  437. *:TableModeRealign*
  438. *table-mode-:TableModeRealign*
  439. :TableModeRealign
  440. This command triggers |table-mode-mappings-realign|
  441. *:TableAddFormula*
  442. *table-mode-:TableAddFormula*
  443. :TableAddFormula
  444. This command is for defining a formula for the current table cell. It
  445. takes input on the cmd-line with a 'f=' prompt and appends it to the
  446. formula line if it exists or adds a new formula line with the
  447. expression using the current cell as the target and the input formula.
  448. *:TableEvalFormulaLine*
  449. *table-mode-:TableEvalFormulaLine*
  450. :TableEvalFormulaLine
  451. This command when invoked from anywhere within the table or directly
  452. on the formula line evaluates it and updates the table accordingly.
  453. *:TableSort*
  454. *table-mode-:TableSort*
  455. :TableSort[!] [i][u][r][n][x][o]
  456. This command sorts column under the cursor and inherits the same flags
  457. as the |:sort| command.
  458. With [!] the order is reversed.
  459. ===============================================================================
  460. CONTRIBUTING *table-mode-contributing*
  461. If you want to take a stab at it, by all means, send me a pull request on
  462. Github (http://github.com/dhruvasagar/vim-table-mode) or get in touch with me
  463. directly via e-mail at dhruva 'dot' sagar 'at' gmail.com.
  464. ===============================================================================
  465. REPORT ISSUES *table-mode-report-issues*
  466. If you discover any issues, please report them at
  467. http://github.com/dhruvasagar/vim-table-mode/issues.