【问题标题】:Sublime Text 3 adds spaces after saving fileSublime Text 3 保存文件后添加空格
【发布时间】:2019-05-10 07:51:12
【问题描述】:

当我使用 Python 语法保存文件时,我遇到了 Sublime Text 3 的问题。运算符附近的空格是自动添加的。
例如:
我输入:print(a," ",b+c) 保存文件后它将是:print(a, " ", b + c)
我尝试更改设置,但我不知道 CTRL+S 后的空格是什么。我想要空格,但我不想在我不输入空格的地方自动添加空格。

我的设置文件:

    {
    "always_show_minimap_viewport": true,
    "auto_complete": false,
    "auto_complete_commit_on_tab": true,
    "auto_match_enabled": true,
    "bold_folder_labels": true,
    "caret_style": "solid",
    "color_scheme": "Packages/ayu/ayu-dark.tmTheme",
    "detect_indentation": true,
    "draw_indent_guides": true,
    "draw_minimap_border": true,
    "enable_telemetry": false,
    "ensure_newline_at_eof_on_save": true,
    "folder_exclude_patterns":
    [
        ".svn",
        ".git",
        ".hg",
        "CVS",
        "*.DS_Store",
        "*.pyc",
        "pycache"
    ],
    "font_face": "Liberation Mono",
    "font_options":
    [
        "subpixel_antialias",
        "no_round"
    ],
    "font_size": 14,
    "highlight_line": false,
    "highlight_modified_tabs": false,
    "ignored_packages":
    [
        "Vintage"
    ],
    "indent_guide_options":
    [
        "draw_active",
        "draw_normal"
    ],
    "indent_to_bracket": true,
    "line_padding_bottom": 0,
    "line_padding_top": 0,
    "match_brackets": true,
    "match_brackets_angle": false,
    "match_brackets_braces": true,
    "match_brackets_content": true,
    "match_brackets_square": true,
    "new_window_settings":
    {
        "hide_open_files": true,
        "show_tabs": true,
        "side_bar_visible": true,
        "status_bar_visible": true
    },
    "pep8_max_line_length": 79,
    "preview_on_click": false,
    "rulers":
    [
        79
    ],
    "shift_tab_unindent": true,
    "show_panel_on_build": false,
    "soda_classic_tabs": true,
    "soda_folder_icons": false,
    "tab_size": 4,
    "theme": "ayu-dark.sublime-theme",
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "use_simple_full_screen": true,
    "vintage_start_in_command_mode": false,
    "wide_caret": true,
    "word_wrap": true,
    "wrap_width": 80,
    "material_theme_accent_graphite": true ,
    "material_theme_compact_sidebar": true,
    "file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", "*.class", "*.psd", "*.sublime-workspace"],
}

语法设置文件:

    // These settings override both User and Default settings for the Python syntax
{
    "draw_white_space": "all",
    "auto_indent": true,
    "rulers": [79],
    "smart_indent": true,
    "tab_size": 4,
    "trim_automatic_white_space": true,
    "use_tab_stops": true,
    "word_wrap": true,
    "wrap_width": 80
}

【问题讨论】:

  • 您安装了第三方软件包,在保存时会重新格式化您的代码; Sublime 不会这样做。您已安装的软件包列表位于 Package Control 设置中,因此如果您发布该列表,我们可能会为您缩小范围。
  • 我现在知道那是 Anaconda。您可能知道我怎样才能在不添加空格的情况下进行自动格式化?如果我将 "auto_formatting": true 更改为 false 我没有任何建议。

标签: python python-3.x sublimetext3 sublimetext


【解决方案1】:

我找到了解决方案。这是一个 Anaconda 插件。 您必须在此插件的用户设置中设置以下标志:

"auto_formatting": true,
"autoformat_ignore":
    [
        "E309",
        "E501",
        "E221",
        "E222",
        "E223",
        "E225",
        "E226",
        "E227",
        "E228",
        "E231"
    ]

【讨论】:

  • PEP 8 标准的存在是有原因的,它们使代码更具可读性。尝试遵循所有标准的 90%,并确保还阅读 PEP 8 以及为什么 python 遵循这些标准。
猜你喜欢
  • 2014-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-24
  • 1970-01-01
  • 1970-01-01
  • 2013-12-26
  • 1970-01-01
相关资源
最近更新 更多