0

To reformat Markdown tables, I use the following sequence of external commands (e.g. after visually selecting my table lines):

:<,>! sed 's/[[:space:]]\{1,\}\|/\#\|/g'
:<,>! column -t -s '\#'

The first command prefixes each | (Markdown column delimiter) with a #. The second command creates aligned columns using # as delimiter and removes it.

I also managed to combine those in a single command:

:<,>! sed 's/[[:space:]]\{1,\}\|/\#\|/g' | column -t -s '\#'

Now, I would like to create the corresponding custom MDTableFormat command somewhere in my vimrc file:

command! -range MDTableFormat ...

but I can't find the proper syntax for this.

1 Answer 1

1

This syntax worked for me:

command! -range MDTableFormat <line1>,<line2>! sed 's/[[:space:]]\{1,\}\|/\#\|/g' | column -t -s '\#'

Reading the documentation, I falsely assumed that -range was enough and <line1>,<line2> were placeholders for you to explicitly specify on which lines you wanted the command to apply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.