」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > JS:VSCode 技巧

JS:VSCode 技巧

發佈於2024-07-30
瀏覽:709

JS: VSCode Tips

Discovering little tricks like that can really streamline your workflow. Here are some more tips and tricks for making the most out of your coding experience in VS Code, especially when you're working with Node.js:

1. Integrated Terminal

You already found out about using the terminal in VS Code, but did you know you can split terminals? Use Ctrl Shift 5 (or Cmd Shift 5 on Mac) to open a split terminal. This is great for running a server in one terminal while executing scripts or running tests in another.

2. Debugger

VS Code has a built-in debugger that works seamlessly with Node.js. Set breakpoints in your code by clicking in the gutter next to the line numbers, and then press F5 to start the debugger. You can step through your code, inspect variables, and view call stacks, making it much easier to find and fix issues.

3. Live Server Extension

If you're working on web projects, the Live Server extension is a game-changer. It automatically refreshes your browser whenever you save changes to your HTML, CSS, or JavaScript files. Just install the extension, right-click your index.html file, and select "Open with Live Server."

4. Emmet Abbreviations

For HTML and CSS, Emmet abbreviations can save you tons of time. For example, typing ul>li*5 and pressing Tab will generate an unordered list with five list items. It's like magic!

5. Prettier Extension

The Prettier code formatter helps keep your code consistent and clean. Install the Prettier extension and then format your code with Alt Shift F (or Option Shift F on Mac). You can also configure it to format your code on save.

6. Code Snippets

Custom snippets can speed up your coding. Go to File > Preferences > User Snippets and create a new snippet file for JavaScript. For example, you can create a snippet for a console log:

"log": {
    "prefix": "clg",
    "body": ["console.log('$1');"],
    "description": "Log output to console"
}

Now, typing clg followed by Tab will expand to console.log();.

7. IntelliSense

VS Code’s IntelliSense offers intelligent code completion, parameter info, and member lists. For JavaScript, it’s particularly useful when dealing with complex objects or unfamiliar libraries. You can trigger it manually by pressing Ctrl Space.

8. Extensions for Node.js

There are a few must-have extensions for Node.js developers:

  • Node.js Extension Pack: A collection of useful extensions like npm, ESLint, and Node.js Modules Intellisense.
  • Nodemon: This extension allows you to use the Nodemon utility which automatically restarts your Node.js application when file changes in the directory are detected.

9. Source Control Integration

VS Code has Git integration built-in. You can manage your repositories, stage changes, make commits, and even resolve merge conflicts directly from the editor. Use the Source Control panel on the left sidebar for all your Git operations.

10. Command Palette

The Command Palette (Ctrl Shift P or Cmd Shift P on Mac) is the gateway to all VS Code commands. You can quickly search and execute commands, open files, and run extensions without leaving your keyboard.

11. Multi-Cursor Editing

Place multiple cursors in your code by holding Alt (or Option on Mac) and clicking where you want to add a cursor. You can also use Ctrl Alt Down (or Cmd Option Down on Mac) to add a cursor below the current line. This is super handy for making the same edit in multiple places.

12. Explorer Shortcuts

Navigate your files quickly using the explorer panel on the left. Ctrl P (or Cmd P on Mac) brings up the quick open file menu, allowing you to jump to any file in your project with just a few keystrokes.

13. Task Runner

You can define tasks in VS Code to run scripts or commands with ease. Create a tasks.json file in the .vscode folder of your project and configure tasks like building your project or running tests.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "npm run build",
            "problemMatcher": []
        }
    ]
}

Now you can run your build task from the Command Palette or the terminal.

14. Code Lens

For JavaScript, Code Lens shows inline references to functions and variables, making it easier to see where they are used. Enable it in settings under Editor: Code Lens.

15. Bracket Pair Colorization

To make nested code easier to read, enable bracket pair colorization. This can be done by adding "editor.bracketPairColorization.enabled": true to your settings.json file.

16. Workspace Settings

VS Code allows you to configure settings specific to your project by adding a .vscode folder with settings.json inside your project directory. This is useful for maintaining consistent settings across team members.

{
    "editor.tabSize": 2,
    "files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true
    }
}

17. Remote Development

VS Code's Remote Development extensions let you work with code on remote machines or in containers. You can use the Remote - SSH extension to connect to a remote server or Remote - Containers to develop inside Docker containers. This is excellent for maintaining a consistent dev environment.

18. Settings Sync

You can sync your settings, extensions, and keyboard shortcuts across different devices using Settings Sync. Enable it from the gear icon in the bottom left, then "Turn on Settings Sync..." and sign in with your GitHub or Microsoft account.

19. Keyboard Shortcuts

Mastering keyboard shortcuts can significantly boost your productivity. Here are a few more handy ones:

  • Ctrl B (or Cmd B on Mac) to toggle the sidebar.
  • Ctrl (or Cmd on Mac) to open the integrated terminal.
  • Ctrl K, Ctrl S (or Cmd K, Cmd S on Mac) to open the keyboard shortcuts editor.

20. Extensions for Productivity

Explore these extensions to further enhance your productivity:

  • Bracket Pair Colorizer 2: Colors matching brackets to make nested code more readable.
  • Path Intellisense: Autocompletes filenames when you start typing a path in your import statements.
  • Todo Tree: Tracks TODO comments in your code and lists them in the explorer.

21. REST Client

The REST Client extension allows you to make HTTP requests directly from VS Code and view the responses. Create a .http or .rest file and write your requests:

GET https://api.github.com/users/octocat

Run the request by clicking "Send Request" above the request line.

22. Polacode

Polacode is an extension that lets you create beautiful code snapshots. You can use it to generate images of your code for documentation or sharing. Simply select the code, right-click, and select "Polacode: Open" to capture the snapshot.

23. CSS Peek

For front-end developers, CSS Peek allows you to view CSS definitions directly in your HTML file by hovering over class names or IDs.

24. GitLens

GitLens supercharges the built-in Git capabilities by providing insights into your repository. It shows who changed a line of code and when, helps with navigating through commit history, and even offers inline blame annotations.

25. Snippets and Extensions for Frameworks

Depending on your tech stack, there are specific snippets and extensions you might find useful:

  • React: The ES7 React/Redux/React-Native snippets extension offers shorthand snippets for creating components, hooks, and more.
  • Vue.js: Vetur is the go-to extension for Vue.js development, providing syntax highlighting, snippets, and more.
  • Angular: Angular Essentials pack includes Angular Language Service and other helpful tools.

26. Jupyter Notebooks

VS Code supports Jupyter Notebooks, making it an excellent tool for data science and machine learning projects. Install the Jupyter extension to create, edit, and run Jupyter notebooks directly in the editor.

27. Docker Integration

If you're working with Docker, the Docker extension is invaluable. It allows you to build, manage, and deploy containerized applications directly from VS Code. You can view containers, images, and registries all from the sidebar.

28. Markdown Preview

VS Code has built-in support for Markdown. You can preview Markdown files by opening the file and pressing Ctrl Shift V (or Cmd Shift V on Mac). This is great for writing documentation or README files.

29. Workspace Trust

VS Code introduces Workspace Trust, which allows you to control the level of trust you assign to the files within a workspace. This is especially useful when working with code from unknown sources, ensuring your environment remains secure.

30. Zen Mode

For those times when you need to focus, Zen Mode provides a distraction-free coding environment. Enter Zen Mode by pressing Ctrl K Z (or Cmd K Z on Mac). This hides all toolbars and panels, leaving you with just your code.

31. Code Navigation

Efficiently navigate your codebase with features like:

  • Go to Definition: F12 or right-click > Go to Definition.
  • Peek Definition: Alt F12 (or Option F12 on Mac) to view the definition inline.
  • Go to Symbol: Ctrl Shift O (or Cmd Shift O on Mac) to jump to symbols in the current file.

32. Project Manager

The Project Manager extension helps you manage and switch between multiple projects. It allows you to save your current project, list your recent projects, and quickly switch between them.

33. Code Spell Checker

Avoid embarrassing typos in your code and comments with the Code Spell Checker extension. It highlights spelling errors and offers suggestions, making your documentation and variable names more professional.

34. Git Graph

Visualize your repository’s commit history with the Git Graph extension. It provides a graphical representation of your branches, commits, and merges, making it easier to understand the flow of your project.

35. Version Control Diffing

VS Code has powerful diffing capabilities. You can compare files or view changes by selecting a file and pressing Ctrl D (or Cmd D on Mac). This is useful for reviewing changes before committing or resolving merge conflicts.

36. Code Metrics

The CodeMetrics extension provides complexity metrics for your code, helping you identify areas that might need refactoring. It shows the cognitive complexity of functions and classes, making it easier to maintain clean and efficient code.

37. Keybinding Customization

You can customize your keybindings to suit your workflow. Open the keybindings editor with Ctrl K Ctrl S (or Cmd K Cmd S on Mac) and modify existing shortcuts or create new ones.

38. File and Code Navigation

VS Code offers powerful file and code navigation capabilities:

  • Quick Open: Use Ctrl P (or Cmd P on Mac) to quickly open files by typing part of their name.
  • Navigate Back and Forward: Use Ctrl - and Ctrl Shift - (or Cmd - and Cmd Shift - on Mac) to move through your cursor history.
  • Breadcrumbs: Enable breadcrumbs to show the current location and hierarchy of your file at the top of the editor.

39. Auto Close Tag and Auto Rename Tag

These extensions are particularly useful for HTML and JSX development. Auto Close Tag automatically closes tags as you type, while Auto Rename Tag synchronizes changes between the opening and closing tags.

40. Project-Specific Extensions

Install extensions tailored to your specific project needs. For example, if you're working on a Python project, the Python extension provides a comprehensive set of tools including IntelliSense, linting, and debugging. For a Java project, consider the Java Extension Pack.

These tips should keep you busy for a while and supercharge your VS Code setup. Enjoy exploring all these features and happy coding, dude!

版本聲明 本文轉載於:https://dev.to/dariansdev/js-40-vscode-tips-2jmg?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 使用 NgRx 掌握 Angular 狀態管理
    使用 NgRx 掌握 Angular 狀態管理
    State management in Angular ensures that data is consistently and efficiently shared across all parts of an application. Instead of each component man...
    程式設計 發佈於2024-11-02
  • Hexabot 設定與視覺化編輯教學:建立您的第一個 AI 聊天機器人
    Hexabot 設定與視覺化編輯教學:建立您的第一個 AI 聊天機器人
    聊天機器人愛好者大家好!在本教程中,我們將引導您完成設定和使用開源 AI 聊天機器人建構器 Hexabot 的過程。我們將首先克隆 GitHub 儲存庫、安裝依賴項並為 Hexabot 配置環境變數。您還將學習如何使用 Docker 啟動專案、存取管理面板以及使用視覺化編輯器建立聊天機器人流程。 ...
    程式設計 發佈於2024-11-02
  • mysql_fetch_row()、mysql_fetch_assoc() 和 mysql_fetch_array():您應該選擇哪一個?
    mysql_fetch_row()、mysql_fetch_assoc() 和 mysql_fetch_array():您應該選擇哪一個?
    mysql_fetch_row()、mysql_fetch_assoc() 和mysql_fetch_array() 解釋背景:[&SQL&]如果您正在使用已棄用的MyMy擴充功能中,在從結果集中檢索資料的mysql_fetch_row()、mysql_fetch_assoc() 和mysql_fe...
    程式設計 發佈於2024-11-02
  • Next.js - 概述
    Next.js - 概述
    本文作為初學者友好的指南和使用 Next.js 的步驟。 Next.js 是一個用於建立 Web 應用程式的靈活框架。相反,它是一個建立在 Node.js 之上的 React 框架。 設定您的 Next.js 專案 要啟動新的 Next.js 項目,您需要在電腦上安裝 Node.js。 安裝 ...
    程式設計 發佈於2024-11-02
  • 如何在程式碼中使用 Unsplash 圖片
    如何在程式碼中使用 Unsplash 圖片
    身為從事新 SaaS 專案的開發人員,我需要直接透過 URL 連結一些 Unsplash 圖片。 最初,我看到一篇推薦使用 https://source.unsplash.com/ API 的文章(連結)。但是,此方法不再有效,僅從 URL 欄位複製連結並不能提供嵌入所需的直接圖像 URL。 h...
    程式設計 發佈於2024-11-02
  • 如何合併關聯數組、處理缺失鍵、填滿預設值?
    如何合併關聯數組、處理缺失鍵、填滿預設值?
    合併多個關聯數組並添加具有預設值的缺失列將關聯數組與不同的鍵集組合起來創建統一的數組可能具有挑戰性。這個問題探索了一種實現此目的的方法,所需的輸出是一個數組,其中鍵被合併,缺失的列用預設值填充。 為了實現這一點,建議結合使用 array_merge 函數精心設計的鍵數組:$keys = array(...
    程式設計 發佈於2024-11-02
  • 透過 testcontainers-go 和 docker-compose 來利用您的測試套件
    透過 testcontainers-go 和 docker-compose 來利用您的測試套件
    Welcome back, folks! Today, we will cover the end-to-end tests in an intriguing blog post. If you've never written these kinds of tests or if you stri...
    程式設計 發佈於2024-11-02
  • 以下是一些適合您文章的基於問題的標題:

**直接簡潔:**

* **如何在Windows控制台中正確顯示UTF-8字元? ** **
* **為什麼傳統方法無法顯示
    以下是一些適合您文章的基於問題的標題: **直接簡潔:** * **如何在Windows控制台中正確顯示UTF-8字元? ** ** * **為什麼傳統方法無法顯示
    在Windows 控制台中正確顯示UTF-8 字元使用傳統方法在Windows 控制台中顯示UTF-8 字元的許多嘗試均失敗正確渲染擴充字元。 失敗嘗試:一個使用 MultiByteToWideChar() 和 wprintf() 的常見方法被證明是無效的,只留下 ASCII 字元可見。此外,使用 ...
    程式設計 發佈於2024-11-02
  • ReactJS 的模擬介紹
    ReactJS 的模擬介紹
    ReactJS 19:重要部份 並發模式增強: ReactJS 19 中最大的改進是並發模式,它不僅在應用程式自身更新時保持UI 平滑和響應靈敏,而且還確保了無縫界面,尤其是在復雜的過渡(例如動畫)時。 改進的伺服器元件: 在 Python 的引領下,ReactJ...
    程式設計 發佈於2024-11-02
  • 首屆DEV網頁遊戲挑戰賽評審
    首屆DEV網頁遊戲挑戰賽評審
    我被要求對DEV團隊9月份組織的第一屆網頁遊戲挑戰賽提交的參賽作品進行評判,結果在10月初發布。 我們幾個月來一直在 DEV 上組織挑戰(迷你黑客馬拉松),併計劃宣布我們的第一個網頁遊戲挑戰。鑑於您在遊戲社群 和 dev.to 的專業知識和參與度,我們想知道您是否有興趣成為客座評審。 誰能對此說...
    程式設計 發佈於2024-11-02
  • 購買經過驗證的現金應用程式帳戶:安全可靠的交易
    購買經過驗證的現金應用程式帳戶:安全可靠的交易
    Buying verified Cash App accounts is not recommended. It can lead to security risks and potential account bans. If you want to more information just k...
    程式設計 發佈於2024-11-02
  • 為什麼 `std::function` 缺乏相等比較?
    為什麼 `std::function` 缺乏相等比較?
    揭開std::function 的等式可比性之謎難題:為什麼是std::&&]難題:為什麼是std:: function,現代C 程式碼庫的一個組成部分,不具備相等比較功能?這個問題從一開始就困擾著程式設計師,導致管理可呼叫物件集合的混亂和困難。 早期的歧義:在C 語言的早期草案中11 標準中,op...
    程式設計 發佈於2024-11-02
  • JavaScript 類型檢查 |程式設計教學
    JavaScript 類型檢查 |程式設計教學
    介紹 本文涵蓋以下技術技能: 在本實驗中,我們將探索一個 JavaScript 函數,該函數檢查提供的值是否屬於指定類型。我們將使用 is() 函數,它利用建構子屬性和 Array.prototype.includes() 方法來確定值是否屬於指定類型。本實驗將幫助您更了解 Jav...
    程式設計 發佈於2024-11-02
  • 使用 Streamlit 將機器學習模型部署為 Web 應用程式
    使用 Streamlit 將機器學習模型部署為 Web 應用程式
    介绍 机器学习模型本质上是一组用于进行预测或查找数据模式的规则或机制。简单地说(不用担心过于简单化),在 Excel 中使用最小二乘法计算的趋势线也是一个模型。然而,实际应用中使用的模型并不那么简单——它们通常涉及更复杂的方程和算法,而不仅仅是简单的方程。 在这篇文章中,我将首先构...
    程式設計 發佈於2024-11-02
  • ## utf8_unicode_ci 與 utf8_bin:哪一種 MySQL 排序規則最適合德國網站?
    ## utf8_unicode_ci 與 utf8_bin:哪一種 MySQL 排序規則最適合德國網站?
    為德語選擇最佳MySQL 排序規則為德語選擇最佳MySQL 排序規則在設計為德語受眾量身定制的網站時,支持像ä、 ü 和ß。當涉及特定於語言的要求時,排序規則的選擇起著重要作用。 字元集和排序規則對於字元處理,UTF-8 仍然是首選選項,提供廣泛的字元支援。至於排序規則,則需要考慮德語特定字元。 排...
    程式設計 發佈於2024-11-02

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3