简体   繁体   English

如何在 Visual Studio Code 中选择一行?

[英]How do I select a single line within Visual Studio Code?

Using Microsoft's Visual Studio Code, how do I select a single line of code?使用 Microsoft 的 Visual Studio Code,如何选择单行代码? (equivalent to Atom's or other IDE's Cmd + L on Mac) (相当于 Mac 上 Atom 或其他 IDE 的Cmd + L

And what would be the command I'm looking for?我正在寻找的命令是什么? (eg editor.action.copyLinesDownAction ) (例如editor.action.copyLinesDownAction

It's quite confusing, since other selection shortucts like Cmd + A and Cmd + D are the same as in my previous IDE's.这很令人困惑,因为Cmd + ACmd + D等其他选择快捷方式与我以前的 IDE 中的相同。

It's Cmd + I by default in VS Code versions prior to 1.32.在 1.32 之前的 VS Code 版本中,默认情况下是Cmd + I。

Starting from version 1.32 it's Cmd + L .1.32版开始,它是Cmd + L

You could change it in Keyboard Shortcuts by searching for expandLineSelection .您可以通过搜索expandLineSelection在键盘快捷键中更改它。

As for me, I noticed that what was causing the issue was that there were similar keyboard shortcuts.至于我,我注意到导致问题的原因是有类似的键盘快捷键。 As a result, what fixed it was deleting the similar keys.结果,修复它的是删除类似的键。

So when I tried to use + L I noticed that there was this thing in the left corner.所以当我尝试使用 + L 时,我注意到左角有这个东西。

Picture that says it is awaiting an actual command:图片表示正在等待实际命令:

图片说它正在等待实际命令

So what I did was simply delete the commands in the keyboard shortcut (ie + K + S ) that were similar.所以我所做的只是删除键盘快捷键(即 + K + S )中相似的命令。 They ended up being shortcuts for the live server extension.它们最终成为实时服务器扩展的快捷方式。

You can see which ones are similar by typing cmd + L in the search bar for the keyboard shortcut.您可以通过在键盘快捷键的搜索栏中键入cmd + L来查看哪些相似。 Any command that starts with + L will take precedence over the single one that just uses + L hence the reason it didn't work for me.任何以 + L开头的命令都将优先于只使用 + L的单个命令,因此它对我不起作用。

Keyboard shortcut search of cmd + l : cmd + l 的键盘快捷键搜索:

cmd + l 的键盘快捷键搜索

Hope this helps anyone that may need clarification on this!希望这可以帮助任何可能需要澄清的人!

对于 VS Code 1.36 版本,使用CTRL - L选择整行,然后按TAB键增加缩进,或SHIFT - TAB减少缩进。

I googled the same question but with the need to delete an entire line in a single keystroke.我用谷歌搜索了同样的问题,但需要在一次按键中删除整行。 If you are in the same boat, the shortcut to delete the current line is Ctrl + Shift + k如果你在同一条船上,删除当前行的快捷方式是Ctrl + Shift + k

There are options to select an entire line or just the contents of a line as follows (Mac mappings):有以下选项可以选择整行或仅选择一行内容(Mac 映射):

  • Select Entire Line : Command + L选择整行Command + L

  • Select Contents of Line : Place Cursor in line content then Shift + Ctrl + Command + (press right arrow twice)线路的选择内容:在网上内容将光标然后按Shift + Ctrl键+指令+→(按右箭头两次)

If you want to assign your own keyboard shortcuts, in your shortcut preferences look for:如果您想分配自己的键盘快捷键,请在您的快捷键首选项中查找:

  • Entire Line : expandLineSelection整行expandLineSelection

  • Select Contents of Line : editor.action.smartSelect.expand选择行的内容editor.action.smartSelect.expand

(You can get to your Keyboard shortcuts by pressing Command + k , Command + s ) (您可以通过按Command + kCommand + s来访问您的键盘快捷键)

As a bonus there's also a command to Shrink the Selection:作为奖励,还有一个命令可以缩小选择:

  • Shrink Selection : Shift + Ctrl + Command + (left arrow)缩小选择Shift + Ctrl + Command + (向左箭头)
  1. Go to PreferencesKeyboard Shortcuts转到首选项键盘快捷键

  2. Search for " expandLineSelection "搜索“ expandLineSelection
    Change Keybinding to any key you wish.将 Keybinding 更改为您想要的任何键。

  3. If you want to use command + L as default, just change it back.如果您想使用command + L作为默认值,只需将其改回即可。

I was struggling also with the same need, and my advice is:我也在为同样的需求而苦苦挣扎,我的建议是:

Don't search for default key combination because those change from installation to installation unfortunately but, you have to option to search by keyword and then set the key combination you prefer the most:不要搜索默认组合键,因为不幸的是,这些组合从安装到安装都会发生变化,但是,您必须选择按关键字搜索,然后设置您最喜欢的组合键

The keyword to search the shortcut for selecting the whole current line is cursorLineEndSelect搜索选择整行的快捷方式的关键字cursorLineEndSelect

View from VScode Screenshot从 VScode 截图查看

当该行被注释时:(ctrl+k+c) on windows 如果该行不是注释:(ctrl+k+u) on windows

The reason CMD+L is working may be that you have live server extension, it will create collision. CMD+L 工作的原因可能是你有实时服务器扩展,它会产生冲突。 Disable it or remove it or modify the shortcuts of live server.禁用或删除它或修改实时服务器的快捷方式。

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 Visual Studio Code linter 忽略一行? - How do I make the Visual Studio Code linter ignore a line? 如何在 Visual Studio Code 中选择大括号内的文本? - How do I select text inside of braces in Visual Studio Code? 如何在Visual Studio代码中选择div的内部 - How do I select the insides of div in Visual Studio Code 如何在 Visual Studio 代码中折叠多个单行注释 - How to fold multiple single line comments in visual studio code 如何在单个 Visual Studio Code session 中并排打开同一个文件? - How do I open the same file side by side in a single Visual Studio Code session? 在 Visual Studio 代码中,如何将单个键盘快捷键分配给多种语言? - In Visual Studio code, how do I assign a single keyboard shortcut to multiple languages? 为什么 Visual Studio Code 中文件资源管理器中的子文件夹折叠成一行? - Why are sub-folders within the File Explorer in Visual Studio Code collapsing into a single line? Select 到 Visual Studio Code 行尾/行首 - Select to End/Beginning of Line in Visual Studio Code 如何在Visual Studio Code或dotnet命令行的两个程序之间链接源文件? - How do I link a source file between two proejcts in Visual Studio Code or dotnet command line? 如何查看在 Visual Studio Code 中删除某行之前存在的最后一次提交? - How do I see last commit that a line existed before it was deleted in Visual Studio Code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM