Orlandster
Orlandster

Reputation: 4868

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? (equivalent to Atom's or other IDE's Cmd+L on Mac)

And what would be the command I'm looking for? (e.g. 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.

Upvotes: 57

Views: 110048

Answers (10)

Gustavo Diaz Lome
Gustavo Diaz Lome

Reputation: 1

I have faced the same problem, and what I noticed is the following: there is a conflict with the Live Server extension that is using a chord shortcut. My solution was to add the same shortcut and press it down twice, as it says, as a chord.

Select Single Line Command+L

Upvotes: 0

abdullah itangishaka
abdullah itangishaka

Reputation: 41

The reason CMD+L is working may be that you have live server extension, it will create collision. Disable it or remove it or modify the shortcuts of live server.

Upvotes: 4

Daniel0007
Daniel0007

Reputation: 31

When the line is commented: (ctrl+k+c) on windows If the line is not a comment: (ctrl+k+u) on windows

Upvotes: 0

alexis19apl
alexis19apl

Reputation: 41

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

View from VScode Screenshot

Upvotes: 0

Zee
Zee

Reputation: 706

For VS Code 1.36 release, or greater, use CTRL-L to select the whole line, then, press TAB key to increase indent, or SHIFT-TAB to decrease indent.

Upvotes: 13

Tucker
Tucker

Reputation: 367

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

Upvotes: 12

Stephan Edmonson
Stephan Edmonson

Reputation: 521

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.

Picture that says it is awaiting an actual command:

picture that says it is awaiting an actual command

So what I did was simply delete the commands in the keyboard shortcut (i.e. + K + S) that were similar. 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. 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.

Keyboard shortcut search of cmd + l:

keyboard shortcut search of cmd + l

Hope this helps anyone that may need clarification on this!

Upvotes: 42

Pat Gilmour
Pat Gilmour

Reputation: 701

There are options to select an entire line or just the contents of a line as follows (Mac mappings):

  • Select Entire Line:Command+L

  • Select Contents of Line: Place Cursor in line content then Shift+Ctrl+Command+ (press right arrow twice)

If you want to assign your own keyboard shortcuts, in your shortcut preferences look for:

  • Entire Line: expandLineSelection

  • Select Contents of Line: editor.action.smartSelect.expand

(You can get to your Keyboard shortcuts by pressing Command+k, Command+s)

As a bonus there's also a command to Shrink the Selection:

  • Shrink Selection: Shift+Ctrl+Command+ (left arrow)

Upvotes: 10

Chetha
Chetha

Reputation: 109

  1. Go to PreferencesKeyboard Shortcuts

  2. Search for "expandLineSelection"
    Change Keybinding to any key you wish.

  3. If you want to use command+L as default, just change it back.

Upvotes: 3

mouche
mouche

Reputation: 1903

It's Cmd+I by default in VS Code versions prior to 1.32.

Starting from version 1.32 it's Cmd+L.

You could change it in Keyboard Shortcuts by searching for expandLineSelection.

Upvotes: 99

Related Questions