How can I expand multi-line selection to full lines in PHPStorm? - keyboard-shortcuts

In Sublime Text I can arbitrarily select a set of lines and then use ⌘+L to expand the selection to the full lines. Is there a similar command in PHPStorm / WebStorm? (I'd like to map that command to a keyboard shortcut.)
I know PHPStorm has the option "Select Line at Caret", but that selects only one line.

Update
Nowadays (welcome 2020) Go to Preferences > Keymap. Change or add the value to
Add Carets to Ends of Selected Lines => CMD+SHIFT+L to have it behave like Sublime Text so it looks like
Old Answer
This is as close as I could get it (before 2020):
Go to Preferences > Keymap. Search for Clone Caret Above/Below.
On a Mac, it looks like this
The keys are:
CMD+SHIFT+CTRL+ARROW_UP for Clone Caret Above
CMD+SHIFT+CTRL+ARROW_DOWN for Clone Caret Below
Click on Apply and it will work

With WebStorm 11 (at least) the multi-caret keyboard shortcut is:
Ctrl then Ctrl+Arrow Up (or click & drag with the middle mouse button/scroll wheel)
then to select the full lines:
Home then Shift+End
which you could even create as a macro with a keyboard shortcut.
I used to accidentally activate the multi-caret all the time (I scroll with Ctrl+Up/Down), so I knew how to do part of it, but it took me ages to figure out that extra Ctrl tap at the beginning.

Hold down Alt + Shift and left click on the lines you want to select. This will put multiple cursors on the editor. Now you can use the Select Line at Caret option you mentioned to select all those lines.
You can find more about multiple selections here.

This is currently not possible with a selection. However, you can still do that from the keyboard. Instead of doing selections set up a shortcut for Clone Caret Above (Alt+Shift+U for me) and Clone Caret Bellow (Alt+Shift+D for me). This allows to go up or down a line and add a caret there. So instead of selecting each line, you directly move the caret there and clone it.
I am also coming from Sublime Text and missing that feature, but this worked also pretty well.

Related

Keyboard shortcut to switch between horizontally split windows in Intellij

I've done numerous searches to find out how to switch between two files that are horizontally split but can't seem to find it. I know that you can switch between vertically split files by using the Goto Next Splitter option, but there doesn't seem to exist an option for horizontally split. Has anyone else figured this out? Thanks!
An example of a situation where I can't switch between the top and bottom files:
I just tried this out, and Goto Next Splitter (Option-Tab on mac) works just fine for me on horizontally split panes
Note: Using CLion 2017.1.2
If you have IdeaVim installed, you can use the Control-W - J/K command to switch between Vim split panes. See also How do I switch between panes in split mode in Vim?
Use Ctrl + Tab or Ctrl + Shift + Tab to switch between opened buffers (or "file editors", if you like). If you have only two buffers like on your screenshot, you can just press Ctrl + Tab and then by pressing Enter the other editor will become focused.
Important addition:
The shortcut varies depending on your keymap. To figure out proper key combination, open File -> Settings -> Keymap and search for "Switcher" keymap in the search field.

How can I enter a literal <TAB> character in IntelliJ/IDEA/PyCharm?

My configuration indents with four spaces, and I want to keep that. Occasionally (e.g. in a Makefile) I want to input a literal TAB character.
How can I force the IntelliJ-IDEs to input a tab or space, when it would not do so when I hit tab or space in that instance?
You seem to be asking two questions here:
1. How do I force IntelliJ IDE to input a tab, when it would not do so when I hit tab?
and
2. How do I force IntelliJ IDE to input a space, when it would not do so when I hit space?
I don't understand how the second case can arise. However, I have provided a solution to it as well.
Case 1. Insert a tab character when an IntelliJ IDE wants to replace it with spaces due to configuration
Solution
Use search and replace.
Details
Place the cursor where you want the tab to be
Press the X key
Select the X you just typed
From the main menu, choose Edit | Find | Replace to bring up the search and replace pane
Make sure there is an X in the search field
Enter \t in the replace field
Be sure the option Regex is checked
Be sure the option In Selection is checked
Click the Replace button
Case 2. Insert a space character when an IntelliJ IDE won't just let you type one (???)
Solution
Use search and replace.
Details
Place the cursor where you want the space to be
Press the X key
Select the X you just typed
From the main menu, choose Edit | Find | Replace to bring up the search and replace pane
Make sure there is an X in the search field
Enter a single space into the replace field
Be sure the option In Selection is checked
Click the Replace button
Install the plugin for Makefile support: https://plugins.jetbrains.com/plugin/9333-makefile-support
When I tried it today, this automatically use hard tabs in the editors for Makefile files.
Open another text editor, type a tab, and then copy and paste into the PyCharm editor. In MacOSX this worked for me using both Sublime Text 2 and TextEdit.
I can't think of any "direct" way. Probably the easiest way that I can think of is to write a Live Template to do it. See the help page on Live Templates for more information. When you write it, you may need to copy and paste a tab character in from another application.
However, when I tried it, IDEA saw it as just empty text and would not save it. So I used a variable with the "capitalize" function to capitalize a tab character.
Here's the template I created that you can paste into your templates. Now I type tab, hit the Tab key and I get a tab character. Of course you can change the abbreviation.
<template name="tab" value="$TAB$" description="Enter a tab Character" toReformat="false" toShortenFQNames="true">
<variable name="TAB" expression="capitalize(" ")" defaultValue=" " alwaysStopAt="false" />
<context>
<option name="OTHER" value="true" />
</context>
</template>
You could extend the idea to have multiple ones that enter multiple tabs. For example tab to enter 1 tab, tab2 for 2 tabs, etc.
Screenshot of it after use:
There may also be a way to hack a macro to do it. You could then assign the macro to a keyboard shortcut. I'll see if I can figure something out and update this if I do.
Use the menu option: Edit -> Convert Indents -> To Tabs.
Whenever I edit a makefile I do the "to tabs" conversion before I save the file.
UPDATE: Really sadly, I think the generated character still gets converted to spaces... Am checking...
There is an Action in JetBrains IDEs to enter a Tab character.
Here are the steps to use the Tab character action: (discovered in PyCharm 2020.3)
Double-tap the Shift key OR Help -> Find Action...
Type the 3 characters tab
Click on the action that is called Tab and shows the icon for the Tab character...
It remembers the last action you did, so if you have several tabs to add, you can get into a quick process by doing ShiftShift then Return each time.
Answer based on #Morfic's comment to the question. I think this is the cleanest and most sensible reply here so I figured it deserves a place as an answer (and needless to say, it worked for me).
If they're different types of files you could configure File -> Settings -> Editor -> Code style -> Tabs and Indents for each one to use either space or tab depending on how you want it.
One way to do this is to copy a TAB character from another text editor, then right click in your PyCharm file and use Copy / Paste Special -> Paste as Plain Text (Ctrl+Alt+Maj+V)
I guess this was not available in older PyCharm versions, because no other answer proposed it. Regular paste (Ctrl+V) doesn't work (replaced by spaces), but this one works. The function will also bypass other automatic formatting.
Inspired of Clare's suggestion,
assign the left tab key after finding 'tab' action.
At Actions tab, search by 'tab' and move your up/down arrow key and place there.
Then type Ctrl+1, you will see a popup. Select as follows and click OK.
Then, you might be asked "Do you want to remove other assignments?" if Tab key was already assigned. Click Leave because your usage won't conflict with the existing setup.

Use VI keys everywhere instead of cursor keys

I like VIM a lot because it kind of doubles the power of my keyboard in a way. It's either in insert or motion or whatever they call it mode.
Navigating through source code, typing code, while being able to keep my hands in the touch type position is great.
But when a dialog box is opened (eg. the one using ctrl+F12), if I have to select something other than the first one in the list, I am forced to have to move my right hand to the cursor keys.
Is there a way so that I can use J and K or else something with ctrl or alt or something, so that I can select an item while keeping my hands in the touch typing position?
You can redefine shortcuts for the Up, Down, Left, Right actions in File | Settings | Keymap (the regular keymap that has nothing to do with IdeaVim). IdeaVim provides Vim emulation only for code editors like file editors, interactive language consoles, etc.
Edit: I guess you can't use j and k since characters typed in the structure window are reserved for searching. But you can use Ctrl+N and Ctrl+P which is the same as the navigation shortcuts for pop-up windows in Vim.
Edit 2: You can't use Ctrl+N and Ctrl+P as well due to this bug in IntelliJ.

Cycle through autocomplete suggestions without arrows

I'm really impressed with the autocomplete feature of the IntelliJ IDE so far.
What I'd like to do, is cycle through the autocomplete suggestions I get when hitting Ctrl + Space without using the arrow keys (↑, ↓).
The reason for this is that I prefer to keep my fingers on the home row (I'm using IntelliJ's Vim emulator additionally).
For example, how would I select sortThis instead of sorted without using the arrow keys or the mouse?
Peter Gromov's answer brought me to a satisfying solution:
In IntelliJ's settings, for Keymap → Editor Actions → Down I set a custom shortcut: Ctrl + J.
This way I can cycle forward through the suggestions.
Setting a shortcut for Down with Selection or Scroll Line Down in the IdeaVim-specific shortcuts did not affect the selection of autocomplete suggestions though.
The answer here: https://stackoverflow.com/a/9713306/2370679 led me to discover that Ctrl+n & Ctrl+p allow navigation of the auto-complete options without having to modify any settings
For macOS the IDE will give a hint that "^↑ and ^↓ will move caret up and down in the editor". These clearly do not work.
There are a few extra steps that are needed after following #matthias-braun's solution.
Here is the full list of step that I use:
Go to Preferences -> Keymap
Expand Editor Actions (not Plug-ins -> IdeaVim)
Select Down
Click the pencil icon or right-click
Select Add Keyboard Shortcut
Press the shortcut (I use ^N)*
Repeat for 3-6 for Up (I use ^P)
Click Ok**
Go to Preferences -> Other Settings -> Vim Emulation
In the drop-down under the Handler column for the row containing Down, select Vim***
Do the same thing for Up
* If you are warned about the key binding already existing then remove it. You can always reset back to the defaults by clicking the little cog icon up the very top to the right of the drop-down menu.
** The Vim Emulation doesn't seem to be populated correctly until you reopen the Preferences.
*** I'm not sure why the Handler should be Vim. This seems backwards to me but it works.
If you're able to scroll up/down in editor with some IdeaVIM-specific shortcuts, they should also work in the completion list.
In this particular case, I'd just type another "t" so that "sortThis" becomes selected (and the only) variant.
I have done the same thing with mapping the arrows but in a more logical way:
I mapped them that when I press 'Alt' 'J' is left, 'L' is right, 'I' is up, and 'k' is down. that way I can have easy access to the arrows while my fingers are on the home row and I don't need to move them nearly as much...
I'm posting it just so people who search it on google can have that idea.

Wrapping comments with line breaks in PyCharm

I have comments that gets balloon (PEP 8: Line too long ... > 120)
I wish there was a command that will wrap the lines with few keystrokes.
Right now, even if I type Alt+Enter and press enter on Reformat file, nothing actually changes. Is there a setting or plugin I could use to accomplish the formatting easily?
Under the Edit menu, there is a Fill Paragraph option, which does what I believe you want. You can assign a key command to this in Preferences, under Appearance & Behavior -> Keymap (search for "fill").
Personally, I choose first stroke Esc, second stroke Q, because that's what I've always used in Emacs...
Firstly, reformatting won't work, not in Python at least, where whitespace is important. PyCharm's "Wrap when typing reaches right margin" option is what you're looking for. Now this will not work when you copy and paste code, but in the places where it gives you trouble, just press enter, and it will work.
To be able to auto-reformat comments (and code, for that matter) to honor a right margin after the fact, go into Project Settings under Code Style and then further under Python. Click the Wrapping and Braces tab, and check the "Ensure right margin is not exceeded" checkbox.
Now if you select a region of lines and then run the Code/Reformat Code... command, PyCharm will do its best to wrap the comments or code appropriately.
You will probably have to do some tweaking of the results to suit your stylistic taste. For example, I wish PyCharm would do aggressive filling of text in block comments, at least optionally so.
PyCharm will not reformat code such that it becomes invalid Python, so sometimes it will still leave a line longer than the margin (120 or whatever you set under Project Settings/Code Style/General).
With recent PyCharm this now is located at "Editor -> Code Style", with the checkbox named "Wrap on typing"
The Screenshot shows PyCharm version 2016.2.1 Professional.
Updated Answer:
Use "soft wraps." You can search for it in the help bar.
View > Active Editor > Use Soft Wraps
It won't work for existing text or text that's copied in, but will for any newly typed text.