File Currently Open
Visual Studio Code Tips and Tricks
"Tips and Tricks" lets you lot jump right in and larn how to be productive with Visual Studio Code. You'll get familiar with its powerful editing, code intelligence, and source code control features and learn useful keyboard shortcuts. This topic goes pretty fast and provides a broad overview, and so be certain to expect at the other in-depth topics in Getting Started and the User Guide to larn more.
If you lot don't take Visual Studio Lawmaking installed, go to the Download page. You tin can find platform specific setup instructions at Running VS Code on Linux, macOS, and Windows.
Prefer a video? Y'all can watch a contempo Microsoft Build talk Visual Studio Code tips and tricks, which describes twenty tips and tricks for working productively with VS Code.
Basics
Getting started
The best manner of exploring VS Code easily-on is to open the Get Started page. You will get an overview of VS Code'south customizations and features. Assist > Go Started.
Pick a Walkthrough for a self-guided tour through the setup steps, features, and deeper customizations that VS Code offers. Every bit yous discover and acquire, the walkthroughs runway your progress.
If you are looking to meliorate your lawmaking editing skills open up the Interactive Editor Playground. Attempt out VS Code'southward code editing features, similar multi-cursor editing, IntelliSense, Snippets, Emmet, and many more. Assist > Editor Playground.
Command Palette
Access all available commands based on your current context.
Keyboard Shortcut: ⇧⌘P (Windows, Linux Ctrl+Shift+P)
Default keyboard shortcuts
All of the commands are in the Command Palette with the associated key binding (if it exists). If you forget a keyboard shortcut, use the Control Palette to assist you out.
Keyboard reference sheets
Download the keyboard shortcut reference sail for your platform (macOS, Windows, Linux).
Quick Open
Speedily open files.
Keyboard Shortcut: ⌘P (Windows, Linux Ctrl+P)
Tip: Type ? to view commands suggestions.
Typing commands such as edt and term followed by a space will bring up dropdown lists.
Navigate between recently opened files
Repeat the Quick Open keyboard shortcut to cycle speedily between recently opened files.
Open up multiple files from Quick Open
You can open multiple files from Quick Open up past pressing the Right arrow key. This will open up the currently selected file in the groundwork and you lot can continue selecting files from Quick Open.
Navigate between recently opened folders and workspaces
Open Recent
Keyboard Shortcut: ⌃R (Windows, Linux Ctrl+R)
Displays a Quick Pick dropdown with the list from File > Open up Recent with recently opened folders and workspaces followed by files.
Command line
VS Lawmaking has a powerful command line interface (CLI) which allows you to customize how the editor is launched to back up various scenarios.
Make sure the VS Code binary is on your path so you can simply blazon 'code' to launch VS Code. See the platform specific setup topics if VS Lawmaking is added to your surroundings path during installation (Running VS Code on Linux, macOS, Windows).
# open lawmaking with electric current directory code . # open the current directory in the well-nigh recently used code window lawmaking -r . # create a new window code -n # change the language lawmaking --locale=es # open diff editor code --diff <file1> <file2> # open up file at specific line and column <file:line[:character]> code --goto package.json:10:5 # run into help options lawmaking --help # disable all extensions lawmaking --disable-extensions . .vscode binder
Workspace specific files are in a .vscode binder at the root. For case, tasks.json for the Chore Runner and launch.json for the debugger.
Status Bar
Errors and warnings
Keyboard Shortcut: ⇧⌘M (Windows, Linux Ctrl+Shift+Thou)
Chop-chop jump to errors and warnings in the project.
Cycle through errors with F8 or ⇧F8 (Windows, Linux Shift+F8)
You can filter problems either by type ('errors', 'warnings') or text matching.
Change language mode
Keyboard Shortcut: ⌘K M (Windows, Linux Ctrl+K Thou)
If you desire to persist the new language mode for that file blazon, you tin apply the Configure File Clan for command to associate the current file extension with an installed linguistic communication.
Customization
At that place are many things you can practise to customize VS Code.
- Change your theme
- Change your keyboard shortcuts
- Tune your settings
- Add JSON validation
- Create snippets
- Install extensions
Change your theme
Keyboard Shortcut: ⌘K ⌘T (Windows, Linux Ctrl+K Ctrl+T)
You can install more themes from the VS Code extension Market place.
Additionally, you can install and change your File Icon themes.
Keymaps
Are you used to keyboard shortcuts from another editor? You lot can install a Keymap extension that brings the keyboard shortcuts from your favorite editor to VS Code. Go to Preferences > Keymaps to run across the current listing on the Marketplace. Some of the more popular ones:
- Vim
- Sublime Text Keymap
- Emacs Keymap
- Atom Keymap
- Brackets Keymap
- Eclipse Keymap
- Visual Studio Keymap
Customize your keyboard shortcuts
Keyboard Shortcut: ⌘Grand ⌘S (Windows, Linux Ctrl+Thou Ctrl+S)
You can search for shortcuts and add your own keybindings to the keybindings.json file.
See more than in Fundamental Bindings for Visual Studio Lawmaking.
Melody your settings
Past default VS Code shows the Settings editor, you can find settings listed below in a search bar, but you can still edit the underlying settings.json file by using the Open Settings (JSON) command or by changing your default settings editor with the workbench.settings.editor setting.
Open User Settings settings.json
Keyboard Shortcut: ⌘, (Windows, Linux Ctrl+,)
Modify the font size of diverse UI elements
// Principal editor "editor.fontSize" : xviii , // Terminal panel "last.integrated.fontSize" : 14 , // Output panel "[Log]" : { "editor.fontSize" : 15 } Change the zoom level
"window.zoomLevel" : 5 Font ligatures
"editor.fontFamily" : "Fira Code" , "editor.fontLigatures" : true Tip: You will demand to have a font installed that supports font ligatures. FiraCode is a popular font on the VS Code squad.
Auto Salvage
"files.autoSave" : "afterDelay" You can likewise toggle Auto Save from the peak-level menu with the File > Auto Save.
Format on save
"editor.formatOnSave" : true Format on paste
"editor.formatOnPaste" : true Change the size of Tab characters
"editor.tabSize" : four Spaces or Tabs
"editor.insertSpaces" : true Render whitespace
"editor.renderWhitespace" : "all" Whitespace characters are rendered by default in text selection.
Ignore files / folders
Removes these files / folders from your editor window.
"files.exclude" : { "somefolder/" : true , "somefile" : truthful } Remove these files / folders from search results.
"search.exclude" : { "someFolder/" : true , "somefile" : true } And many, many other customizations.
Language specific settings
You lot tin scope the settings that you just desire for specific languages by the language identifier. Yous tin can find a list of ordinarily used language IDs in the Language Identifiers reference.
"[languageid]" : { } Tip: You can also create language specific settings with the Configure Language Specific Settings command.
Add JSON validation
Enabled by default for many file types. Create your own schema and validation in settings.json
"json.schemas" : [ { "fileMatch" : [ "/bower.json" ], "url" : "https://json.schemastore.org/bower" } ] or for a schema defined in your workspace
"json.schemas" : [ { "fileMatch" : [ "/foo.json" ], "url" : "./myschema.json" } ] or a custom schema
"json.schemas" : [ { "fileMatch" : [ "/.myconfig" ], "schema" : { "type" : "object" , "properties" : { "name" : { "type" : "string" , "description" : "The proper name of the entry" } } } }, Run across more than in the JSON documentation.
Extensions
Keyboard Shortcut: ⇧⌘10 (Windows, Linux Ctrl+Shift+X)
Notice extensions
- In the VS Lawmaking Marketplace.
- Search inside VS Code in the Extensions view.
- View extension recommendations
- Community curated extension lists, such as awesome-vscode.
Install extensions
In the Extensions view, you lot can search via the search bar or click the More Actions (...) button to filter and sort by install count.
Extension recommendations
In the Extensions view, click Show Recommended Extensions in the More Actions (...) push menu.
Creating my own extension
Are yous interested in creating your own extension? You lot tin larn how to exercise this in the Extension API documentation, specifically check out the documentation on contribution points.
- configuration
- commands
- keybindings
- languages
- debuggers
- grammars
- themes
- snippets
- jsonValidation
Files and folders
Integrated Terminal
Keyboard Shortcut: ⌃` (Windows, Linux Ctrl+`)
Farther reading:
- Integrated Terminal documentation
- Mastering VS Lawmaking'southward Terminal article
Keyboard Shortcut: ⌘B (Windows, Linux Ctrl+B)
Toggle Panel
Keyboard Shortcut: ⌘J (Windows, Linux Ctrl+J)
Zen mode
Keyboard Shortcut: ⌘1000 Z (Windows, Linux Ctrl+K Z)
Enter lark free Zen way.
Press Esc twice to go out Zen Manner.
Side by side editing
Keyboard Shortcut: ⌘\ (Windows, Linux Ctrl+\)
Yous can also drag and drop editors to create new editor groups and move editors between groups.
Switch between editors
Keyboard Shortcut: ⌘1 (Windows, Linux Ctrl+1), ⌘2 (Windows, Linux Ctrl+two), ⌘3 (Windows, Linux Ctrl+three)
Movement to Explorer window
Keyboard Shortcut: ⇧⌘E (Windows, Linux Ctrl+Shift+Due east)
Create or open a file
Keyboard Shortcut: Ctrl+click (Cmd+click on macOS)
You can apace open a file or image or create a new file by moving the cursor to the file link and using Ctrl+click.
Close the currently opened binder
Keyboard Shortcut: ⌘Westward (Windows, Linux Ctrl+Due west)
Navigation history
Navigate entire history: ⌃Tab (Windows, Linux Ctrl+Tab)
Navigate back: ⌃- (Windows Alt+Left, Linux Ctrl+Alt+-)
Navigate forrad: ⌃⇧- (Windows Alt+Correct, Linux Ctrl+Shift+-)
File associations
Create language associations for files that aren't detected correctly. For example, many configuration files with custom file extensions are actually JSON.
"files.associations" : { ".database" : "json" } Preventing dingy writes
VS Code will show you an fault bulletin when you endeavor to relieve a file that cannot be saved because it has changed on disk. VS Lawmaking blocks saving the file to preclude overwriting changes that have been made outside of the editor.
In club to resolve the save conflict, click the Compare action in the error message to open a diff editor that will show you lot the contents of the file on disk (to the left) compared to the contents in VS Code (on the correct):
Apply the deportment in the editor toolbar to resolve the relieve conflict. You lot can either Accept your changes and thereby overwriting whatsoever changes on disk, or Revert to the version on disk. Reverting means that your changes will exist lost.
Note: The file will remain dingy and cannot be saved until you pick ane of the ii actions to resolve the disharmonize.
Editing hacks
Here is a selection of common features for editing lawmaking. If the keyboard shortcuts aren't comfortable for you lot, consider installing a keymap extension for your old editor.
Tip: You tin can see recommended keymap extensions in the Extensions view with which filters the search to @recommended:keymaps.
Multi cursor selection
To add together cursors at arbitrary positions, select a position with your mouse and employ Alt+Click (Option+Click on macOS).
To set cursors higher up or below the current position use:
Keyboard Shortcut: ⌥⌘↑ (Windows Ctrl+Alt+Upwards, Linux Shift+Alt+Up) or ⌥⌘↓ (Windows Ctrl+Alt+Downward, Linux Shift+Alt+Down)
You can add together additional cursors to all occurrences of the current selection with ⇧⌘L (Windows, Linux Ctrl+Shift+L).
Annotation: You can also modify the modifier to Ctrl/Cmd for applying multiple cursors with the
editor.multiCursorModifiersetting . See Multi-cursor Modifier for details.
If you do not want to add all occurrences of the current selection, yous tin use ⌘D (Windows, Linux Ctrl+D) instead. This only selects the side by side occurrence afterwards the one you selected then you tin add selections one by one.
Column (box) choice
You tin select blocks of text by property Shift+Alt (Shift+Option on macOS) while y'all drag your mouse. A separate cursor volition exist added to the end of each selected line.
You can also use keyboard shortcuts to trigger cavalcade choice.
Vertical rulers
You can add vertical cavalcade rulers to the editor with the editor.rulers setting, which takes an array of column character positions where you lot'd like vertical rulers.
{ "editor.rulers" : [ 20 , twoscore , threescore ] }
Fast scrolling
Pressing the Alt central enables fast scrolling in the editor and Explorers. Past default, fast scrolling uses a 5X speed multiplier only you tin control the multiplier with the Editor: Fast Scroll Sensitivity (editor.fastScrollSensitivity) setting.
Copy line up / down
Keyboard Shortcut: ⇧⌥↑ (Windows Shift+Alt+Upwardly, Linux Ctrl+Shift+Alt+Upwards) or ⇧⌥↓ (Windows Shift+Alt+Down, Linux Ctrl+Shift+Alt+Downwards)
The commands Re-create Line Up/Down are unbound on Linux considering the VS Code default keybindings would conflict with Ubuntu keybindings, see Effect #509. You tin still set the commands
editor.activity.copyLinesUpActionandeditor.activity.copyLinesDownActionto your own preferred keyboard shortcuts.
Move line up and downward
Keyboard Shortcut: ⌥↑ (Windows, Linux Alt+Up) or ⌥↓ (Windows, Linux Alt+Down)
Shrink / aggrandize selection
Keyboard Shortcut: ⌃⇧⌘← (Windows, Linux Shift+Alt+Left) or ⌃⇧⌘→ (Windows, Linux Shift+Alt+Right)
You tin acquire more in the Bones Editing documentation.
Go to Symbol in File
Keyboard Shortcut: ⇧⌘O (Windows, Linux Ctrl+Shift+O)
Yous tin can grouping the symbols by kind by adding a colon, @:.
Go to Symbol in Workspace
Keyboard Shortcut: ⌘T (Windows, Linux Ctrl+T)
Outline view
The Outline view in the File Explorer (default collapsed at the bottom) shows y'all the symbols of the currently open file.
You lot tin can sort by symbol name, category, and position in the file and allows quick navigation to symbol locations.
Navigate to a specific line
Keyboard Shortcut: ⌃K (Windows, Linux Ctrl+G)
Undo cursor position
Keyboard Shortcut: ⌘U (Windows, Linux Ctrl+U)
Trim trailing whitespace
Keyboard Shortcut: ⌘K ⌘X (Windows, Linux Ctrl+K Ctrl+Ten)
Transform text commands
You lot can modify selected text to capital letter, lowercase, and title case with the Transform commands from the Command Palette.
Code formatting
Currently selected source code: ⌘One thousand ⌘F (Windows, Linux Ctrl+K Ctrl+F)
Whole document format: ⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I)
Lawmaking folding
Keyboard Shortcut: ⌥⌘[ (Windows, Linux Ctrl+Shift+[) and ⌥⌘] (Windows, Linux Ctrl+Shift+])
You can too fold/unfold all regions in the editor with Fold All ( ⌘K ⌘0 (Windows, Linux Ctrl+K Ctrl+0)) and Unfold All ( ⌘G ⌘J (Windows, Linux Ctrl+One thousand Ctrl+J)).
You tin can fold all cake comments with Fold All Cake Comments ( ⌘Chiliad ⌘/ (Windows, Linux Ctrl+Chiliad Ctrl+/)).
Select electric current line
Keyboard Shortcut: ⌘L (Windows, Linux Ctrl+L)
Navigate to outset and end of file
Keyboard Shortcut: ⌘↑ (Windows, Linux Ctrl+Home) and ⌘↓ (Windows, Linux Ctrl+Stop)
Open Markdown preview
In a Markdown file, use
Keyboard Shortcut: ⇧⌘Five (Windows, Linux Ctrl+Shift+V)
Adjacent Markdown edit and preview
In a Markdown file, use
Keyboard Shortcut: ⌘Grand Five (Windows, Linux Ctrl+M V)
The preview and editor will synchronize with your scrolling in either view.
IntelliSense
⌃Infinite (Windows, Linux Ctrl+Space) to trigger the Suggestions widget.
You tin view available methods, parameter hints, short documentation, etc.
Peek
Select a symbol so type ⌥F12 (Windows Alt+F12, Linux Ctrl+Shift+F10). Alternatively, you can use the context menu.
Go to Definition
Select a symbol then type F12 . Alternatively, you tin can use the context menu or Ctrl+click (Cmd+click on macOS).
You can go back to your previous location with the Become > Dorsum command or ⌃- (Windows Alt+Left, Linux Ctrl+Alt+-).
Y'all can also run into the type definition if you press Ctrl (Cmd on macOS) when you lot are hovering over the type.
Become to References
Select a symbol then type ⇧F12 (Windows, Linux Shift+F12). Alternatively, you lot tin employ the context carte.
Find All References view
Select a symbol and so type ⇧⌥F12 (Windows, Linux Shift+Alt+F12) to open up the References view showing all your file's symbols in a dedicated view.
Rename Symbol
Select a symbol then type F2 . Alternatively, you lot can use the context menu.
Search and modify
Besides searching and replacing expressions, you can also search and reuse parts of what was matched, using regular expressions with capturing groups. Enable regular expressions in the search box by clicking the Use Regular Expression .* button ( ⌥⌘R (Windows, Linux Alt+R)) and so write a regular expression and use parenthesis to define groups. You tin can so reuse the content matched in each group by using $i, $2, etc. in the Replace field.
.eslintrc.json
Install the ESLint extension. Configure your linter however yous'd like. Consult the ESLint specification for details on its linting rules and options.
Here is configuration to employ ES6.
{ "env" : { "browser" : true , "commonjs" : truthful , "es6" : truthful , "node" : true }, "parserOptions" : { "ecmaVersion" : 6 , "sourceType" : "module" , "ecmaFeatures" : { "jsx" : true , "classes" : true , "defaultParams" : true } }, "rules" : { "no-const-assign" : 1 , "no-extra-semi" : 0 , "semi" : 0 , "no-fallthrough" : 0 , "no-empty" : 0 , "no-mixed-spaces-and-tabs" : 0 , "no-redeclare" : 0 , "no-this-earlier-super" : 1 , "no-undef" : 1 , "no-unreachable" : 1 , "no-use-before-define" : 0 , "constructor-super" : 1 , "curly" : 0 , "eqeqeq" : 0 , "func-names" : 0 , "valid-typeof" : 1 } } bundle.json
See IntelliSense for your parcel.json file.
Pismire syntax
Support for Emmet syntax.
Snippets
Create custom snippets
File > Preferences > User Snippets (Code > Preferences > User Snippets on macOS), select the linguistic communication, and create a snippet.
"create component" : { "prefix" : "component" , "body" : [ "grade $1 extends React.Component {" , "" , " \t return() {" , " \t\t return ($2);" , " \t }" , "" , "}" ] }, See more than details in Creating your own Snippets.
Git integration
Keyboard Shortcut: ⌃⇧Thousand (Windows, Linux Ctrl+Shift+Thousand)
Git integration comes with VS Lawmaking "out-of-the-box". You can install other SCM providers from the Extension Marketplace. This section describes the Git integration but much of the UI and gestures are shared by other SCM providers.
Diffs
From the Source Command view, select a file to open the unequal.
Alternatively, click the Open Changes button in the superlative right corner to diff the current open file.
Views
The default view for diffs is the next view.
Toggle inline view by clicking the More than Actions (...) push button in the pinnacle right and selecting Toggle Inline View.
If y'all prefer the inline view, yous can set "diffEditor.renderSideBySide": false.
Review pane
Navigate through diffs with F7 and ⇧F7 (Windows, Linux Shift+F7). This volition present them in a unified patch format. Lines tin be navigated with arrow keys and pressing Enter will jump back in the diff editor and the selected line.
Edit pending changes
You can make edits straight in the pending changes of the diff view.
Branches
Hands switch between Git branches via the Status Bar.
Staging
Stage file changes
Hover over the number of files and click the plus push button.
Click the minus button to unstage changes.
Stage selected
Stage a portion of a file by selecting that file (using the arrows) and so choosing Stage Selected Ranges from the Command Palette.
Disengage last commit
Click the (...) button and then select Disengage Last Commit to undo the previous commit. The changes are added to the Staged Changes section.
See Git output
VS Code makes it piece of cake to see what Git commands are actually running. This is helpful when learning Git or debugging a difficult source command issue.
Use the Toggle Output command ( ⇧⌘U (Windows Ctrl+Shift+U, Linux Ctrl+G Ctrl+H)) and select Git in the dropdown.
Gutter indicators
View diff decorations in editor. Encounter documentation for more details.
Resolve merge conflicts
During a merge, go to the Source Control view ( ⌃⇧Chiliad (Windows, Linux Ctrl+Shift+G)) and brand changes in the diff view.
Y'all can resolve merge conflicts with the inline CodeLens which lets you Accept Current Alter, Have Incoming Change, Take Both Changes, and Compare Changes.
Set VS Code equally default merge tool
git config --global merge.tool vscode git config --global mergetool.vscode.cmd 'code --wait $MERGED' Ready VS Code as default diff tool
git config --global unequal.tool vscode git config --global difftool.vscode.cmd 'code --wait --unequal $LOCAL $REMOTE' Debugging
Configure debugger
Open the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P)) and select Debug: Open launch.json, which will prompt yous to select the surroundings that matches your project (Node.js, Python, C++, etc). This will generate a launch.json file. Node.js support is congenital-in and other environments require installing the appropriate language extensions. See the debugging documentation for more details.
Breakpoints and stepping through
Place breakpoints adjacent to the line number. Navigate forrard with the Debug widget.
Data inspection
Inspect variables in the Run panels and in the console.
Logpoints
Logpoints act much like breakpoints but instead of halting the debugger when they are hit, they log a bulletin to the console. Logpoints are especially useful for injecting logging while debugging production servers that cannot be modified or paused.
Add a logpoint with the Add Logpoint command in the left editor gutter and it will be displayed as a "diamond" shaped icon. Log messages are apparently text merely can include expressions to exist evaluated within curly braces ('{}').
Chore runner
Auto observe tasks
Select Terminal from the peak-level menu, run the command Configure Tasks, then select the type of task you'd like to run. This will generate a tasks.json file with content like the following. See the Tasks documentation for more than details.
{ // See https://become.microsoft.com/fwlink/?LinkId=733558 // for the documentation nearly the tasks.json format "version" : "2.0.0" , "tasks" : [ { "type" : "npm" , "script" : "install" , "group" : { "kind" : "build" , "isDefault" : true } } ] } In that location are occasionally issues with auto generation. Check out the documentation for getting things to work properly.
Select Terminal from the height-level menu, run the control Run Task, and select the task you want to run. Terminate the running task by running the command Terminate Job
Ascertain keyboard shortcuts for tasks
You tin define a keyboard shortcut for whatsoever chore. From the Control Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P)), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.action.tasks.runTask command, and define the Task every bit args.
For example, to demark Ctrl+H to the Run tests task, add the following:
{ "key" : "ctrl+h" , "command" : "workbench.activity.tasks.runTask" , "args" : "Run tests" } Run npm scripts as tasks from the Explorer
From the explorer yous can open up a script in the editor, run it equally a task, and launch it with the node debugger (when the script defines a debug pick like --inspect-brk). The default action on click is to open the script. To run a script on a unmarried click, set npm.scriptExplorerAction to "run". Utilise the setting npm.exclude to exclude scripts in package.json files contained in detail folders.
With the setting npm.enableRunFromFolder, you tin enable to run npm scripts from the File Explorer'due south context menu for a folder. The setting enables the command Run NPM Script in Folder... when a folder is selected. The command shows a Quick Pick list of the npm scripts contained in this folder and you lot tin select the script to be executed as a chore.
Portable mode
VS Lawmaking has a Portable mode which lets you keep settings and information in the same location as your installation, for example, on a USB drive.
Insiders builds
The Visual Studio Code team uses the Insiders version to exam the latest features and bug fixes of VS Code. You tin also apply the Insiders version by downloading information technology here.
- For Early on Adopters - Insiders has the nigh recent code changes for users and extension authors to endeavour out.
- Frequent Builds - New builds every day with the latest bug fixes and features.
- Side-by-side install - Insiders installs side by side to the Stable build allowing you to use either independently.
Source: https://code.visualstudio.com/docs/getstarted/tips-and-tricks
0 Response to "File Currently Open"
Post a Comment