vscode Formatter for deleting control character.
A formatter that deletes the control characters contained in an open document. The control characters to be deleted by default are as follows:
/[\u0000]|[\u0001]|[\u0002]|[\u0003]|[\u0004]|[\u0005]|[\u0006]|[\u0007]|[\u0008]|[\u000b]|[\u000c]|[\u000d]|[\u000e]|[\u000f]|[\u0010]|[\u0011]|[\u0012]|[\u0013]|[\u0014]|[\u0015]|[\u0016]|[\u0017]|[\u0018]|[\u0019]|[\u001a]|[\u001b]|[\u001c]|[\u001d]|[\u001e]|[\u001f]|[\u001c]|[\u007f]/gm
It is also possible to define the regular expression pattern as a user.
This extenstion was created to cope with the problem that the backspace control character in the Issue below:
- Backspace can not erase the last one character during Chinese/Japanese IME conversion (macOS) · Issue #24981 · Microsoft/vscode
- 714771 - Two backspaces required to delete last character in webview input - chromium - Monorail
Install extensions,
- Execute the
Format Document
command, - If
"editor.formatOnSave": true
is set, invoke on save (⌘S) - If
"editor.formatOnType": true
is set, invoked onEnter (line break)
or;
input
In either case, the action is triggered and the control character is deleted.
The Format Document
command and editor.formatOnSave
, editor.formatOnType
will trigger all formatter defined with * FormattingEditProvide
.
Therefore, if you want to use them as a single function without using them, please use the Remove control characters
command.
If there is a problem with the default control character, you can customize it using the ctrlchar-remover.pattern
setting.
Delete the character that matches the pattern of the specified regular expression. (If you specify \u0008
, you must escape with\
, like \\u0008
)
ctrlchar-remover.pattern
:
Example deletion of backspace (\u0008)
only:
"ctrlchar-remover.pattern": "[\\u0008]"
Example of deletion of backspace (\u0008)
and Line Feed (\u000a)
:
"ctrlchar-remover.pattern": "[\\u0008]|[\\u000a]"
ATTENTION: Of course, you can also specify patterns other than control characters.
- Can be visualized by
Toggle Control Characters
command orView -> control character switching
. - To handle with the basic function of VS Code without using this extension, input
[\b]
for search by typing⌥⌘F
and using.* (⌥⌘R)
, To search backspaces control character in the document. In addition, you can delete it by pressingReplace All (⌥⌘Enter)
. - if
afterDelay
is set as the value offiles.autoSave
, the format will not be applied during auto save.
- https://en.wikipedia.org/wiki/Control_Pictures
- https://en.wikipedia.org/wiki/Control_character
- https://en.wikipedia.org/wiki/C0_and_C1_control_codes
- https://unicode-table.com/en/
- jrieken/vscode-formatter-sample
- ThisIsManta/vscode-stylus-supremacy
- HookyQR/VSCodeBeautify
- esbenp/prettier-vscode
This extension is applied to all language modes because language mode is not specified.
If you want to enable it only in a specific language mode, enclosing it with "[language-mode]":{}
enables it only for the specified language-mode
.
Below is an example that applies only to Markdown
mode:
"[markdown]": {
"editor.wordWrap": "on",
"editor.quickSuggestions": false,
"editor.formatOnSave": true,
"editor.formatOnType": true
}
In order for formatOnType
to work, it is necessary to input a trigger character.
Yes - format on type only works on certain trigger characters. Extension define what those characters are, for instance TypeScript uses \n, ;, and }.