I'm using Prettier to automatically reformat JavaScript (well, TypeScript, but same deal in this situation) source-code.
It enforces a comment-style like this, with leading spaces replaced with ·
:
···/**
····*·Foo bar baz,
····*·something something!
····*/
Note that in a three-space width, the *
is centered. This is contrary to what Vim likes to do with the default 'comments
' setting of s1:/*,mb:*,ex:*/
. For example, when typing exactly the keys <Space><Space><Space>/* test<CR>test2<CR>|
, you end up with the following:
/*
* test
* test2
* |
This wouldn't be a huge problem, as I can depend on Prettier to undo that hot mess when it reformats the source-code. However, what is a huge problem, is that this screws up the 'textwidth'
: a line that is within 'tw'
when the asterisk is misaligned can become outside the 'tw'
once reformatted to align the asterisks.
To fix this, I've attempted adding the whitespace to the 'comments'
setting, as described in :help option-backslash
and :help 'comments'
:
:set comments=s1:/*,mb:\ *\ ,ex:\ */,://,b:#,:%,:XCOMM,n:>,fb:-
Unfortunately, not only does this not work as expected, but it completely breaks the fo+=j
line-joining behaviour — the *
gets retained when joining comment-lines.
How can I use Vim to write comments within a fixed text-width, while also using Prettier?