Select current line in intellij
Asked Answered
I

7

81

Is there any way to select the whole line at caret in IntelliJ 15? I know you can select the current word (ctl + w), go to beginning/end of line but I can't find a current line selection feature.

Immunogenetics answered 12/4, 2016 at 11:47 Comment(3)
Not sure if there is, but there are commands you can perform on that line without having to select it. For example, if you press Cmd+C (Mac) without selecting anything, that will copy the line under the caret (same with Cmd+X and cutting it). Also Cmd+Y will delete the current line, Cmd+D duplicate it, and Cmd+Shift+Up/Down arrows will move the line up or down.Strickler
Possible duplicate of How to select/copy current line without using mouse in IntelliJ IDEAIndented
Please see my comment in the answer below. There is a "Select Line at Caret" shortcut that has no default value for its shortcut.Importunity
I
164

Simply hit

ctrl+c

Note that for this to select the whole line, you need to ensure that nothing is already selected; otherwise it'll work as an usual "copy" command.

Isosceles answered 13/4, 2016 at 17:34 Comment(3)
What if you wanted to select multiple lines to duplicate them? ctrl+c just doesn't cut it. It seems IntelliJ envisioned using ctrl+w for this. Interestingly not mentioned anywhere in the answers for this question.Rabia
@o'rety ctrl+w is for highlighting only, and it is contextual. To highlight a whole line will be many presses of ctr+w - just to get the line highlighted. There is a shortcut called "Select Line at Caret" - interestingly, it has no value by default. I personally had this set to ctrl+alt+shift+,. So the "correct" answer to this question would be: set a shortcut for "Select Line at Caret" in your keymap: and use that.Importunity
@z33k, if you assign a keyboard shortcut to "Extend Line Selection" (I do Cmd + Shift + L to match the VSCode convention), then repeating the L selects multiple lines.Ribose
P
34
  1. move caret to line
  2. on Windows, press ctrl+shift+a . This popup appears, where you find Select Line at Caret
    enter image description here
  3. for quick access, you can specify a shortcut in Settings enter image description here
Puma answered 13/4, 2016 at 9:17 Comment(2)
Coming from VSCode, this would be slightly nicer if it selected the current line and positioned the caret at the beginning of the next line, so you could repeat the command to select the next line. As it is, you can only select the current line and repeating it does nothing.Ribose
@Ribose there is a "extend line selection" key that you can also set to any keyMars
B
12

I would like to also add the following from JetBrains website. Because, that what i was looking for here, but no one mentioned it.

1- To select text from the current caret position to the beginning/end of the current word:

Ctrl+Shift+Left, Ctrl+Shift+Right.

2- To select text from the caret position to the beginning/end of the current line:

Double-click Ctrl and press Home/End

3- To select text from the current caret position to the top/bottom of the screen:

Ctrl+Shift+Page Up, Ctrl+Shift+Page Down.

Bab answered 20/3, 2017 at 16:9 Comment(1)
For MacOS, selecting to end/beginning of document, function - shift - command - (right/left arrow).Jujube
K
8

If none of the above are working, I suggest using end and home keys in combination with shift allowing you to select lines quickly.

Kelsi answered 5/7, 2017 at 17:1 Comment(0)
N
4

Go to the end of the line and hit Ctrl+W. If you'll hit Ctrl+W at the beginning of the line it will select only one word.

Necolenecro answered 4/10, 2018 at 7:32 Comment(0)
V
4

Not a keyboard feature, but nice to use: to select the whole row just click on row number on the left of the code.

In addition to that you can click and drag selection.

Moreover, you can doubleclick on the number of the first line of method which results selection of the whole method.

Vaporous answered 27/7, 2021 at 15:31 Comment(1)
Please see https://mcmap.net/q/258122/-select-current-line-in-intellij if you are using IntelliJ's new UI.Fling
F
3

In IntelliJ's new UI the feature that allows selecting the whole row by clicking on the row number does not work by default, instead clicking on the row number adds a breakpoint.

To reenable this functionality you have to follow this procedure:

  1. Press Ctrl+Shift+A
  2. Type Breakpoints Over Line Numbers
  3. Disable

As described in https://www.jetbrains.com/help/idea/new-ui.html#gutter.

Fling answered 29/8, 2023 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.