4 ms·
My editor (vim) will warn me with a loud visual red block for any non ascii char outside a string literal. But I do not think that is enough. Compiler and inter
by kuon 5y ago
My editor (vim) will warn me with a loud visual red block for any non ascii char outside a string literal. But I do not think that is enough. Compiler and interpreter must be more strict.
- jrochkind1 5y agoI'm surprised VS Code doesn't at least have that option. (Or does it?)
- myfonj 5y agoIt has `editor.renderControlCharacters` but only recently started displaying few dangerous previously invisible ones (directional overrides) natively [1], but besides that you had to use extension that adds highlights for non-ascii non-whitelisted [2] or predefined [3] characters. [1] https://github.com/microsoft/vscode/issues/116939 https://github.com/microsoft/vscode/issues/116939 [2] https://marketplace.visualstudio.com/items?itemName=nachocab.highlight-dodgy-characters https://marketplace.visualstudio.com/items?itemName=nachocab... [3] https://marketplace.visualstudio.com/items?itemName=nhoizey.gremlins https://marketplace.visualstudio.com/items?itemName=nhoizey....
- tomxor 5y agoMind sharing the relevant config line? I thought this was default but just realised it only does the <FFFF> thing when there is no printable glyph available. Allowing printable unicode in strings seems like a nice balance if it can be done reliably.
- fatheart 5y agoAfter seeing this thread I added the following to my vimrc: highlight link NonASCII Error autocmd Syntax * :syntax match NonASCII "[^\d0-\d127]" Obviously haven't been using it long, and I'm not confident enough in my vim knowledge to vouch for its correctness, but it works in the limited amount of scenarios I tested so far.
- kuon 5y agoSure: fun! HighlightNonAscii() if &ft =~ 'markdown\|text' return endif syntax match nonascii "[^\x00-\x7F]" highlight nonascii guibg=#ff2232 guifg=#000000 endfun autocmd BufEnter * call HighlightNonAscii() Your version might depend on your frontend (gui, terminal...). And you might want to filter more file types.
- gpvos 5y agoThat's not the default vim configuration though.