File tree Expand file tree Collapse file tree 4 files changed +74
-1
lines changed Expand file tree Collapse file tree 4 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,27 @@ The following options control which syntax extensions will be turned on. They ar
349
349
350
350
let g:vim_markdown_edit_url_in = 'tab'
351
351
352
+ ### Borderless tables
353
+
354
+ - ` g:vim_markdown_borderless_table `
355
+
356
+ Add support for borderless tables, such as:
357
+ ```
358
+ header 1|header 2
359
+ --|--
360
+ data 1|data 2
361
+ ```
362
+ if set to `1`:
363
+
364
+ let g:vim_markdown_borderless_table = 1
365
+
366
+ the table would be formatted as usual:
367
+ ```
368
+ | header 1 | header 2 |
369
+ |----------|----------|
370
+ | data 1 | data 2 |
371
+ ```
372
+
352
373
## Mappings
353
374
354
375
The following work on normal and visual modes:
Original file line number Diff line number Diff line change @@ -490,6 +490,30 @@ Change how to open new files ~
490
490
>
491
491
let g:vim_markdown_edit_url_in = 'tab'
492
492
<
493
+ -------------------------------------------------------------------------------
494
+ *vim-markdown-support-borderless-tables*
495
+ Support borderless tables ~
496
+
497
+ *g:vim_markdown_borderless_table*
498
+ - 'g:vim_markdown_borderless_table'
499
+
500
+ Add support for borderless tables, such as:
501
+ >
502
+ header 1|header 2
503
+ --|--
504
+ data 1|data 2
505
+ <
506
+ if set to 1:
507
+ >
508
+ let g:vim_markdown_borderless_table = 1
509
+ <
510
+ the table would be formatted as usual:
511
+ >
512
+ | header 1 | header 2 |
513
+ |----------|----------|
514
+ | data 1 | data 2 |
515
+ <
516
+
493
517
===============================================================================
494
518
*vim-markdown-mappings*
495
519
Mappings ~
Original file line number Diff line number Diff line change @@ -538,6 +538,19 @@ endfunction
538
538
"
539
539
function ! s: TableFormat ()
540
540
let l: pos = getpos (' .' )
541
+
542
+ if get (g: , ' vim_markdown_borderless_table' , 0 )
543
+ " add `|` to the beginning of the line if it isn't present
544
+ normal ! {
545
+ call search (' |' )
546
+ execute ' silent .,'' }s/\v^(\s{0,})\|?([^\|])/\1|\2/e'
547
+
548
+ " add `|` to the end of the line if it isn't present
549
+ normal ! {
550
+ call search (' |' )
551
+ execute ' silent .,'' }s/\v([^\|])\|?(\s{0,})$/\1|\2/e'
552
+ endif
553
+
541
554
normal ! {
542
555
" Search instead of `normal! j` because of the table at beginning of file edge case.
543
556
call search (' |' )
@@ -765,7 +778,7 @@ endif
765
778
command ! - buffer -range =% HeaderDecrease call s: HeaderDecrease (<line1> , <line2> )
766
779
command ! - buffer -range =% HeaderIncrease call s: HeaderDecrease (<line1> , <line2> , 1 )
767
780
command ! - buffer -range =% SetexToAtx call s: SetexToAtx (<line1> , <line2> )
768
- command ! - buffer TableFormat call s: TableFormat ()
781
+ command ! - buffer - range TableFormat call s: TableFormat ()
769
782
command ! - buffer Toc call s: Toc ()
770
783
command ! - buffer Toch call s: Toc (' horizontal' )
771
784
command ! - buffer Tocv call s: Toc (' vertical' )
Original file line number Diff line number Diff line change @@ -68,3 +68,18 @@ Expect (preserve colons to align text):
68
68
| left | right | center | |
69
69
|:-----|------:|:------:|:--|
70
70
| left | right | center | |
71
+
72
+ Given markdown (borderless table);
73
+ left |right| center
74
+ :- | --: |:---:
75
+ left |right| center
76
+
77
+ Execute (format borderless table):
78
+ let g:vim_markdown_borderless_table = 1
79
+ TableFormat
80
+ unlet g:vim_markdown_borderless_table
81
+
82
+ Expect (table with borders):
83
+ | left | right | center |
84
+ |:-----|------:|:------:|
85
+ | left | right | center |
You can’t perform that action at this time.
0 commit comments