Sublime text: Merge multiple adjacent white spaces into one

无人久伴 提交于 2019-12-04 04:27:46

问题


How to do this in sublime text

"aaa     bbb ccc    ddddddd   "

should get converted to

"aaa bbb ccc ddddddd "

回答1:


Create a snippet:

<snippet>
    <content><![CDATA[
${SELECTION/\s{2,}/ /g}
]]></content>
</snippet>

Then create a keybinding to call that snippet in your Preferences -> KeyBindings - User file:

{ "keys": ["ctrl+shift+z"], "command": "insert_snippet", "args": { "name": "Packages/User/Snippets/test_snippets/regex_whitespace.sublime-snippet" } },

Then, select text on a line, or multiple lines, and use the keymap.




回答2:


This can also be done with a regex search and replace. First, select the text you want to alter. Next, click on Find -> Replace.... Make sure the Regex and In selection buttons are selected. To visualize what you're going to replace, you can also select the Highlight matches button as well. In the Find What field, enter (\s){2,}, and in the Replace With field, just enter a space. Click Replace All, and all instances of two or more whitespace characters will be replaced with a single space.



来源:https://stackoverflow.com/questions/28103799/sublime-text-merge-multiple-adjacent-white-spaces-into-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!