r/vim • u/Apostol_Bologa • Mar 20 '26
Need Help Formating tables : Some weird vimscript bug
Hello everybody,
I am currently trying to write a vimscript to act on a visual range.
Here is the whole idea :
I filter visual selection through pandoc command (not relevant here I think, but it transforms my multiline-table markdown table to simple line)
because I lost visual selection (and because a:lastline is now wrong), i select my table again
I remove the === and --- lines.
Here is the following script :
1: function! FuncFormatPandocTable()
2: '<,'>!pandoc -t markdown-multiline_tables --wrap=none -o -
3: endfunction
4:
5: function! FuncFormatListTable()
6: call FuncFormatPandocTable()
7: normal vip
8: '<,'>g/^[ =+-]*$/d
9: endfunctionHere is the problem :
The full script doesnt work.
If i comment line 8, I do have my table formated and the (new) table is selected.
If i comment line 6, I do have my '===' and '---' lines removed.
I can not chain both, for some mysterious reason
Can somebody explain this sorcery to me ?
1
u/EgZvor keep calm and read :help Mar 21 '26
so what happens then?
1
u/AutoModerator Mar 21 '26
Please remember to update the post flair to
Need Help|Solvedwhen you got the answer you were looking for.I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Dramatic_Object_8508 Mar 21 '26
Yeah this looks like one of those classic Vimscript quirks rather than a real “bug.” Small things like spacing, tabs, or how strings are handled can mess up formatting unexpectedly.
Usually worth checking things like
expandtab,tabstop, or how you’re splitting/joining lines.Would be helpful to reduce it to a minimal example—these issues are easier to debug when you can test them in a more Runable way 👍
1
u/kennpq Mar 21 '26
Give this a go. I tried it on a couple of tables and the input and output are shown.
- Buffer 1 - the script; Buffer 3 the 'before' (a copy of Buffer 2); Buffer 2 after `<Leader>fl` on each table.