1 introduction
In my daily work and study, I often use Python programming on Windows system and Markdown writing, and I will synchronize the writing content to my blog, Zhihu and official account set up by WordPress. After reviewing a variety of tools, I finally chose VS Code as the unified editor. The rich plug-ins and community can meet all my needs. Here is how to make VS Code an editor that combines Python programming and Markdown blogging. The following introduction will cover basic setup and some useful tips, plug-ins, and more.
2 Installation and Environment Construction
2.1 VS Code Installation
This does not have what to say, go directly to the official website to choose the appropriate installation package for your system, download and install. Download address: https://code.visualstudio.com/Download. By the way, after the installation, there is an English interface. If you like Chinese interface, you can search for “Chinese” in the plug-in market, and the first one is listed. After the installation, you will be prompted to restart VS Code. After the restart, it will become Chinese. If not, press Ctrl+Shift+P to bring up VS Code’s command line input, type Configure Display Language, and select. In the json file that opens, Change the “locale”:”” to “locale”:” zh-cn “, restart vscode, and the interface language will be Chinese.
2.2 Common Shortcuts of VS Code
Digest the following two is enough, mainly “basic editing” and “navigation” shortcuts, can speed up the usual programming speed. Early not skilled to remember, you can buy a large mouse pad full of keyboard shortcuts, from time to time, ha ha ha.
21 VSCode shortcuts to make Code faster and more interesting VSCode – (2) shortcuts complete, no more
2.3 Building a Python Editor
- “Install VS Code’s Python plug-in“: Directly search for “Python” in the plugin market.
- “Install the Python interpreter“: I usually use two methods, one is directly fromwebsiteDownload. The other one, if you’re often involved in data science, machine learning, programming, you can just download itAnaconda, which contains not only the Pyhton interpreter, but also common libraries and tools. Check that the environment variables are configured after the installation is complete.
- Choose the first tutorial: Python Installation Tutorial (For Windows, Python3.7 as an example)
- Select the second option tutorial: https://docs.anaconda.com/anaconda/install/windows/
- Use the command line tool to create a new project folder.
mkdir hello world
cd hello world
code .
Copy the code
Method 2: Create a folder, right-click it, and open it with VS Code.
Method 3: Open VS Code and clickfile
->Open folder
After opening our project folder, create a new one.py
The Python file at the end, then select the Python interpreter in the lower left corner of the editor, and one will appear in the project file.vscode/settings.json
File, which is the setup file for this workspace. Now you can edit your own Python file and run it, as shown below:
2.4 Build the Markdown editor
Markdown is a very lightweight and easy-to-learn markup language. Markdown writing is supported on many blogs, forums, and other sites. It is also recommended if you need to document your own code. Use Markdown to edit articles locally and easily distribute them across platforms. How to use Markdown in VS Code is also very easy, just install a few plug-ins.
- “Markdown All in One” : a package that packs the most commonly used Markdown optimizations for you;
- “Markdown Preview Enhanced” : Enhanced Preview rendering;
- “Markdown+Math” : Provides support for Latex mathematical formulas in Markdown.
Once these plug-ins are installed, you can create a new project and create a Markdown file ending in.md. Click the Open sidebar preview button in the upper right corner of the edit box to render the Markdown file in real time. After Markdown Preview Enhanced is installed, there are two such diagrams. It is recommended to select the Preview icon corresponding to Markdown Preview Enhanced.
-
“Markdown common Grammar” : This is enough:
Markdown syntax is illustrated in detail
3 Some tips
3.1 More comfortable Python programming environment
- “Code completion“: Code completion plug-ins in VS Code are
Visual Studio IntelliCode
. IntelliCode generates recommendations using machine learning models trained by thousands of common code bases, and becomes more accurate as you write code. It makes programming recommendations based on context, rather than simply recommending apis in alphabetical order.
IntelliCode uses one of two engines when entering a Python workspace. By default, Microsoft Python Analysis Engine is used. When entering a Python workspace, you will see that it is loading, usually for a long time. Friends who can’t stand it are here.vscode/settings.json
Set in the
"python.jediEnabled": true.Copy the code
This means using Jedi as the IntelliCode engine. In addition, if you have some additional packages that need to be added to autocomplete, you can do so using the following Settings.
"python.autoComplete.extraPaths": "Your package path"
Copy the code
- “Code review“:
- pylintIt is a Python code checker. Installation is required through PIP. For code that does not conform to the specification, a wavy line prompts. Open it with the following Settings
"python.linting.enabled": true."python.linting.pylintEnabled": true.Copy the code
- Flake8 and yapf: The two combinations I usually use,flake8Flake8 is an official Python tool to help check whether Python code is standardized. Compared with Pylint, flake8 has flexible checking rules, supports integration of additional plug-ins, and has strong scalability. Yapf is a code formatting tool. After Flake8 and Yapf are installed through PIP, perform the following configuration.
"python.linting.enabled": true."python.linting.pylintEnabled": false."python.linting.flake8Enabled": true."python.formatting.provider": "yapf".Copy the code
Once installed, we can automatically format the code by right-clicking in the margin of the Python code file and selecting Format Document.
However, there is one rule that I am not comfortable with. Flake8 defaults to a maximum of 79 characters on a line, which will show wavy lines to indicate that the code is too long. We can make it longer and add the following configuration to set the maximum length to 128 characters.
"python.linting.flake8Args": ["--max-line-length=128"].Copy the code
- “Several plug-ins are recommended“:
-
Settings Sync: upload the configuration of VSCode and the plugin we downloaded to GitHub, so that we can configure the familiar VSCode on another computer.
-
Better Comments: This plugin makes VS Code comment messages more personal. It can display annotations differently based on tags such as alerts, queries, TODO, highlighting, and so on. In addition, you can style the commented out code. In addition, any other comment style you want can be specified in the Settings.
-
Bracket Pair Colorizer: Bracket pairs (), [] and {} can be shown in different colors and can be directly linked by line segments when clicked. In addition, it supports user – defined symbols.
-
Better AlignIt is mainly used for up-down alignment of code. It aligns code with colons (:), assignments (=, +=, -=, *=, /=), and arrows (=>).
-
LeetCode: Brush LeetCode artifact.
-
3.2 Markdown to Zhihu article release
In the local use of Markdown to write an article, you can use the plug-in Zhihu On VSCode one button to publish to Zhihu, specific operations see: Zhihu On VSCode coming – redefine content creation!
3.3 Markdown to WordPress article publishing
In WordPress, you can install the plugin WP editor. md to copy the Markdown article. You can do some fine tuning, such as images.
3.4 Markdown to wechat public article release
I use the online tool: https://doocs.gitee.io/md/? Hao. su is nice to use. The page is simple and beautiful. When it comes to external links, you can use the tool’s wechat external links to automatically convert to the end of the text reference function. In addition, if it involves mathematical formulas, directly copying the past is not good, I currently use a Chrome plug-in: mpMath, use online tools to copy the article to the official account background, and then edit the formula one by one, a little trouble, if you have a better solution, you can also share with me ~
Welcome to follow my public account “Wild wind classmate”, original technical articles, dry goods recommended articles will be pushed the first time.