Is there an IntelliJ IDEA action that select a word if there is no selection but stay unchanged if there is? - intellij-idea

I want to write a macro that if there is no selection it automatically operates on the current word, otherwise it operates on the selection. However I cannot find a suitable action, EditorSelectWord keeps on expanding the selection forever.
p.s. The macro is meant to change "xyz" to "{#code xyz}", but it also needs to change "x/y/z" to "{#code x/y/z}".

IntelliJ IDEA does not appear to be the best tool for this specific job. It looks like macros only support a fixed list of steps that will always be executed, without the possibility for if statements: https://www.jetbrains.com/idea/help/using-macros-in-the-editor.html.
You could use Ctrl-W manually when there is no selection, but it would of course be much nicer if the macro could handle it. Another possibility is to use a tool like the stream editor sed. The substitution command of sed might be usable in your case, unless the text occurs in places where you do not want to substitute it:
sed 's/xyz/{#code xyz}/g' inputFileName > outputFileName
It might also be a great reason to write a small program of your own that for example modifies only specific strings in Javadocs in your source files.

Related

How to undo in Intellij IDEA replace in files?

In intellij 2022.1, I use Ctrl+Shift+R to bring up the Replace in Files window - it shows 100+ matches in 40+ files. The search string and the replace string differ in only one character, for example: this.bar.is.fooed and this.barf.is.fooed. I only need to replace certain instances based on nearby text.
I'm in the groove, clicking the Replace button, checking the next entry, clicking, checking, ... and thinking my brain can keep things straight (it can't; neither can yours:-) I'm halfway through when I realize the last few replaces were wrong.
How can I undo them? Ctrl+Z is grayed out. This related SO question doesn't say and neither does the JetBrains documentation!
Use Local History to revert the changes.
Undo/redo is not supported for Replace dialog, vote for the related request.

Can IntelliJ IDEA automatically format a code block after finishing it?

Some IDEs offer the feature to automatically format a line or block of code after finishing it e.g. by writing the closing curly or semicolon.
I find it hard to believe that IDEA does not offer this kind of feature. Or does it?
If you know how to turn it on - or if I maybe need some plugin - let me and the world know, please!
If it's a single line, you can use the Complete Current Statement action (which adds a closing bracket, semi-colon, and so on) with ctrl-shift-enter - this seems to reformat the whole line.
Otherwise, you can obviously rebind ctrl-w and ctrl-alt-l (to reformat selected text) or just ctrl-alt-l (reformat whole file) to faster / easier keybindings so that you can quickly reformat whenever you want to.
There is no automatic reformat feature, related requests:
IDEABKL-5806 Automatically trigger code formatter on file save
IDEABKL-475 Hard (auto-)reformat code
See also my answer to the similar question with the Complete Current Statement workaround.

Set breakpoint in VBA code programmatically

I have a very large piece of code written in VBA (>50,000 lines - numerous modules). There is one array of interest to me, and I'd like to find all the conditions under which the value of any element of this array changes. The values can change in any module. Running the script line by line is not the most efficient option due to the size of the code.
I am looking for better ways to solve this problem. Two ways that come to my mind is to programmatically set a breakpoint (which I am not sure if can be done) or programmatically insert an if-block after each assignment that somehow alerts me that the value has changed. (not preferred).
So my question boils down to:
Is it possible to programmatically set breakpoints in VBA code?
If the answer to the above question is No, what is an efficient way to solve this problem?
UPDATE:
Thanks for the comments/replies. As I had implied, I am interested in the least amount of modification to the current code (i.e. inserting if-blocks, etc) and most interested in the break-point idea. I'd like to know if it's doable.
Use the keyword STOP to break te code if a certain condition is true.
There are Two Ways to do that:
Use Stop Key word. Example as given below, set a break point at Stop
if (x = 21 ) Then
Stop
End If
Using Add Watch
Go to Debug -> Select Add Watch
NB:I know this is an old topic but this could help others.
You could use Watches:
Right click on the variables you wish to monitor -> Add Watch...
In Watch Type: 'Break when value changes'
While you run your code, you can check the status of your Watches thanks to the Watch Window (accessible from the 'View' menu)
in the hope someone can benefit from this :
In such situations regardless of the programming language used - writing a few lines of code either in Perl, AWK or even shell scripts can solve the problem :
search for a regular expression containing the array name (ignoring case).
Once you export all modules and classes in the Workbook(s) into a given directory - the scripts can search those for you.

Saving a position while coding?

Back in olden times, I used to code with an editor that allowed you to mark where you were in the code with a keypress. You could jump to another point in the same or another file to check a reference or somesuch. When you were ready, you could hit another keypress and return to the point you saved.
I've long since migrated to Dreamweaver and wanted this functionality. Does it exist in DW? If so, I missed that part of the manual. If not, any suggestions on an editor that DOES have that functionality?
Scott.
There is no official way to do it, but you could use the code collapse feature to create something like a bookmark. Collapse the single line and DW will have a mark at that line number until you clear it.

Auto-Completion in Unix VI editor

After using graphical IDE's like Visual Studio, I'm used to pressing CTRL+Space to auto-complete a variable or function name. Now, I know such a thing isn't completely possible in VI, but I heard there was a list of commands that could be mapped that allowed automatic completion of variables and functions in the current file opened. Does anyone know what this sequence is?
Just noticed that you said "vi"; I hope that "vim" is also okay.
It depends on the particular programming language, but in general, the magic word is Omnicomplete.
Put this into .vimrc:
filetype plugin on
set ofu=syntaxcomplete#Complete
Press Ctrl+N or Ctrl+P to trigger the completion. This is insanely customizable; you might like the tips here that make it work more like other IDEs.