Customize VSCode
Customizing VS Code for Python (Windows version)
I started using VScode very recently and have found it to be very easy to use and productive for what I do. I use it to write my python code but have also tried it with R and other language and have liked so far. So, I thought i’d write up the steps to customize the settings for future reference.
Installation
Direct Download
- Get VS Code from project website
- Extract the zip and open the file
- Ta Dah! its is installed
- Opens VScode welcome page. Lots of shortcuts and tutorials to play around
Mac Package Manger
$> brew cask install visual-studio-code
Extensions I have used
- Ayu: for folder icons
- HTML Preview: for previewing html, markdown etc
- IntelliJ IDEA Keybinding: for keybindings in vscode
- Markdown + Math: for typing math symbols in $\LaTeX$
- Predawn Theme Kit: for vscode theme
- Python: for python of course! details below
- Rainbow CSV: For csv preview, search etc
Python Extension
- Need to have python installed in the system
- INSTALLATION
- Go to Extension icon on the “Activity Bar” on the left
- Search for Python. Click “install” and the python extension is ready
- It has nice features such as code highlighting, linting, formatting, intellisence
- Usually as we write code and try to run, there will be notification asking to install. Otherwise, can install
pylint
,black
, etc. from command line in global environment
- Usually as we write code and try to run, there will be notification asking to install. Otherwise, can install
- VS code also comes with integrated terminal
- Install Linter eg.
pylint
to use Linter - Install code formatter eg.
black
,ypaf
,pep8
, etc.shift+Alt+F
- To see how certain python module was written - hover the mouse to the function, and right click then select
go to definition
Running Python in VS code
VScode creates .vscode folder in the location where the project is located and this is where all the local settings are stored.
Python settings can be found in settings.json
file
This settings could include which python intrepreter is selected, font size, color scheme, etc. They all can be customized.
There are times when I use the same Python virtual environment for some of the prototyping and install the libraries there instead of creating a new venv.
It is possible that the Select Python Intrepreter
may not list that because it is in a path not recognized at the directory level of the script.
To add python from that venv add the path to the settings.json "python.pythonPath":"~\\..\\my_virtual_env\\Scripts\\activate"
Global User settings
Changing the global user settings to customize the VScode work environment gives the user the familiar workspace. Similar to the workspace setting above, there is a global user setting availe
- Color Theme -
command pallete > preferance: color theme
But if needed to install external color theme theninstall
. It will open the extension marketplace. Choose to install something likepredawn
- File icon Theme -
command pallete > preferance: file icon theme
To install from the marketplace, go toinstall
and search from the extension marketplace. Selecting the icon Theme changed color theme but then went back to color theme and changed it back to the prefered color theme. - Change global settings- click on the
gear
icon. then select the settings. It by default opens on UI version. If want a json version, then click on {} towards the top right
Open Default settings
command palette > open default setting (json)
- To change setting view from UI to JSON- find
workbench.quickOpen.preserveInput
and change to JSON To see what the options to change the values to: Look at the pencil icon and right click to select the option - See default setting while opening user setting
"workbench.settings.openDefaultSettings": true,
Font and other appearance setting code runner
- will allow run code with keyboard shortcuts without having to go to terminal. Install code runner form extension market place eg
- To change setting view from UI to JSON- find
References:
VS Code Docs:
Corey M Schafer
Corey’s User settings