Sometimes I have to write Java class where I need to define multiple fields of the same type. For example, I know that I will need to duplicate private final String on the next 4 lines.
Is it possible to spawn multiple carets in IntelliJ editor, so I can type on mutliple lines at the sime time?
IntelliJ IDEA 14.1 & 15
You can press Alt + Shift and using the mouse left click you can put many carets.
E.g.:
will become
typing "added" only once.
If you want to have a continuous vertical line, it's enough to press Alt + drag your mouse vertically. If there are lines with a length lower than the current position, the vertical line will be broken (carets will be placed at the end of every line) if "Allow placement of caret after end of line" is disabled (in File > Settings... > Editor > General > Virtual Space).
Another way to add a continuous vertical line is to hit Ctrl twice and then press up or down arrow key (supported in JetBrains 2016.X products, and possibly earlier).
If you cannot get the shortcuts working, check what they're currently assigned to under Settings > Keymap Add or Remove Caret, Clone Caret Above and Clone Caret Below. If they look right and you're on Linux, your window manager may be capturing the combination, e.g., for Alt + window drag operations.
See:
http://blog.jetbrains.com/idea/2015/02/multiple-selections-in-editor-using-mouse/
https://www.jetbrains.com/help/idea/2016.3/multicursor.html
I think "Column Selection Mode" could help you. You can enable it in the context menu in the editor. Then you can select multiple lines and type same text at once.
Column Select
For Windows, you can use CTRL+CTRL(Hold)+↑ / ↓. For Mac, replace the CTRL with ⌘.
Change Multi-caret Hotkey
To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.
I mapped mine to ALT+SHIFT+↑ / ↓.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.
On Windows:
You can enable the Column Selection Mode (Alt + Shift + Insert)
And then Shift + ↑ / ↓ can select multiple columns
Hit Esc to go back to single cursor
Add/remove a caret: Alt + Shift + Mouse Click
Remove all carets: Esc
As for now(2018.9), you just:
Press middle mouse key to create a four-rows-high caret
Type what you want
Or,
Create the first line,
Press the "Duplicate entire line" key combination to create a new, identical line.
By the way, I think "multiple caret" should be like carets enabling me to edit different locations which are not necessarily vertically aligned. In Sublime Text you can press Ctrl and click. And in IntelliJ you can only "Clone caret up/down", that is to say, they are vertically aligned, which is not flexible.
Related
In OCaml's utop, I can use alt+left or alt+right to move through autocomplete sections, but when I click tab to autocomplete the first selection is used. What do I do?
You can complete with the current selection with alt+down.
If you type in #utop_bindings;;, you can see all keybindings.
You may also customize your bindings by creating a ~/.lambda-term-inputrc-file, for example:
[read-line]
tab: complete-bar
See: https://github.com/ocaml-community/utop#key-bindings
How to select multiple places in code in Android Studio ?
I want to insert the same text in multiple places in my source code. Like a have more than one mouse cursor. I used to do it in VS2012 so easily though not sure how to do it in Android Studio ?
I found how and lets share this cool feature with you. I found three cool features:
For multiple selection just hold alt + shift then select whenever you want to change by mouse click then type some thing you can write at multiple places at the same time.
Another cool feature is column selection. This lets you to click in a great manner and greatly of help especially when you are refactoring.
In most systems it works with holding middleMouseButton and dragging over your code and in others it works by holding alt and selecting code it acts like below:
the third cool feature is sublime selection it finds the same word in code and let you change that or append that easily. you can do that by pressing alt + j on Windows / Linux and ctrl + g in mac. Look how it works:
Also as #Narayana said in comments, Ctrl + Shift + Alt + j selects all occurrences in one shot, for one-shot refactoring.
You can use Alt + Shift and click multiple locations to for multiple cursor.
To select similar occurrences in files use Alt + j.
For more details : Click Here
Multiline Caret (without mouse)
Windows: CTRL + CTRL(Hold) + ↑ / ↓
Mac: ⌘ + ⌘(Hold) + ↑ / ↓
ESC will end multiline mode.
Change Multi-caret Hotkey
To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.
I mapped mine to ALT+SHIFT+↑ / ↓.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.
For both Mac and Windows, just open the Context Menu and click on the "Column selection mode" to enable or disable the behaviour..
On a MacOS you can use:
Tap: Control + Command + G - Select all the same value
Tap: Control + G - Every tap combination select the new same value
Hold: Option + Mouse Click - Select multiline with a mouse
Hold: Option + Shift and Tap: Mouse Click - duplicate cursor for a each tap place
Press Shift + Alt + Insert combination to edit in Column selection mode.
On a mac I like to do ⌥ (option) + shift + mouse click on multiple lines in Android Studio 3.1.3.
Use the following:
ALT + SHIFT
on Mac , hold OPTION + SHIFT then use the mouse to highlight what you want to select
On Windows, you can try a plugin whose name is ConyEdit. It has a great column mode based on regular expression.
I'm using android studio arctic fox and pressing Alt alone and then selecting code is working properly in windows.
I use setxkbmap to define layout change shortcut as ctrl+shift, as I am used to. But I face a problem sometimes that it clashes with shortcuts of the software I use, like ctrl+shift+A. How can I avoid changing layout when I press ctrl+shift+other_button? I use OpenSuse Linux with i3 wm.
There isn't really a way around this if you want to use ctrl+shift to switch you layouts because ctrl+shift is now caught by xkb at a lower level than the applications you are using. I had the same issue and just switched to using both ctrls to change layout. Have a look at
$ grep 'grp:' /usr/share/X11/xkb/rules/base.lst
grp:switch Right Alt (while pressed)
grp:lswitch Left Alt (while pressed)
grp:lwin_switch Left Win (while pressed)
grp:rwin_switch Right Win (while pressed)
grp:win_switch Any Win key (while pressed)
grp:caps_switch Caps Lock (while pressed), Alt+Caps Lock does the original capslock action
grp:rctrl_switch Right Ctrl (while pressed)
grp:toggle Right Alt
grp:lalt_toggle Left Alt
grp:caps_toggle Caps Lock
grp:shift_caps_toggle Shift+Caps Lock
grp:shift_caps_switch Caps Lock (to first layout), Shift+Caps Lock (to last layout)
grp:win_menu_switch Left Win (to first layout), Right Win/Menu (to last layout)
grp:lctrl_rctrl_switch Left Ctrl (to first layout), Right Ctrl (to last layout)
grp:alt_caps_toggle Alt+Caps Lock
grp:shifts_toggle Both Shift keys together
grp:alts_toggle Both Alt keys together
grp:ctrls_toggle Both Ctrl keys together
grp:ctrl_shift_toggle Ctrl+Shift
grp:lctrl_lshift_toggle Left Ctrl+Left Shift
grp:rctrl_rshift_toggle Right Ctrl+Right Shift
grp:ctrl_alt_toggle Alt+Ctrl
grp:alt_shift_toggle Alt+Shift
grp:lalt_lshift_toggle Left Alt+Left Shift
grp:alt_space_toggle Alt+Space
grp:menu_toggle Menu
grp:lwin_toggle Left Win
grp:win_space_toggle Win Key+Space
grp:rwin_toggle Right Win
grp:lshift_toggle Left Shift
grp:rshift_toggle Right Shift
grp:lctrl_toggle Left Ctrl
grp:rctrl_toggle Right Ctrl
grp:sclk_toggle Scroll Lock
grp:lctrl_lwin_rctrl_menu LeftCtrl+LeftWin (to first layout), RightCtrl+Menu (to second layout)
grp:lctrl_lwin_toggle LeftCtrl+LeftWin
These are all the different key combinations you can use to change the layout. I use grp:ctrls_toggle but you have a lot of options to play with and see what you like.
I had a similar issue, and worked out a compromise which wasn't immediately obvious from the accepted answer.
My layout switching was initially set to Alt+Shift
and this interfered with my ability to use the Alt+Shift+} shortcut to indent in nano / pico.
My compromise was to change the layout switching option from grp:alt_shift_toggle to grp:lalt_lshift_toggle. In other words, only pressing the left Alt and left Shift together change layouts, leaving, e.g. (left) Alt + (right) Shift + } free to produce the desired indentation effect in pico.
In case it is useful to anyone, this is the full line I used in my .fluxbox/startup file:
setxkbmap -layout "gb,gr,ru" -variant ",,phonetic_winkeys" -option "grp:lalt_lshift_toggle" -model pc105 -rules evdev # keyboard layout switching
Is it possible to some how setup IntelliJ IDEA so that I can column select with the cursor keys similarly to how I might in Notepad++, Visual Studio, or FlashDevelop.
For instance when I'm typing code I almost always do my navigation solely through use of the keyboard. In the IDEs mentioned previously I can quickly select blocks of code by holding Shift + Alt then tapping ↑ to extend my cursor across the lines above. I can then hold Shift + Alt + Ctrl and tap ← or → to quickly jump across words and select the chunk of text I want.
In IntelliJ IDEA I have to constantly enable and disable Column Selection Mode using the Shift + Alt + Insert and even then it doesn't quite function as it does in the other IDEs or Text Editors.
Any ideas?
You can do column editing using the Edit | Column Selection Mode.
The shortcut to turn it on/off is Alt+Shift+Insert. You navigate with arrow keys to select blocks of text.
Multiline Caret (without mouse)
Windows/Linux: CTRL + CTRL(Hold) + ↑ / ↓
Mac: ⌘ + ⌘(Hold) + ↑ / ↓
ESC will end multiline mode.
Change Multi-caret Hotkey
To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.
I mapped mine to ALT+SHIFT+↑ / ↓.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.
It is also possible to select holding middle mouse key.
Go to the Settings | Keymap and set a shortcut for Clone Caret Above and for Clone Caret Below
Most convenient way is to:
MAC: Hold Option+Shift and click with mouse.
Windows: Hold Alt and click with mouse.
On a mac, to toggle block select on/off:
shift command 8
⇧⌘8
For me on Mac:
Press once 'option' key, release it, and press and hold it again.
Now navigate with cursor to select desired code.
Press 'Esc' to exit column mode! :)
I think #Meo's answer is the most correct, but if your hand happens to be on the mouse, you can also accomplish this with Ctrl+Alt+Shift+Left Mouse Button Click. Or look for the Add Rectangular Selection on Mouse Drag in the keymap settings.
In Windows or Linux I press two times Ctrl
For Mac cmd+shift+* didn't work for me. I changed the keymap to something else and now it works seamlessly.
I can't make it working, move line up or down doesn't work. When I reset keyboard for VS and applay scheme for Resharper it ask me for this :
and if I take first selection , then alt + up switch me between methods, if I use second selection then this combination does not effects.
Alt+Up is not a ReSharper shortcut to move a line. It most likely belongs to the Productivity Power Tools extension, that has a feature to move one or more (selected) lines.
Personally, I don't like this feature in PPT, since it will just move the line(s), regardless of their scope, causing compilation errors. I much rather use ReSharper's feature of moving blocks of code up or down, by pressing Ctrl + Shift + Alt + ↑/↓ or ←/→ - when on the beginning of the line, it will move the entire line or block of code, but can also be used to move entire methods, change the order of parameters, etc.
I ended up resetting my Resharper shortcuts. Then when prompted with the dialog, chose Use Visual Studio Commands for the Alt+Up & Alt+Down shortcut.
You could also set this manually in Tools > Options > Environment > Keyboard. Search for "MoveSelectedLines" and then assign Alt+Up/Down to the appropriate command.
On my machine with Resharper 2016.1 it makes a difference on what position the cursor is located:
cursor located from 1st to last character on the line: the shortcuts work as described by Igal Tabachnik
cursor located on white spaces before 1st characters of the line the shortcuts are ignored.
Regards
Bernhard