15 个提高工作效率的 VS Code 键盘快捷键
快捷键 VSCode
![](/data/attachment/album/202106/13/123502pqfi45mgpf8847yf.jpg)


毫无疑问，微软的 [VS Code是最好的开源代码编辑器之一](https://itsfoss.com/best-modern-open-source-code-editors-for-linux/)。它与传说中的 Vim 不同，VS Code 不需要你是一个快捷键大师（LCTT 译注：以下都指键盘快捷键），开发者们对它大部分的功能都及其熟悉，且推崇备至。


但这并不意味着你不能成为快捷键大师，或者说你在 VS Code 中不应该使用快捷键。


在敲代码的时候，你可能需要用鼠标去执行其他的动作，比如在 VS Code 编辑器中切换终端，而此时你的代码流程会被打断，这是不是很讨厌？如果是的，那么你应该立即熟记下面这些 VS Code 有用的快捷键。


它不仅能帮助你摆脱鼠标，还能使你的生产力和工作效率得到提高。


那么，让我们来了解一下如何通过使用快捷键快速进行代码导航来进行快速编码。


### 有用的 VS Code 快捷键


免责声明。下面的这些快捷键是我在 VS Code 的使用中发现的较为有用的，你可以根据你的需要来发现更多有用的快捷键。


下面我还给出了 MacOS 用户的键盘快捷键。


#### 1、显示所有命令




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + SHIFT + P` 或 `F1` | `SHIFT + ⌘ + P` 或 `F1` |


我们从最有用的快捷键开始，这个快捷键能打开命令面板（列表），它提供了对 VS Code 所有功能的访问。


![命令面板](/data/attachment/album/202106/13/123816ja9b49a66g43a2a4.jpg)


这是一个非常重要的 VS Code 快捷键，因为即使你忘记了或不想记起其他任何快捷键，但你记得这个，那么你仍然可以使用命令面板进行各种操作，如创建新文件、打开设置、改变主题，还可以查看所有快捷键。


#### 2、垂直和水平拆分 VS Code 编辑器




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + \` | `⌘ + \` |


为了提高效率，但你又没有安装多个显示器，那么你可以通过水平或垂直分割 VS Code 的编辑器来一次查看多个文件的代码。


![分割 VS Code 编辑区](/data/attachment/album/202106/13/123816y913894393uj1a4h.png)


要在多个编辑区间切换焦点，你可以使用数字键或箭头键。




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + 1`/`2`/`3` | `⌘ + 1`/`2`/`3` |
| `CTRL + K` `CTRL + ←`/`→` | `⌘ + K` `⌘ + ←`/`→` |


#### 3、切换集成终端




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + `` | `⌘ + `` |


VS Code 中的集成终端是一个非常方便的功能，它可以让你在不切换窗口的情况下快速执行任务。要在编辑器中显示/隐藏终端，下面的快捷键会非常方便。


![集成终端](/data/attachment/album/202106/13/123817a8b3bbu3f2ozj5c8.png)


但是，如果你跟我一样觉得 CTRL + ` 在键盘的角落位置而比较难按到，你可以打开命令面板执行`View: Toggle Terminal` 命令来切换终端。


![使用命令面板切换终端](/data/attachment/album/202106/13/123817w0q52878z2jbqfcb.png)


#### 4、转到文件




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + P` | `⌘ + P` |


随着项目的壮大，查找文件可能会变得困难。因此，我建议，即使你使用鼠标，这个命令也能为你节省很多搜索和导航到版本库中的文件的时间。


![转到文件](/data/attachment/album/202106/13/123818xhx48eeu4reixwhh.jpg)


#### 5、转到行




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + G` | `^ + G` |


当你找到文件，你可能需要去到文件中指定的行增加或编辑代码，而如果这个文件包含了数千行代码，那么滚动代码将会浪费你大量的时间。而 `CTRL + G` 或 `^ + G` 快捷键能让你快速的去掉指定的行。


![转到行](/data/attachment/album/202106/13/123818uxcbwiwl66btzl4b.jpg)


另外，你也可以使用上面的转到文件的快捷键，在输入框中输入冒号 `:` 加行号，结果就跟转到行是一样的。


#### 6、在整个项目中搜索




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + SHIFT + F` | `⌘ + SHIFT + F` |


很可能你需要在整个项目中搜索一个文本、变量或函数，在这种情况下，上面的命令就非常方便，它会在侧边栏显示一个搜索输入框。


![在项目中搜索](/data/attachment/album/202106/13/123819naol1ljfk6ys1jor.jpg)


我们还可以在搜索的时候添加一些过滤器，比如使用 `ALT+C` 来启用大写匹配，`ALT+W` 用于匹配整个单词，`ALT+R` 用于启用正则表达式。


#### 7、禅模式




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + K Z` | `⌘ + K Z` |


想要在不受干扰的环境中工作以保持更专注？ 你可以试试禅模式（先按下 `CTRL + K`，再按下 `Z`），它会隐藏所有 UI（状态栏、活动栏、面板和侧边栏）并仅在全屏上显示编辑器。


![禅模式](/data/attachment/album/202106/13/123819ixsa92fger19ra12.png)


要启用禅模式，你可以使用上面的快捷键或者打开命令面板执行 `View: Toggle Zen Mode`，要退出禅模式，你可以按两次 `Esc` 键。


#### 8、将选择添加到下一次匹配中




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + D` | `⌘ + D` |


这条命令能让你选择所选文本的下一个出现的地方，从而进行编辑。如果下一个匹配出现的位置与第一个相离较远，那这将会很方便处理。


![查找下一个匹配](/data/attachment/album/202106/13/123820yo4scocyj7os32oo.jpg)


#### 9、切换行注释




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + /` | `⌘ + /` |


将光标移到行的开头，然后添加双斜杠进行注释，这种麻烦的操作我们可以用上面的快捷键来代替了。


![注释代码](/data/attachment/album/202106/13/123820hz5uu0skd00k3pz2.jpg)


甚至，如果你想注释多行代码，你可以先通过 `SHIFT+UP`/`Down` 快捷键来选中多行，然后按 `CTRL+/` 快捷键进行注释。


#### 10、转到文件的开头或结尾




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + HOME`/`END` | `⌘ + ↑`/`↓` |


如果你迷失在文件的中间位置，该命令可以让你快速达到文件的起点或终点。


#### 11、代码折叠或打开




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + SHIFT + [`/`]` | `⌥ + ⌘ + [`/`]` |


这也是最有用的快捷键之一，它可以帮助你折叠/取消折叠一个区域的代码。通过这种方式，你可以隐藏不必要的代码，每次只查看所需的部分代码，以便更加专注和快速编码。


![折叠一块代码](/data/attachment/album/202106/13/123821g1o7qaul37o7zcch.jpg)


#### 12、窥视执行




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + SHIFT + F12` | `⌘ + SHIFT + F12` |


这个快捷键最有可能的作用是帮助你进行代码分析，或修复 bug 时了解函数和变量的运行情况。


![窥视执行](/data/attachment/album/202106/13/123821zp475t98vvfipvdf.png)


#### 13、删除当前行




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + SHIFT + K` | `SHIFT + ⌘ + K` |


这是一条可以快速执行，选中当前行并按删除/退格键，这两个任务的简单命令。


#### 14、查找与替换




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + F` | `⌘ + F` |
| `CTRL + H` | `⌥ + ⌘ + F` |


用一个新的文本替换文件中所有出现的该文本的最好方法是什么？如果你手动一个一个的通过滚动代码来处理，且如果需要替换的地方又很多，那么你可能会花费大量的时间。


![查找与替换](/data/attachment/album/202106/13/123822rqm0inni8v8a3eaq.png)


而使用查找和替换功能我们能在几秒内完成相同的任务。你可以用两个快捷键来打开它，其中一个实际上是打开用于查找文本的输入框，另一个用于输入新的文本。


#### 15、VS Code 的全部键盘快捷键




| Windows/Linux | macOS |
| --- | --- |
| `CTRL + K CTRL + S` | `⌘ + K ⌘ + S` |


最后，如果你还在为记住上述所有的快捷键而苦恼，你大可不必。因为你可以使用上面的快捷键查看编辑器所有可用的命令。


![快捷键](/data/attachment/album/202106/13/123822m77zw79ax074w7wa.png)


你还可以根据自己的喜好编辑命令的绑定键。


### 想要为 VS Code 添加更多快捷键？


如果你想对 VS Code 的快捷键有完整的了解，你可以查看 VS Code 的 [文档](https://code.visualstudio.com/docs/getstarted/keybindings)。


或者，如果你想在纸上将所有快捷键打印出来慢慢看，下面这些是各个系统对应的快捷键速查表： [Linux](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf)、[macOS](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf) 和 [Windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf)。




---


via: <https://itsfoss.com/vs-code-shortcuts/>


作者：[Sarvottam Kumar](https://itsfoss.com/author/sarvottam/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[ywxgod](https://github.com/ywxgod) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

There is no doubt that Microsoft’s [VS Code is one of the best open source code editor](https://itsfoss.com/best-modern-open-source-code-editors-for-linux/) out there. Unlike the legendary Vim, VS Code doesn’t need you to be a keyboard ninja and has tons of features that developers swear by.

But this doesn’t mean you cannot, or you should not use keyboard shortcuts in [Visual Studio Code](https://itsfoss.com/install-visual-studio-code-ubuntu/).

Do you hate breaking your coding flow and move your hand to a mouse for performing an action like toggling terminal in your Visual Studio Code (VS Code) editor? If yes, then you should immediately get yourself familiar and memorize these useful keyboard shortcuts for VS Code.

It will not just help you to get rid of a mouse, but also make you highly productive and efficient.

So, let’s get to know how you can code fast by quickly navigating through the code editor using keyboard shortcuts.

## Useful VS Code Keyboard Shortcuts

I have also mentioned keyboard shortcuts for macOS users.

### 1. Show All Commands

Windows/Linux | macOS |
---|---|

CTRL + SHIFT + P or F1 | SHIFT + ⌘ + P or F1 |


Starting with the most helpful shortcut, it opens the Command Palette that provides access to all the functionality of VS Code.

![VS Code Command Palette visibke when the appropriate keyboard shortcut is pressed](https://itsfoss.com/content/images/2023/04/Command-Palette.webp)

It is a very important VS Code Shortcut because even if you forget or don’t want to remember any shortcut except this one, you can still perform various operations using Command Palette like create a new file, open settings, change theme, and view all keyboard shortcuts as well.

### 2. Split VS Code Editor Vertically Or Horizontally

Windows/Linux | macOS |
---|---|

CTRL + \ | ⌘ + \ |


If you don’t have a multi-monitor setup for high productivity, you can still view codes of multiple files at once by splitting the editor either horizontally or vertically.

![Split Mode in VS Code where multiple files are opened in a grid like arrangement](https://itsfoss.com/content/images/2023/04/Split-VS-Code.webp)

To change focus into editor group, you can either use number or arrow keys.

Windows/Linux | macOS |
---|---|

CTRL + 1/2/3 | ⌘ + 1/2/3 |

CTRL + K CTRL + ←/→ | ⌘ + K ⌘ + ←/→ |


### 3. Toggle Integrated Terminal

Windows/Linux | macOS |
---|---|

CTRL + ` | ⌘ + ` |


Integrated terminal in VS Code is a very convenient feature that lets you execute the task quickly without switching windows. To hide/unhide the terminal in the editor, this keyboard shortcut comes in very handy.

![A Integrated terminal opened in VS Code](https://itsfoss.com/content/images/2023/04/Integrated-Terminal.webp)

However, like me, if you find pressing "**CTRL+`**" difficult to use due to its weird corner location, you can still open Command Palette and execute `View: Toggle Terminal`

command.

![Toggle terminal using Command Palette](https://itsfoss.com/content/images/2023/04/Toggle-Terminal-Using-Command-Palette.webp)

### 4. Go To File

Windows/Linux | macOS |
---|---|

CTRL + P | ⌘ + P |


As the project grows, looking for a file might become a very difficult task. Hence, I would suggest even you use a mouse, this command can save you a lot of time in searching and navigating to a file in a repository.

![Go to a particular file in VS Code using the search and navigation feature](https://itsfoss.com/content/images/2023/04/Go-to-file.webp)

### 5. Go To Line

Windows/Linux | macOS |
---|---|

CTRL + G | ^ + G |


Once you search a file, you may now want to jump to a specific line for adding or editing code. If a file contains thousands of lines of code, scrolling can definitely eat up your time. Hence, CTRL+G or ^+G VS Code Keyboard Shortcut can quickly take you to a line you want.

![Jump to a particular line by specifying the required line number](https://itsfoss.com/content/images/2023/04/Go-to-line.webp)

Alternatively, you can also use the fourth shortcut for ‘Go To File,’ where appending `:`

colon with line number in the input box works as ‘Go To Line.’

### 6. Search Complete Project

Windows/Linux | macOS |
---|---|

CTRL + SHIFT + F | ⌘ + SHIFT + F |


Most probably, you may also want to search for a text, variable, or function in your whole project. In such a case, this command is very convenient that shows search input in the sidebar.

![Search project from the](https://itsfoss.com/content/images/2023/04/Search-project.webp)

You can also add filters to your search using ALT+C to match case, ALT+W to match the whole word, and ALT+R to use regular expression.

### 7. Zen Mode

Windows/Linux | macOS |
---|---|

CTRL + K Z | ⌘ + K Z |


Want to work in a distraction-free environment to stay more focused? Zen mode is a feature in a VS Code that hides all UI (Status Bar, Activity Bar, Panel, and Sidebar) and displays only the editor on a full screen.

![Zen Mode or the distraction free mode in VS Code](https://itsfoss.com/content/images/2023/04/Zen-Mode.webp)

To enable Zen Mode, you can either use the above shortcut or open Command Palette and execute “View: Toggle Zen Mode.” To exit Zen mode, you need to press `Esc`

button twice.

### 8. Add Selection To Next Find Match

Windows/Linux | macOS |
---|---|

CTRL + D | ⌘ + D |


This command enables you to select the next occurrences of a selected text for editing. It comes very handy if the next match is located far away from the first match.

![Select the next occurrences of a selected text for editing](https://itsfoss.com/content/images/2023/04/Next-find-match.webp)

### 9. Toggle Line Comment

Windows/Linux | macOS |
---|---|

CTRL + / | ⌘ + / |


The struggle to reach the start of a line and then add a double forward slash to the comment line can be replaced with this quick keyboard shortcut.

![Quickly comment out lines using the keyboard shortcut](https://itsfoss.com/content/images/2023/04/Comment-out-code.webp)

Even if you want to comment out multiple lines, you can select all lines using `SHIFT+UP/Down`

and then press `CTRL+/`

.

### 10. Jump To The Beginning Or End Of File

Windows/Linux | macOS |
---|---|

CTRL + HOME/END | ⌘ + ↑/↓ |


If you get lost in the middle of your codes, the command can help to quickly reach either start or end of the file.

### 11. Code Folding Or Unfolding

Windows/Linux | macOS |
---|---|

CTRL + SHIFT + [ or ] | ⌥ + ⌘ + [ or ] |


It is one of the most useful shortcuts that can help you collapse/uncollapse a region of code. In this way, you can hide unnecessary code and view only the required section of code at a time to focus more and code fast.

![Fold or unfold blocks of code by clicking on the expand symbol](https://itsfoss.com/content/images/2023/04/Collapse-a-region-of-code.webp)

### 12. Peek Implementation

Windows/Linux | macOS |
---|---|

CTRL + SHIFT + F12 | ⌘ + SHIFT + F12 |


The shortcut is most likely to help you in your code analysis or bug fixing where you want to understand the working of functions and variables.

![Peek Implementation for code analysis](https://itsfoss.com/content/images/2023/04/Peek-Implementation.webp)

### 13. Delete Current Line

Windows/Linux | macOS |
---|---|

CTRL + SHIFT + K | SHIFT + ⌘ + K |


A single quick command can sum up two tasks of selecting a current line and pressing the delete/backspace button.

### 14. Find And Replace

Windows/Linux | macOS |
---|---|

CTRL + F | ⌘ + F |

CTRL + H | ⌥ + ⌘ + F |


What could be the best way to replace all occurrences of a text in a file with a new one? If you go for one by one manually by scrolling down the code, no wonder how much time it will take if text occurrence is large.

![Find and Replace text in VS Code](https://itsfoss.com/content/images/2023/04/Find-and-replace.webp)

While using Find and Replace do the same task within seconds. You can open it using two shortcuts where one actually opens the input box for finding text and the other for replacing text.

### 15. VS Code Keyboard Shortcuts

Windows/Linux | macOS |
---|---|

CTRL + K CTRL + S | ⌘ + K ⌘ + S |


At last, if you still struggle with remembering all the above keyboard shortcuts, you still don’t have to worry. This is because you can view all available commands for your editor using the above shortcut.

![Available Keyboard Shortcuts listed in VS Code](https://itsfoss.com/content/images/2023/04/Keyboard-Shortcuts.webp)

You can also edit keybinding for the command as per your comfort.

Here is a summary of all the keyboard shortcuts discussed above.

Usage | Linux/Windows | macOS |
---|---|---|

Opens Command Palette | CTRL + SHIFT + P or F1 | SHIFT + ⌘ + P or F1 |

Split Editor Vertically Or Horizontally | CTRL + \ | ⌘ + \ |

Change focus into editor group | CTRL + 1/2/3 | ⌘ + 1/2/3 |

CTRL + K CTRL + ←/→ | ⌘ + K ⌘ + ←/→ | |

Toggle Integrated Terminal | CTRL + ` | ⌘ + ` |

Searching and navigating to a file in a repository | CTRL + P | ⌘ + P |

Jump to a specific line | CTRL + G | ^ + G |

Search for a text, variable, or function in your whole project | CTRL + SHIFT + F | ⌘ + SHIFT + F |

Zen Mode (distraction-free environment) | CTRL + K Z | ⌘ + K Z |

Select the next occurrences of a selected text | CTRL + D | ⌘ + D |

Toggle Line Comment | CTRL + / | ⌘ + / |

Jump To The Beginning Or End Of File | CTRL + HOME/END | ⌘ + ↑/↓ |

Code Folding Or Unfolding | CTRL + SHIFT + [ or ] | ⌥ + ⌘ + [ or ] |

Peek Implementation to understand the working of functions and variables. | CTRL + SHIFT + F12 | ⌘ + SHIFT + F12 |

Delete Current Line | CTRL + SHIFT + K | SHIFT + ⌘ + K |

Find And Replace | CTRL + F | ⌘ + F |

CTRL + H | ⌥ + ⌘ + F | |

VS Code Keyboard Shortcuts | CTRL + K CTRL + S | ⌘ + K ⌘ + S |


## Want More on VS Code?

If you want to have complete knowledge of VS Code keyboard shortcuts, you can check out the [documentation](https://code.visualstudio.com/docs/getstarted/keybindings?ref=itsfoss.com) of Visual Studio Code.

Or, if you want all available shortcuts in a single piece of paper, get the above cheat sheet for [Linux](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf?ref=itsfoss.com), [macOS](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf?ref=itsfoss.com), and [Windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf?ref=itsfoss.com). You can have a quick look whenever you forget.

Once you learn keyboard shortcuts on VS Code, see how to make your code neat with [VS Code auto intend feature](https://itsfoss.com/auto-indent-vs-code/).

[How to Automatically Indent Your Code in Visual Studio CodeFormat your code correctly. Learn how to automatically indent code in Visual Studio Code.](https://itsfoss.com/auto-indent-vs-code/)![](https://itsfoss.com/content/images/wordpress/2022/11/automatically-indent-vscode.png)


![](https://itsfoss.com/content/images/wordpress/2022/11/automatically-indent-vscode.png)

I think you already know to connect VS Code with GitHub?

[How to Connect GitHub to VS Code [Step by Step]Take your coding experience to the next level of ease by integrating GitHub into VS Code.](https://itsfoss.com/vs-code-github/)![](https://itsfoss.com/content/images/2023/04/integrate-github-with-vscode.png)


![](https://itsfoss.com/content/images/2023/04/integrate-github-with-vscode.png)

If the built-in telemetry is holding you back from using VS Code, try VSCodium.

[VSCodium: 100% Open Source Version of Microsoft VS CodeBrief: VSCodium is a clone of Microsoft’s popular Visual Studio Code editor. It’s identical to VS Code with the single biggest difference that unlike VS Code, VSCodium doesn’t track your usage data. Microsoft’s Visual Studio Code is an excellent editor not only for web developers but](https://itsfoss.com/vscodium/)![](https://itsfoss.com/content/images/wordpress/2019/04/vscodium.png)


![](https://itsfoss.com/content/images/wordpress/2019/04/vscodium.png)

Let me know your favorite shortcut in the comment section.