除了通过持久设置,是否有一种动态的方式来启用和禁用不可见的空格显示?
"draw_white_space": "all",
除了通过持久设置,是否有一种动态的方式来启用和禁用不可见的空格显示?
"draw_white_space": "all",
draw_white_space
:// Set to "none" to turn off drawing white space, "selection" to draw only the
// white space within the selection, and "all" to draw all white space
"draw_white_space": "selection",
import sublime
import sublime_plugin
class ToggleWhiteSpaceCommand(sublime_plugin.TextCommand):
def run(self, edit, options=["none", "selection", "all"]):
try:
current = self.view.settings().get("draw_white_space", "selection")
index = options.index(current)
except:
index = 0
index = (index + 1) % len(options)
self.view.settings().set("draw_white_space", options[index])
定义的命令包含一个可选参数options
,它允许您指定要在其之间切换的值,其中默认值是所有可能的选项。
您可以直接将按键绑定到该命令,以在设置的所有可能值之间切换状态,还可以使用以下内容,如果您只想在始终打开和始终关闭之间切换,则可以使用以下内容:
{
"keys": ["super+s"],
"command": "toggle_white_space",
"args": {
"options": ["all", "none"]
}
},