How can I make U+200B character or delete them in using sublime text 3. I found http://pastebin.com/ehWxNfMe but I am not sure how to use it
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
The following will work in Sublime Text 2 and 3. However, due to some issues discussed later, it has the potential to block the program when editing large files, and/or on slow computers. A Sublime Text 3-specific version using an asynchronous method is at the bottom.
Open a new file in Sublime, and set its syntax to Python. Paste the following into it:
Save the file in your
Packages/User
directory asshow_zero_width_space.py
, and it should start working immediately. Basically what it does is every time the current view is modified, it searches through it character by character looking for the zero-width space character,U+200B
. If it finds one, it adds the location to a list and keeps looking until it reaches the end of the file. Then, if any characters were found, they are highlighted according to theinvalid
scope in your theme. Once highlighted, they can be selected and deleted.Since this plugin runs every single time the view is modified (after every keystroke, for example), it has the potential to really slow down Sublime, especially for large files. Therefore, if you are working on files you know are clean, simply rename the plugin to
show_zero_width_space.py.old
and make sure you delete any file namedshow_zero_width_space.pyc
, and it won't be active. For a Sublime Text 3-specific workaround, see below.Sublime Text 3-specific version
The Sublime Text 3 API for
EventListener
now includes anon_modified_async()
method, in keeping with the fact that all ST3 functions are now thread-safe. This runs the code asynchronously, in a non-blocking manner, so Sublime shouldn't be slowed down by it. The new plugin is as follows:The easiest way to delete zero width spaces in Sublime Text is using the search and replace functionality:
Ctrl + h
(Alt + Cmd + f
for Mac )Alt + r
(Alt + Cmd + r
for Mac )\x{200b}
as the search termPlugins for solving this problem for good!
I searched for a plugin that would highlight all the possibly code breaking characters but couldn't find one for Sublime Text so I wrote one: https://github.com/TuureKaunisto/highlight-dodgy-chars
The plugin works on a whitelist principle: all non-ascii characters that are not whitelisted in the settings get highlighted.
If you want to highlight things based on your own regular expression, this plugin will do the trick: https://github.com/bluegray/Highlighter and is also easily installable via Package Manager.