How to search inside a specific block of code in IntelliJ IDEA? - search

How I can search within a specific block of code or selection in IntelliJ IDEA?
I got used to using this feature in Eclipse. In Eclipse you can just double click on the beginning of a curly bracket, and it'll highlight the entire block of code. After which you could do Command+f
(Ctrl+f on Windows) to search ONLY in the highlighted block, or you could just highlight whatever you need and search just that block of code.

Go to Settings | Keymap, search for the Find... action in the Other group. This action should have the following description:
Find a string in active editor, shows
modal dialog
Assign a keyboard shortcut to this action (you need to make a copy of default keymap to modify it), for example Ctrl+Alt+Shift+F.
When in editor, select any block of text, then press this shortcut, a dialog will open with the Scope automatically set to Selected text:
To quickly select the method body while standing on the opening curly brace use Ctrl+W.

As of 2020, I'm able to perform find in selection on PhpStorm
Select the block of text and hit Cmd + F on MacOS / Ctrl + F on other platforms
On the find toolbar (that appears on top) there's an In Selection button; use that to limit search scope to the selected text only
Here's the link to my original answer on JetBrains support forums
I'm using
PhpStorm 2020.1.2
Build #PS-201.7846.90, built on June 3, 2020

First select some text and press ctrl+R to open the dialog, then check the "in selection" option :

In current version, 2020.2, default for Find In Selection is Ctrl+Alt+E.

On IntelliJ in Mac:
In a file select the specific block in which we want to find something
Press CMD + F
Press CTRL + OPTION + G
Notice that the cursor has automatically landed in the find toolbar's text field
Type in what is intended to be found
Press enter to move the cursor to the first occurrence.

Related

How do I substitute in vim editor?

I want to substitute with vim editor a word but only on a portion of a code, that is to say the word "[iteration]" by "[index]". I know how to select the text to replace (visual mode) but I don't know how to apply a substitution on the text selected. The only thing I know to do is global substitution by typing "%s/\[interation\]/\[index\]/g: how can do the same on only selected text?
After you select a block in visual mode, press :, and you'll get a prompt with '<,'>, representing the block you've selected. You can then add instructions to be performed on that block like s/[interation]/[index]/g (without the %!). I.e., you'll have '<,'>s/[interation]/[index]/g. Press Enter and you're good to go.

How can I write to multiple lines simultaneously in Geany?

I want to modify the beginning of every line of a txt file in Geany. Somehow it is possible to write in multiple lines at the same time (maybe with box selection?).
How to do this?
You need to install before the plugin Extra Selection.
For my configuration (Debian/Buster, Geany 1.33) I add to configure shortcuts key.
See plugin manual for more details :
Usage :
Under Tools -> Extra Selection, there are 7 new items: "Column
Mode", "Select to Line", "Select to Matching Brace", "Toggle
Rectangular/Stream", "Set Anchor", "Select to Anchor" and "Rectangle
Select to Anchor". Normally these should be bound to keys, for example
Alt-C, Alt-Shift-L, Ctrl-Shift-B, Ctrl+2, F12, Shift-F12 and
Alt-Shift-F12.
This is just an addition to the answer by #zaboop since the edit queue was full and many people might not have understood the solution properly.
In Geany you cannot edit different parts of multiple lines at once (like in VS Code) without using plugins.
Instead what you can do is you can edit the starting of multiple lines at once.To do so:
Hold Shift + Alt and press your up or down arrow keys to correspondingly select the lines above or below the current line.
Then release Shift + Alt and continue editing the lines.
No plugins needed.
Strangely, unlike the other answers, I had to press Shift + Ctrl while selecting a region, and selecting only works with the mouse, not with the keyboard. After selecting, I was able to edit multiple lines at once.
Configuration: (Debian-based) Raspberry Pi OS, accessed via VNC, Geany 1.33
Select the region, while pressing Alt-Shift, then move around with cursor with arrows.

Decorate a block of text with a digraph box

Is there a vim scrip to allow me to visually select a box, then put a box around it using digraphs?
For example, input:
Hello World
And the output after visual selection (and the calling the script)
┌─────────────┐
│ Hello world │
└─────────────┘
Thanks!
Interesting... I had to do a lot of those re-formatting, thus I wrote a script called "BlockIt", do exactly what you want I guess. And it can do more than that.
Check it out:
https://github.com/sk1418/blockit
Not tested but DrawIt (command \b) should do that.
Look at www.vim.org for other drawing scripts (link to my search results).
You can use visual block mode for this purpose.
Press Ctrl+V to enter visual mode.
Move arrows left, right, up and down to select your box. (If you wanted to interchange the ends, you can press Ctrl+O. I mean, we usually select through the bottom right end. If you want to switch to top left corner and select topside, you can use this)
Now, after making the selection to fit your desired box size, you can fill it with a character like #,* or whatever you want.
Press r# to replace the entire box with a #. You can put any character after r.
Now, your box is full of characters.
You want to type something inside! You can enter replace mode by pressing Insert twice.
Then, start typing your text . press Esc once done.

How to comment or uncomment code in Textmate 2

How do I comment or uncomment code in Textmate 2?
I came across How do I use a shortcut to comment out code automatically in Textmate? , but it's for Textmate 1.x, and "Bundles" > "Source" > "Comments" doesn't have "Comment line".
I'm using TextMate 2.0-beta.7.1.
I recall disabling command + / because it was causing problems while working on Rails apps, but I assumed that would just disable the keyboard shortcut, not the ability to comment and uncomment lines.
In TextMate 2.0.19 you can comment, or uncomment, a line or selection with the shortcut Cmd (⌘) + /.
If this shortcut doesn't work for you, you can do it like this :
Select Bundles in the menu bar
Select Source
Select Comments
Select Comment line
Happy coding 🖖
TIPS
Define a new shortcut for comment or uncomment
If the native shortcut doesn't work for you, define a new one like this :
Select Bundles in the menu bar
Select Edit Bundles...
Select Source
Select Menu Actions
Select Comments
Select Comment Line / Selection
Click on Key Equivalent
Type your shortcut
Close the Bundles editor
A prompt will ask you to confirm your changes
Test it!
Others useful shortcuts
Insert Block Comment : Option (Alt, ⌥) + Cmd (⌘) + /
Insert Comment Banner: Select the word or text you want to use as a banner and Ctrl (⌃) + Shift (⇧) + B
Insert Comment Header ( This will insert the name of the script and some useful details): You have to define it 😅 because in my case it was empty... I defined it with Ctrl (⌃) + Shift (⇧) + N
Use Help in TextMate 😉
Select Help in the menu bar
type "comment"
This will brings you directly to the option comment line. I suggest doing that first because in most cases, you will find the answer.
Bundles -> Source -> Menu Actions -> Comments -> Comment Line
Is that what you're looking for?

Substitute for vim replace in Sublime

I'm looking for a replacement for vim's "replace with character" command--specifically, I want to be able to select some text and replace each character with some character that I type (difficulty: No "vintage" mode)
Example:
Starting with
I am some text with an arbitrary number: 12358998281
I want an easy way to select 12358998281 and turn it into 99999999999, to make the result
I am some text with an arbitrary number: 99999999999
(in vim, this would be done by moving the cursor to the beginning of 12358998281, selecting with ve, then pressing r9)
I can do this by selecting the text, bringing up the "find" dialog, making sure "in selection" and "by regex" are enabled, searching for ., then typing my character into the resulting multiselect. This is incredibly laborious, however, and it prevents me from doing this process on a multiselect (for example, if 12358998281 exists in multiple parts of the file, I might want to quickly replace all instances of it with 99999999999, rather than performing the process above, getting the substitution, copying it to the clipboard, and then replacing with that).
Does Sublime have a command that acts like vim's "replace" that I can bind to something, or do I have to write a macro to get what I need? Or, am I approaching this from entirely the wrong direction?
A more generalized way of thinking of this is "how can I break a select into a multiselect on all characters", if that helps.
By using this package https://sublime.wbond.net/packages/RegReplace you can create regex patterns and bind them to shortcuts.
Also if there are multiple occurrences of one word, you can put cursor on whatever part of the word and press CTRL+D multiple times. One CTRL+D press will select the word under the cursor, every other press will select next occurrence of the word.
You could also use https://sublime.wbond.net/packages/Expand%20Selection%20to%20Whitespace to expand the selection to whitespace if your word contain some random characters, and then press CTDL+D to select next occurrences of the word.
Edit: With the package regex shortcuts indeed you have to create regexes before binding them. But the CTRL+D does work without it.
I don't see a problem with using "Expand selection to whitespace" and than doing the CTRL+D as I wrote in the answer.
I've checked the usage of visual as you wrote in the question and this solution seems much faster to do. You don't have to place cursor in the beggining of the word as It can be whereever in the word and no find/replace is needed, since you'll multiselect all occurrences by holding CTRL+D for a sec and You'll be free to edit it.
You can also use https://sublime.wbond.net/packages/Expand%20Selection%20to%20Quotes to select text inside quote and combine it with CTRL+D if standard CTRL+D doesn't work with some text, or if select to whitespace selects too much text.
I ended up solving this with a simple (if inelegant) plugin:
import sublime_plugin
import sublime
class MultiSelectWithinSelectedCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()
new_regions = []
for selected_region in selection:
if selected_region.empty():
selection.add(self.view.word(selected_region))
for selected_region in selection:
if selected_region.a > selected_region.b:
region_begin = selected_region.b
else:
region_begin = selected_region.a
for pos in range(selected_region.size()):
subregion_begin = region_begin + pos
subregion_end = subregion_begin + 1
new_regions.append(sublime.Region(subregion_begin, subregion_end))
selection.clear()
selection.add_all(new_regions)
Once I've stuck this in my plugins directory, I would bind a command in the keymap file like usual:
{ "keys": ["alt+f"], "command": "multi_select_within_selected" }
(with alt+f chosen arbitrarily), and lo, multi-select on all selected characters with a keypress (after which, I can press my replacement character).

Resources