自訂捲軸

當您遇到長的程式碼檔案時,可能很難追蹤所有項目在檔案中的位置。 您可以自訂程式碼編輯器的捲軸,以獲得程式碼目前狀況的概觀。

註釋

您可以選擇捲軸是否要顯示程式碼變更、中斷點、書籤、錯誤與插入號位置等註釋。

  1. 選擇 [工具]>[選項]>[文字編輯器]>[所有語言]>[捲軸],以開啟 [捲軸] 選項頁面。

  2. 選取 [在垂直捲軸上顯示註釋],然後選取想要看到的註釋。 可用的註釋:

    • 變更
    • 標記
    • 錯誤
    • 插入號位置

    提示

    [顯示標記] 選項包含中斷點與書籤。

開啟大型程式碼檔案來試用看看,並取代一些在檔案中數個位置出現的文字。 捲軸會顯示出您改動過的內容,因此如果您改掉了不該更動的東西,可以將變更還原。

以下是在搜尋字串之後,捲軸呈現的外觀。 請注意,字串的所有執行個體都出現在捲軸中。

Visual Studio scroll bar after searching for a string

以下是取代字串所有出現處之後的捲軸外觀。 捲軸中的紅色標記顯示文字取代發生錯誤的位置。

Visual Studio scroll bar after replacing a string with errors

註釋表格

好奇哪些捲軸註釋及其相關聯的色彩符合哪些動作? 如需詳細資訊,請參閱下表。

程式碼變更

程式碼變更會在垂直捲動條最左邊加上註釋。

追蹤的檔案 (在 Git 存放庫中)

色彩 預設註釋 狀態 設定名稱
Screenshot of the default annotation in scroll bar that indicates a tracked addition that's saved. 未儲存 在原始檔控制下追蹤檔案新增
Screenshot of the default annotation in scroll bar that indicates a tracked addition that's unsaved. 已儲存 在原始檔控制下追蹤檔案新增
Screenshot of the default annotation in scroll bar that indicates a tracked deletion. 已刪除 在原始檔控制下追蹤檔案刪除
藍色 Screenshot of the default annotation in scroll bar that indicates a tracked modification that's unsaved. 未儲存 在原始檔控制下追蹤檔案修改
藍色 Screenshot of the default annotation in scroll bar that indicates a tracked modification that's saved. 已儲存 在原始檔控制下追蹤檔案修改

未追蹤的檔案 (不在 Git 存放庫中)

色彩 預設註釋 狀態 設定名稱
金卡 Screenshot of the default annotation in scroll bar that indicates change in a file before it's saved. 未儲存 在儲存之前追蹤檔案中的變更
Screenshot of the default annotation in scroll bar that indicates a change in a file after it's saved. 已儲存 在儲存之後追蹤檔案中的變更
藍色 Screenshot of the default annotation in scroll bar that indicates a reverted change in a file. 已還原 追蹤檔案中已還原的變更

標記

標記會在垂直捲動條的中間區段加上註釋。

色彩 預設註釋 設定名稱
深灰色 Screenshot of the default annotation in scroll bar that indicates a bookmark in a file. 書籤
黃色 Screenshot of the default annotation in scroll bar that indicates a find match status. 尋找相符項目
深紅色 Screenshot of the default annotation in scroll bar that indicates a breakpoint in a file. 中斷點
淺灰色 Screenshot of the default annotation in scroll bar that indicates a selection match in a file. 選取項目比對
藍色 Screenshot of the default annotation in scroll bar that indicates a view definition mark in a file. 檢視定義

錯誤、警告、資訊或建議

垂直捲動條最右側會標注錯誤、警告、資訊和建議。

色彩 預設註釋 設定名稱
Screenshot of the default annotation in scroll bar that indicates a syntax error in a file. 語法錯誤
Screenshot of the default annotation in scroll bar that indicates a warning in a file. 警告
藍色 Screenshot of the default annotation in scroll bar that indicates information in a file. 資訊
淺灰色 Screenshot of the default annotation in scroll bar that indicates a suggestion in a file. 建議省略符號 (...)

插入號位置

插入號位置也會在垂直捲動條最右邊加上註釋。

色彩 預設註釋 設定名稱
深藍色 Screenshot of the default annotation in scroll bar that indicates an overview caret in a file. 概觀插入號

顯示模式

捲軸有兩種模式:捲軸模式和地圖模式。

捲軸模式

捲軸模式會在捲軸上顯示註釋指標。 在捲軸上按一下會向上或向下捲動頁面,但不會跳至檔案中的該位置。

地圖模式

圖模式會以縮圖的方式將程式碼行顯示在捲軸上。 您可以在 [原始檔概觀] 中選擇值,以變更地圖欄的的寬度。 若要在您將指標停在地圖上時顯示大型程式碼預覽,請選擇 [顯示預覽工具提示] 選項。 摺疊的區域會以不同的陰影呈現,並且在您按兩下時展開。

提示

若要在地圖模式中關閉縮圖程式碼檢視,您可以將 [原始檔檢視] 設定為 [關閉]。 如果已選取 [顯示預覽工具提示],當您將指標暫留在捲軸上時,您仍然會看到該位置的程式碼預覽,且當您按一下時,游標仍然會跳至該位置。

下列影像顯示開啟地圖模式且寬度設定為 [中] 的搜尋範例:

Visual Studio scroll bar in map mode

下列影像顯示 [預覽工具提示] 選項:

Visual Studio scroll bar with a tooltip

提示

若要變更您在圖模式中看到的色彩,請選擇 [工具]>[選項]>[環境]>[字型和色彩]。 接下來,在 [顯示項目] 中,選擇前面加上 「概觀」的任何項目、進行您想要的色彩變更,然後選擇 [確定]