Sublime Text Setting for Python

Learn how to set up Sublime Text for Python development with an example of configuring basic syntax highlighting.

Configuring Sublime Text for Python Development

Sublime Text is an incredibly popular text editor for writing code. With its easy to use interface and powerful features, it's no wonder why many developers opt for Sublime as their go-to text editor. Configuring Sublime Text for Python development is easy and can be done quickly.

The first step is to install the Sublime Text Package Control. To do this, open the command palette (Ctrl + Shift + P) and type “Package Control: Install Package”. Then type “Python” into the search field and install the Python package.

Once the Python package is installed, there are some settings that you'll want to configure to make sure your Sublime Text editor is properly set up for Python development. Start by opening the settings menu (Preferences > Settings). From there, you'll want to add the following settings:


{
  "tab_size": 4,
  "translate_tabs_to_spaces": true,
  "ensure_newline_at_eof_on_save": true,
  "trim_trailing_white_space_on_save": true
}

The first two settings (tab_size and translate_tabs_to_spaces) are important for formatting your code properly. The tab_size setting specifies the number of spaces that will be used for each indentation level. The translate_tabs_to_spaces setting ensures that when you press the tab key, it will insert the specified number of spaces rather than an actual tab character.

The ensure_newline_at_eof_on_save setting adds a new line character to the end of the file when you save it. This is helpful in ensuring that the file has the correct formatting when it is opened in another text editor.

The trim_trailing_white_space_on_save setting will automatically remove any extra white space at the end of lines when you save the file. This is useful for keeping your code clean and ensuring that it is properly formatted.

Once you have added these settings, you should also add the following to the Sublime Text User Key Bindings file (Preferences > Key Bindings – User):


[
  { "keys": ["ctrl+shift+p"], "command": "show_overlay", "args": {"overlay": "command_palette"} }
]

This adds a keyboard shortcut (Ctrl + Shift + P) for quickly opening the command palette. This is a very useful shortcut and can save you a lot of time when working with Sublime Text.

Finally, you should add the following to the Sublime Text User Preferences file (Preferences > Settings – User):


{
  "ignored_packages":
  [
    "Vintage",
    "Python"
  ]
}

This setting will prevent the Vintage package from being loaded when Sublime Text starts up. The Vintage package can cause problems when working with Python code, so it is best to disable it.

With these settings configured, you should be able to start writing Python code in Sublime Text with confidence. Sublime Text is an excellent text editor for Python development and with a few simple configuration changes, you can make it even better.

Answers (0)