在SublimeText 3上,我尝试在“=>”
之前和之后自动添加空格我尝试在用户密钥绑定中添加:
{ "keys": ["equals,>"], "command": "insert_snippet", "args": { "name": "Packages/User/spacer.sublime-snippet" } }
这是我的片段:
<snippet>
<content><![CDATA[ => ]]></content>
</snippet>
但它不起作用。
答案 0 :(得分:1)
控制台说Unknown key equals,>
equals
是多余的。所以正确的设置:
{ "keys": [">"], "command": "insert_snippet", "args": { "name": "Packages/User/spacer.sublime-snippet" } }
下次请先在控制台中查找错误。
更新
在这种情况下应该使用我希望它匹配“=&gt;”。
["=",">"]
{ "keys": ["=",">"], "command": "insert_snippet", "args": { "name": "Packages/User/spacer.sublime-snippet" } }
答案 1 :(得分:1)
当我读到这个问题时,我意识到我经常在某些东西的两边插入空格,所以我将下面的Sublime Text插件用于我自己的使用,并且作为事后的想法,决定将它发布在这里。
此插件在任何选定文本之前和之后添加单个空格,例如"Sel" --> " Sel "
。当然,处理多个选择。单个游标被忽略,否则你只需添加两个空格。它与Sublime Text v.2和v.3兼容。
将以下代码保存在名为AddSpacesAroundSelection.py
的文件中,并将文件放在Sublime Text Packages文件夹中的某个位置。例如~/.config/sublime-text-3/Packages/User/
# File: AddSpacesAroundSelection.py
# Command: add_spaces_around_selection
# Keys: { "keys": ["ctrl+space"], "command": "add_spaces_around_selection" }
import sublime, sublime_plugin
class AddSpacesAroundSelectionCommand(sublime_plugin.TextCommand):
"""
The AddSpacesAroundSelectionCommand class is a Sublime Text plugin which
adds a single space on both sides of each selection. e.g. "Sel" -> " Sel "
"""
def run(self, edit):
""" run() is called when the command is run. """
space_char = " "
# Loop through all the selections.
for sel in self.view.sel():
# If something is actually selected (i.e. not just a cursor) then
# insert a space on both sides of the selected text.
if sel.size() > 0:
# Insert the space at the end of the selection before the
# beginning of it or the insertion position will be wrong.
self.view.insert(edit, sel.end(), space_char)
self.view.insert(edit, sel.begin(), space_char)
# End of def run()
# End of class AddSpacesAroundSelectionCommand()
为您的用户.sublime-keymap
文件添加密钥绑定。在我的系统上,ctrl+space
密钥绑定未被使用,它们似乎适合使用。
{ "keys": ["ctrl+space"], "command": "add_spaces_around_selection" },
希望这有帮助。