Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Ten tips to know about VS Code


May 31, 2021 Article blog


Table of contents


The article comes from the public number: Taobao front-end team, author Yu Bo

Often help some students One-on-One solve problems, in watching some students use VS Code, some lame, in fact, some useful skills can improve our daily work efficiency.

First, refactor the code

VS Code provides some quick refactoring of code, such as:

Extract a whole piece of code as a function: Select the source code fragment to extract, and then click the light bulb in the make-up slot to see which refactoring operations are available. C ode snippets can be extracted into a new method or within different scopes (current closure, within the current function, in the current class, within the current file). During the extraction refactoring, VS Code boots the function to be named.

 Ten tips to know about VS Code1

Extract an expression to a constant: Create a new constant for the currently selected expression.

 Ten tips to know about VS Code2

Move to a new file: Move the specified function to a new file, VS Code automatically names and creates the file, and introduces a new file within the current file.

 Ten tips to know about VS Code3

Convert the export method: export const name or export default

 Ten tips to know about VS Code4

Merge parameters: Combine multiple parameters of a function into a single object argument:

 Ten tips to know about VS Code5

Reference: Refactoring operations (code.visualstudio.com/docs/editor/refactoring), JS/TS refactoring operations (code.visualstudio.com/Docs/languages/typescript#_refactoring)

Second, customize the view layout

VS Code's layout system is flexible enough to move views from the activity bar and panel on the workbench.

 Ten tips to know about VS Code6

Reference: Rearrange the views (https://code.visualstudio.com/updates/v1_45?ref=codebldr#_dynamic-view-icons-and-titles )

Third, quickly debug the code

Debugging JS/TS code within VS Code is as simple as using the Debug: Open Link command. This is useful when debugging front-end or Node projects, which typically start a local service by simply filling in the local service address into the Debug: Open Link input box.

 Ten tips to know about VS Code7

Reference: Debug (https://code.visualstudio.com/docs/editor/debugging )

View and update references to symbols

View references to symbols, quickly modify the context of references: For example, a quick preview of where a function is called and when it is called context, and you can update the code of the calling context in the preview view.

 Ten tips to know about VS Code8

Rename symbols and their references: Then the example above, if you want to update the function name and all the calls, how do you do that? P ress F2 then type the new name you want, and then press Enter to submit. All references to the symbol will be renamed, and the operation will be cross-file.

 Ten tips to know about VS Code9

Ref: Peek (https://code.visualstudio.com/docs/editor/editingevolved#_peek), Rename Symbol (https://code.visualstudio.com/docs/editor/editingevolved#_rename-symbol )

V. Symbol navigation

Code positioning can be very painful when viewing a long file. S ome developers use a small map of VS Code, but there's a easier way to use ⇧⌘O shortcut to evoke the symbol navigation panel and quickly locate the code with symbols in the currently edited file. T ype characters in the input box to filter and navigate up and down through arrows in the list. This approach is also very friendly to Markdown files and can be quickly navigated by title.

 Ten tips to know about VS Code10

Reference: Go to Symbol (https://code.visualstudio.com/docs/editor/editingevolved#_go-to-symbol )

Six, split the editor

When editing files that are particularly informative, you often need to switch between them in context, when you can update the same file with two editors by splitting the editor: press the shortcut ⌘\ split the active editor into two.

 Ten tips to know about VS Code11

You can continue to split the editor endlessly and arrange the editor views by dragging and dragging the editor group.

 Ten tips to know about VS Code12

Reference: Side by side editing (https://code.visualstudio.com/docs/getstarted/userinterface#_side-by-side-editing )

Seven, rename the terminal

VS Code provides an integrated terminal that makes it easy to perform command-line tasks quickly. With a lot more often open multiple terminals, this time to name the terminal can improve the efficiency of terminal positioning.

 Ten tips to know about VS Code13

Reference: Rename terminal sessions (https://code.visualstudio.com/docs/editor/integrated-terminal#_rename-terminal-sessions )

Eight, Git operation

VS Code has built-in Git source control and provides some convenient ways to operate Git. For example:

Resolve Conflicts: VS Code identifies merge conflicts, differences in conflicts are highlighted, and inline actions are provided to resolve conflicts.

 Ten tips to know about VS Code14

Staging or undoing selected lines of code: You can undo modifications, staging modifications, and undoing staging for selected lines within the editor.

 Ten tips to know about VS Code15

Reference: Using Version Control in VS Code (https://code.visualstudio.com/docs/editor/versioncontrol )

Nine, search results snapshot

VS Code provides cross-file search capabilities, and search result snapshots provide more information about search results, such as the linecode of the code, the context of the search keyword, and the possible editing and saving of search results.

 Ten tips to know about VS Code16

Ref: Search Editors (https://code.visualstudio.com/updates/v1x43-search-editors )

Ten, visual construction page

Web pages can be generated visually in VS Code by installing the https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks plug-in for VS Code. Once the plug-in is installed, ⇧⌘P evoking the naming panel, entering Visual Build in the command panel evokes the visual build interface, which builds the page by selecting page elements, dragging layouts, setting element styles and properties, and finally clicking Build Code to generate React code.

 Ten tips to know about VS Code17

Here's a look at W3Cschool编程狮 introduction to the ten tips you need to know about VS Code, and I hope it will help you.