Sublime As Ide

broken image


With Sublime Text, it's possible to turn your text editor into the functional equivalent of a Python IDE. The best part is you don't have to install an IDE to do it.

  1. I run Python 3.7.2 on my computer. Now, that we are sure that the Python is correctly installed and paths are added to Environment Variables, you can install and open Sublime Text 3 editor. Click the Windows search icon, and enter 'sublime'.A new icon will appear.
  2. Sublime text is my favourite text editor. That's why I want to make this as full C or C IDE. I have already downloaded MinGW compiler. Using that I can compile and run my program. But I am facing problems in taking input from sublime text console.
  3. Online Compiler from Programiz. If you want to start writing Python code without.

There are two types of settings that define your preferred environment:

  • Project settings, that apply to a specific project. In the Settings/Preferences dialog Ctrl+Alt+S, they are marked with .

  • IDE settings, that are common for all projects and refer to the project-independent aspects.

Project settings

Project settings are stored with each specific project as a set of .xml files under the .idea folder. If you specify the template project settings, these settings will be automatically used for each newly created project.

The settings that pertain to a project, are marked with the icon in the Settings/Preferences dialog.

IDE settings

IDE settings are stored in the dedicated directories under PyCharm home directory. The PyCharm directory name is composed of the product name and version.

Syntax
%APPDATA%JetBrains
Example
C:UsersJohnSAppDataRoamingJetBrainsPyCharm2020.3
Syntax
~/Library/Application Support/JetBrains/
Example
~/Library/Application Support/JetBrains/PyCharm2020.3
Syntax
~/.config/JetBrains/
Example
~/.config/JetBrains/PyCharm2020.3

Locations of directories

The config directory has several subfolders that contain .xml files with your personal settings. You can easily share your preferred keymaps, color schemes, and so on by copying these files into the corresponding folders on another PyCharm installation. Prior to copying, make sure that PyCharm is not running, because it can erase the newly transferred files before shutting down.

The following is the list of some of the subfolders under the config folder, and the settings contained therein.

Folder nameUser settings
codestylesContains code style schemes.
colorsContains editor colors and fonts customization schemes.
filetypesContains user-defined file types.
inspectionContains code inspection profiles.
keymapsContains PyCharm keyboard shortcuts customizations.
optionsContains various options, for example, feature usage statistics and macros.
templatesContains user-defined live templates.
toolsContains configuration files for the user-defined external tools.
shelfContains shelved changes.

Locations of the config, system, and plugins directories can be modified in idea.properties file. For more information, see Platform properties.

A solid text editor is a developer's best friend. You use it constantly and itbecomes like a second pair of hands. The keyboard commands you use dailybecome so engrained in your muscle memory that you stop thinking about thementirely.

With Sublime Text, it's possible to turn your text editor into the functionalequivalent of a Python IDE. The best part is you don't have to install an IDEto do it.

Requirements¶

Here are my requirements for an ‘IDE':

  • It should provide excellent, configurable syntax colorization.
  • It should allow for robust tab completion.
  • It should offer the ability to jump to the definition of symbols in otherfiles.
  • It should perform automatic code linting to help avoid silly mistakes.
  • It should be able to interact with a Python interpreter such that whendebugging, the editor will follow along with the debugger.

Which Version?¶

Version 2 will be fine, but I would urge you to consider updating to version 3.Some of the plugins I recommend are not available for version 2.

Basic Settings¶

All configuration in Sublime Text is done via JSON. It's simple to learn. goand read that link then return here.

There are a number of different levels of configuration in Sublime Text. Youwill most often work on settings at the user level.

Sublime Text 3 Editor Download

Sublime As Ide

Open Preferences -> Settings-Default to see all the default settingsand choose which to override.

Create your own set of preferences by opening Preferences -> Settings-User. This will create an empty file, you can then copy the settings you wantto override from the default set into your personal settings.

Here's a reasonable set of preliminary settings (theme, color scheme and fontare quite personal, find ones that suit you.):

Especially important is the setting translate_tabs_to_spaces, which ensuresthat any time you hit a tab key, the single t character is replaced by fours characters. In Python this is vital!

Note

Remember, the font, color scheme and theme settings above are those Iuse. You will need to install extra packages to get them.

Extending the Editor¶

Most of the requirements above go beyond basic editor function. Use Plugins.

Sublime Text comes with a great system for Package Control. It handlesinstalling and uninstalling plugins, and even updates installed plugins foryou. You can also manually install plugins that haven't made it to the big-timeyet, including ones you write yourself. Happily, the plugin system isPython!

Installing Package Control¶

Note

Some earlier versions of Sublime Text came with the package control systemalready installed. This is no longer the case. You'll need to install ityourself. https://torrent-bands.mystrikingly.com/blog/how-to-view-pdf-files-on-windows-7. Follow the instructions athttps://sublime.wbond.net/installation.

To install a plugin using Package Control, open the commandpalette withshift-super-P (ctrl-shift-P on Windows/Linux). The super key is commandor on OS X. When the palette opens, typing install will bring up thePackageControl:InstallPackage Iphone mail simulator. command. Hit enter to select it.

After you select the command, Sublime Text fetches an updated list of packagesfrom the network. It might take a second or two for the list to appear. When itdoes, start to type the name of the package you want. Sublime Text filters thelist and shows you what you want to see. To install a plugin, select it withthe mouse, or use arrow keys to navigate the list and hit enter when yourplugin is highlighted.

Useful Plugins¶

Here are the plugins I've installed to achieve the requirements above.

Autocompletion¶

By default, Sublime Text will index symbols in open files and projects, butthat doesn't cover installed python packages that may be part of a non-standardrun environment.

There are two to choose from:

  1. SublimeCodeIntel offers strong support for multiple languages throughit's own plugin system. It is a bit heavy and requires building an index.
  2. SublimeJedi only supports Python, but is faster and keeps an index on itsown.

I've installed SublimeJedi, and used settings similar to thesefor each projectto ensure that all relevant code is found:

The python_interpreter_path allows me to indicate which Python executableshould be introspected for symbol definitions.

The python_package_paths setting allows designating additional paths thatwill be searched for Python packages containing symbols. In the above case, Iam using buildout to manage installed packages, andthe omeletterecipe to provide a single folder in which all installed code can bereferenced. If you work with virtualenvor some other sandbox system, your value for python_package_paths will lookquite different.

Once configured, you should be able to use the ctrl-shift-G keyboardshortcut to jump directly to the definition of a symbol. You can also usealt-shift-F to find other usages of the same symbol elsewhere in your code.

Code Linting¶

Code linting shows you mistakes you've made in your source before you attemptto run the code. This saves time. Sublime Text has an available plugin for codelinters called SublimeLinter.

Python has a couple of great tools available for linting, the pep8 andpyflakes packages. Pep8 checks for style violations, lines too long,extra spaces and so on. Pyflakes checks for syntactic violations, likeusing a symbol that isn't defined or importing a symbol you don't use.

Another Python linting package, flake8 combines these two, and adds inmccabe, a tool to check the cyclomatic complexity of code you write. Thiscan be of great help in discovering methods and functions that could besimplified and thus made easier to understand and more testable.

There is a nice plugin for the SublimeLinter that utilizes flake8. For it towork, the plugin will need to have a Python executable that has the Pythontools it needs installed.

Use `virtualenv`_ to accomplish this. First, create a virtualenv and activateit:

Then use Python packaging tools to install the required packages:

The Python executable for this virtualenv now has the required packagesinstalled. You can look in /path/to/sublenv/bin to see the executablecommands for each:

(sublenv)$ ls sublenv/binactivate easy_install-2.7 pip2.7activate.csh flake8 pyflakesactivate.fish pep8 pythonactivate_this.py pip python2easy_install pip2 python2.7

Now install SublimeLinter and then SublimeLinter-flake8 using Package Control.

Here are the settings you can add to Preferences -> PackageSettings ->SublimeLinter -> Settings-User:

The paths key points to the path that contains the flake8 executablecommand.

The python_paths key points to the location of the python executable to beused.

The settings inside the flake8 object control the performance of thelinter. Read more about them here.

Sublime Text Ide

White Space Management¶

One of the issues highlighted by flake8 is trailing spaces. Sublime textprovides a setting that allows you to remove them every time you save a file:

Do not use this setting

Removing trailing whitespace by default causes a ton of noise in commits.

Keep commits for stylistic cleanup separate from those that make importantchanges to code.

The TrailingSpaces SublimeText plugin can help with this.

Here are the settings you can use:

This allows trimming whitespace on save, but only on lines you have directlymodified. You can still trim all whitespace manually and keep changesetsfree of noise.

Follow-Along¶

The final requirement for a reasonable IDE experience is to be able to follow adebugging session in the file where the code exists.

There is no plugin for SublimeText that supports this. But there is a Pythonpackage you can install into the virtualenv for each of your projects that doesit.

Python

Open Preferences -> Settings-Default to see all the default settingsand choose which to override.

Create your own set of preferences by opening Preferences -> Settings-User. This will create an empty file, you can then copy the settings you wantto override from the default set into your personal settings.

Here's a reasonable set of preliminary settings (theme, color scheme and fontare quite personal, find ones that suit you.):

Especially important is the setting translate_tabs_to_spaces, which ensuresthat any time you hit a tab key, the single t character is replaced by fours characters. In Python this is vital!

Note

Remember, the font, color scheme and theme settings above are those Iuse. You will need to install extra packages to get them.

Extending the Editor¶

Most of the requirements above go beyond basic editor function. Use Plugins.

Sublime Text comes with a great system for Package Control. It handlesinstalling and uninstalling plugins, and even updates installed plugins foryou. You can also manually install plugins that haven't made it to the big-timeyet, including ones you write yourself. Happily, the plugin system isPython!

Installing Package Control¶

Note

Some earlier versions of Sublime Text came with the package control systemalready installed. This is no longer the case. You'll need to install ityourself. https://torrent-bands.mystrikingly.com/blog/how-to-view-pdf-files-on-windows-7. Follow the instructions athttps://sublime.wbond.net/installation.

To install a plugin using Package Control, open the commandpalette withshift-super-P (ctrl-shift-P on Windows/Linux). The super key is commandor on OS X. When the palette opens, typing install will bring up thePackageControl:InstallPackage Iphone mail simulator. command. Hit enter to select it.

After you select the command, Sublime Text fetches an updated list of packagesfrom the network. It might take a second or two for the list to appear. When itdoes, start to type the name of the package you want. Sublime Text filters thelist and shows you what you want to see. To install a plugin, select it withthe mouse, or use arrow keys to navigate the list and hit enter when yourplugin is highlighted.

Useful Plugins¶

Here are the plugins I've installed to achieve the requirements above.

Autocompletion¶

By default, Sublime Text will index symbols in open files and projects, butthat doesn't cover installed python packages that may be part of a non-standardrun environment.

There are two to choose from:

  1. SublimeCodeIntel offers strong support for multiple languages throughit's own plugin system. It is a bit heavy and requires building an index.
  2. SublimeJedi only supports Python, but is faster and keeps an index on itsown.

I've installed SublimeJedi, and used settings similar to thesefor each projectto ensure that all relevant code is found:

The python_interpreter_path allows me to indicate which Python executableshould be introspected for symbol definitions.

The python_package_paths setting allows designating additional paths thatwill be searched for Python packages containing symbols. In the above case, Iam using buildout to manage installed packages, andthe omeletterecipe to provide a single folder in which all installed code can bereferenced. If you work with virtualenvor some other sandbox system, your value for python_package_paths will lookquite different.

Once configured, you should be able to use the ctrl-shift-G keyboardshortcut to jump directly to the definition of a symbol. You can also usealt-shift-F to find other usages of the same symbol elsewhere in your code.

Code Linting¶

Code linting shows you mistakes you've made in your source before you attemptto run the code. This saves time. Sublime Text has an available plugin for codelinters called SublimeLinter.

Python has a couple of great tools available for linting, the pep8 andpyflakes packages. Pep8 checks for style violations, lines too long,extra spaces and so on. Pyflakes checks for syntactic violations, likeusing a symbol that isn't defined or importing a symbol you don't use.

Another Python linting package, flake8 combines these two, and adds inmccabe, a tool to check the cyclomatic complexity of code you write. Thiscan be of great help in discovering methods and functions that could besimplified and thus made easier to understand and more testable.

There is a nice plugin for the SublimeLinter that utilizes flake8. For it towork, the plugin will need to have a Python executable that has the Pythontools it needs installed.

Use `virtualenv`_ to accomplish this. First, create a virtualenv and activateit:

Then use Python packaging tools to install the required packages:

The Python executable for this virtualenv now has the required packagesinstalled. You can look in /path/to/sublenv/bin to see the executablecommands for each:

(sublenv)$ ls sublenv/binactivate easy_install-2.7 pip2.7activate.csh flake8 pyflakesactivate.fish pep8 pythonactivate_this.py pip python2easy_install pip2 python2.7

Now install SublimeLinter and then SublimeLinter-flake8 using Package Control.

Here are the settings you can add to Preferences -> PackageSettings ->SublimeLinter -> Settings-User:

The paths key points to the path that contains the flake8 executablecommand.

The python_paths key points to the location of the python executable to beused.

The settings inside the flake8 object control the performance of thelinter. Read more about them here.

Sublime Text Ide

White Space Management¶

One of the issues highlighted by flake8 is trailing spaces. Sublime textprovides a setting that allows you to remove them every time you save a file:

Do not use this setting

Removing trailing whitespace by default causes a ton of noise in commits.

Keep commits for stylistic cleanup separate from those that make importantchanges to code.

The TrailingSpaces SublimeText plugin can help with this.

Here are the settings you can use:

This allows trimming whitespace on save, but only on lines you have directlymodified. You can still trim all whitespace manually and keep changesetsfree of noise.

Follow-Along¶

The final requirement for a reasonable IDE experience is to be able to follow adebugging session in the file where the code exists.

There is no plugin for SublimeText that supports this. But there is a Pythonpackage you can install into the virtualenv for each of your projects that doesit.

https://qjvn.over-blog.com/2021/02/running-word-on-mac.html. The package is called PDBSublimeTextSupport and its simple to install with pip:

With that package installed in the Python that is used for your project, anybreakpoint you set will automatically pop to the surface in SublimeText. Andas you step through the code, you will see the current line in your SublimeText file move along with you.





broken image