What useful macros have you created in Netbeans? [closed] - netbeans

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I use Netbeans (nightly build) for Ruby on Rails development and I'm looking to beef up my macros. I've created a few myself:
copy identifier:
select-identifier copy-to-clipboard
paste clipboard over identifier:
select-identifier paste-from-clipboard
double quote element
select-element-next "\""
single quote element:
select-element-next "'"
But I'm looking for other useful ones and Google is giving me nothing.
The record macro feature usually doesn't work too well so I'd rather just "write" the macros myself but I can't even find a reference that lists what commands (like "select-identifier") are actually available.
Any Netbeans macro gurus out there?

Here is a list of macro codes with short explanations. Might be useful for someone.
Update: replaced old link with one to the Netbeans site and included the macro list in here.
abbrev-debug-line Debug Filename and Line Number
adjust-caret-bottom Move Insertion Point to Bottom
adjust-caret-center Move Insertion Point to Center
adjust-caret-top Move Insertion Point to Top
adjust-window-bottom Scroll Insertion Point to Bottom
adjust-window-center Scroll Insertion Point to Center
adjust-window-top Scroll Insertion Point to Top
all-completion-show Show All Code Completion Popup
annotations-cycling Annotations Cycling
beep Beep
build-popup-menu Build Popup Menu
build-tool-tip Build Tool Tip
caret-backward Insertion Point Backward
caret-begin Insertion Point to Beginning of Document
caret-begin-line Insertion Point to Beginning of Text on Line
caret-begin-word Insertion Point to Beginning of Word
caret-down Insertion Point Down
caret-end Insertion Point to End of Document
caret-end-line Insertion Point to End of Line
caret-end-word Insertion Point to End of Word
caret-forward Insertion Point Forward
caret-line-first-column Insertion Point to Beginning of Line
caret-next-word caret-next-word
caret-previous-word caret-previous-word
caret-up Insertion Point Up
collapse-all-code-block-folds Collapse All Java Code
collapse-all-folds Collapse All
collapse-all-javadoc-folds Collapse All Javadoc
collapse-fold Collapse Fold
comment Comment
complete-line Complete Line
complete-line-newline Complete Line and Create New Line
completion-show Show Code Completion Popup
copy-selection-else-line-down Copy Selection else Line down
copy-selection-else-line-up Copy Selection else Line up
copy-to-clipboard Copy
cut-to-clipboard Cut
cut-to-line-begin Cut from Insertion Point to Line Begining
cut-to-line-end Cut from Insertion Point to Line End
default-typed Default Typed
delete-next Delete Next Character
delete-previous Delete Previous Character
documentation-show Show Documentation Popup
dump-view-hierarchy Dump View Hierarchy
expand-all-code-block-folds Expand All Java Code
expand-all-folds Expand All
expand-all-javadoc-folds Expand All Javadoc
expand-fold Expand Fold
fast-import Fast Import
find-next Find Next Occurrence
find-previous Find Previous Occurrence
find-selection Find Selection
first-non-white Go to First Non-whitespace Char
fix-imports Fix Imports
format Format
generate-code Insert Code
generate-fold-popup Generate Fold Popup
generate-goto-popup Generate Goto Popup
generate-gutter-popup Margin
goto Go to Line...
goto-declaration Go to Declaration
goto-help Go to Javadoc
goto-implementation Go to Implementation
goto-source Go to Source
goto-super-implementation Go to Super Implementation
in-place-refactoring Instant Rename
incremental-search-backward Incremental Search Backward
incremental-search-forward Incremental Search Forward
insert-break Insert Newline
insert-date-time Insert Current Date and Time
insert-tab Insert Tab
introduce-constant Introduce Constant...
introduce-field Introduce Field...
introduce-method Introduce Method...
introduce-variable Introduce Variable...
java-next-marked-occurrence Navigate to Next Occurrence
java-prev-marked-occurrence Navigate to Previous Occurrence
jump-list-last-edit Last edit
jump-list-next Forward
jump-list-prev Back
last-non-white Go to Last Non-whitespace Char
make-getter Replace Variable With its Getter
make-is Replace Variable With its is* Method
make-setter Replace Variable With its Setter
match-brace Insertion Point to Matching Brace
move-selection-else-line-down Move Selection else Line down
move-selection-else-line-up Move Selection else Line up
org.openide.actions.PopupAction Show Popup Menu
page-down Page Down
page-up Page Up
paste-formated Paste Formatted
paste-from-clipboard Paste
redo Redo
reindent-line Re-indent Current Line or Selection
remove-line Delete Line
remove-line-begin Delete Preceding Characters in Line
remove-selection Delete Selection
remove-tab Delete Tab
remove-trailing-spaces Remove Trailing Spaces
remove-word-next remove-word-next
remove-word-previous remove-word-previous
replace Replace
run-macro Run Macro
scroll-down Scroll Down
scroll-up Scroll Up
select-all Select All
select-element-next Select Next Element
select-element-previous Select Previous Element
select-identifier Select Identifier
select-line Select Line
select-next-parameter Select Next Parameter
select-word Select Word
selection-backward Extend Selection Backward
selection-begin Extend Selection to Beginning of Document
selection-begin-line Extend Selection to Beginning of Text on Line
selection-begin-word Extend Selection to Beginning of Word
selection-down Extend Selection Down
selection-end Extend Selection to End of Document
selection-end-line Extend Selection to End of Line
selection-end-word Extend Selection to End of Word
selection-first-non-white Extend Selection to First Non-whitespace Char
selection-forward Extend Selection Forward
selection-last-non-white Extend Selection to Last Non-whitespace Char
selection-line-first-column Extend Selection to Beginning of Line
selection-match-brace Extend Selection to Matching Brace
selection-next-word selection-next-word
selection-page-down Extend Selection to Next Page
selection-page-up Extend Selection to Previous Page
selection-previous-word selection-previous-word
selection-up Extend Selection Up
shift-line-left Shift Line Left
shift-line-right Shift Line Right
split-line Split Line
start-macro-recording Start Macro Recording
start-new-line Start New Line
stop-macro-recording Stop Macro Recording
switch-case Switch Case
to-lower-case To Lowercase
to-upper-case To Uppercase
toggle-case-identifier-begin Switch Capitalization of Identifier
toggle-comment Toggle Comment
toggle-highlight-search Toggle Highlight Search
toggle-line-numbers Toggle Line Numbers
toggle-non-printable-characters Toggle Non-printable Characters
toggle-toolbar Toggle Toolbar
toggle-typing-mode Toggle Typing Mode
tooltip-show Show Code Completion Tip Popup
uncomment Uncomment
undo Undo
word-match-next Next Matching Word
word-match-prev Previous Matching Word

I needed to surround text fragments with HTML tags, but couldn't figure out how to do it quickly, so I came up with this macro:
cut-to-clipboard "<strong>" paste-from-clipboard "</strong>"
Simple, clean, and you can put any tag/text you want. Give it a shortcut like Alt+B and you have quick way to insert HTML

for php add semicolon to end line ("complete line")
but keep your cursor at the current point,
so you can keep typing the rest of the line
split-line
caret-down
caret-end-line ";"
caret-begin-line
selection-begin-line remove-selection
delete-previous

This is my first netbeans macro.
"echo '< pre >';print_r();die();"
my shortcut key => Alt+A
for this you can use any shortcut

Oh well, just experimenting with netbeans.
I add a simple new macro for netbeans.
name: "scrollup_newline"
code:
insert-break
scroll-up
It works well, so every i press enter, the editor move one line down. This way i can code and have the caret in the middle of the editor.

This is for HTML. I just made:
caret-begin-line "<li>" caret-end-line "</li>" caret-down
Mapped it to ctrl+shift+L This is my first netbeans macro. Later maybe I can make it work for an entire selection somehow.
Edit: Can't figure out doing it for selections, but adding "caret-down" at the end was almost as good.

Here is the macro I wrote today. I am very much missing an "extract method" or "introduce method" refactoring in PHP, so I wrote this macro. I know this is far less complex than the refactorings in Java, but it can be used and it saves a few copy/pastes and writing repetitive code.
cut-to-clipboard
"$this->UNNAMED_METHOD();"
collapse-fold
caret-end-line caret-backward caret-end-line insert-break
"private function UNNAMED_METHOD() {"insert-break
paste-from-clipboard insert-break

This macro inserts -moz- and -webkit- prefixed equivalents of a css3 style rule:
caret-end-line selection-begin-line copy-to-clipboard caret-backward insert-break caret-up "-webkit-" paste-from-clipboard insert-break "-moz-" paste-from-clipboard

insert-date-time remove-word-previous remove-word-previous
Mapped to CTRL+SHIFT+D to insert the short date, so useful cause I like to date my comments / TODOs but often don't know the date!
Although I think Code Templates and more useful, for example:
// <editor-fold defaultstate="collapsed" desc="${cursor}">
and
// </editor-fold>
Mapped to 'fold' then tab and 'endfold' then tab respectively.
Also
JOptionPane.showMessageDialog(null, "${EXP default="Got here"}");
Mapped to 'jop' then tab is handy.

Probably not the most efficient but it helps me out lol
"(() ? : );"
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
As one can see, this is for PHP quick conditionals. This then places the cursor in the spot where you start typing the condition. Perfect no matter where your throwing it into. I put this to Ctrl+NUMPAD0 for quick typing access. I orignally had it to two TABs but that quickly got annoying haha

I often like to have commas as the first character separating properties or list items in JavaScript; like so:
var foo = {
a : 'a'
//, b : 'B' //todo: make lcase
, c : 'c'
};
Sometimes, I either forget to do this, or have a mass of text to update. To fix these quickly, I bound the keyboard shortcut C-, C-, -- That's two presses of ',' while holding CTRL key -- to:
caret-end-line selection-next-word selection-next-word " " caret-backward caret-backward insert-break

I found Code Templates to be very useful, especially this one (for HTML):
<${tag}>${cursor}</${tag}>
The abbreviation is "tt", and it can also surround any text with custom tag, when called by the code template menu.
<${param_name default="tag"}${cursor}>
${selection}
</${param_name default="tag"}>
This one will surround anything with any tag. Select something, then Alt+F3, then just select this template from the menu. After that type the tag you want, e.g. "div".

This is a code template for creating a static logger in a class using SLF4J. I tie it to "Log".
private static final ${loggerType type="org.slf4j.Logger" default="Logger" editable="false"} log = ${loggerFactoryType type="org.slf4j.LoggerFactory" default="LoggerFactory" editable="false"}.getLogger(${classType editable="false" currClassName default="getClass()"}.class);
This makes a log.debug line which I tie to "log":
log.debug("${message}", "${variables}");

Related

How to edit all lines in Visual Studio Code

I have a list of data to which I need to put a ' symbol at the start of the line and at the end of the line. So the original data looks like this:
abcde
cdeab
deabc
eabcd
And I want all of the lines to look like this:
'abcde'
'cdeab'
'deabc'
'eabcd'
In my real data, I would have 10,000 of lines. So if I can do something like Ctrl+Shift+A to select the entire document and then have some magic shortcut to change from selecting all lines to editing all lines that would be perfect!
You could edit and replace with a regex:
Find (Ctrl+F):
^(.+)$
Replace:
'$1'
This regex finds any content on a line and wraps it inside quotes. The $1 refers to whatever is matched inside the parentheses in the regex. In this case, it's "one or more characters" i.e. everything on the line. Be sure to tick the regex icon.
If every line may or may not have a space before the content, and you want every line to have a space, try this:
Find:
^ ?(.+)$
Replace (notice the space before the first quote):
'$1'
Here is an easy way to do this:
Ctrl+A to select all or select your desired text.
Shift+Alt+I to put a cursor at the end of each line.
Type your ' (or whatever you want at the end).
Home will move all your cursors to the beginning of the lines.
Type your ' (or whatever you want at the beginning of all the lines).
You can use the Alt + Shift shortcut.
First press Alt + Shift then click the mouse button on the first line.
Go to the last line, and then do the same.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Do the same on the other side too.
Use Toggle Multi curosr Modified from action pane.
Select the cursor points with ctrl + <Mouse click> , you can modify everything simultaneously.
This will require lots of manual efforts if lines are more
You can use Find and Replace.
Besides, paste to Excel and using a function to add character '.
The first thing that came to my mind - replace abcde with 'abcde' line by using option Find and Replace option. I'm pretty sure Visual Studio Code has something similar to that.
You can use the Shift +Alt shortcut for windows and for Mac use Shift + Option
First press Alt + Shift/Shift + Option then click the mouse button on the first line.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Place Cursor where you want to insert/delete text.
Goto Selection Menu and choose Column Selection Mode
Scroll to the bottom of the data and shift + click in the last line where you placed the first cursor.
Perform action (add/delete whatevs)
Repeat for whatever other areas you want to change.
v: 1.74.3
1- You can use the Ctrl + H shortcut (menu Edit → Replace)
Enter abcde in Find Control.
Enter 'abcde' in Replace Control.
Then press Ctrl + Alt + Enter.

How do I get a cursor on every line in vscode

I'm trying to use the multi cursor functionality of vscode on a large(ish) file.
the file is too large to select every line individually with ctrl-alt-up or down. In sublime-text I would select everything and push ctrl-shift-l. Is there a similar thing in vscode. I've tried using a regex search for ^, but that gives me an error stating "Expression matches everything".
The command Selection / Add Cursors to Line Ends altshifti will put a cursor on every line in the current selection. (For mac use optshifti)
Tip: You can pull up the keyboard shortcut reference sheet with ctrlk,ctrls (as in, those two keyboard combos in sequence).
(For mac use cmdk,cmds)
Hold Alt+Shift and select the block. Then press End or Right button.
You get selected individual lines.
I use version VSCode 1.5.3 in Windows.
Hold Alt+Shift+i
Hold Home (fn+-> Mac) for right-most or End for left most(fn+<- Mac)
This feature is actually called split selection into lines in many editors.
Sublime Text uses the default keybinding, CTRLSHIFT L
VSCode uses ALTSHIFTI
For Atom you actually need to edit your keymap to something like this
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-shift-L': 'editor:split-selections-into-lines'
Real Lines vs Display Lines
First we have to understand the difference between Real Lines and Display Lines to completely understand the answer of the question.
When Word Wrap is enabled, each line of text that exceeds the width of the window will display as wrapped. As a result, a single line in the file may be represented by multiple lines on the display.
The easiest way to tell the difference between Real Lines and Display Lines is by looking at the line number in the left margin of the text editor. Lines that begin with a number correspond to the real lines, which may span one or more display lines. Each time a line is wrapped to fit inside the window, it begins without a line number.
Cursor At the Beginning of each Display Lines:
Cursor At the Beginning of each Real Lines:
Answer to the Question
Now that we know the difference between Display Lines and Real Lines, we can now properly answer the actual question.
Hold AltShift and select the text block.
Press Home to put cursor on the beginning of every Display Line.
Press End to put cursor on the end of every Display Line.
Press HomeHome (Home twice) to put cursor on the beginning of every Real Line.
Press EndEnd (End twice) to put cursor on the end of every Real Line.
Please understand that AltShiftI put cursor on the end of every Real Line.
Install the extension Sublime Commands.
[Sublime Commands] Adds commands from Sublime Text to VS Code: Transpose, Expand Selection to Line, Split into Lines, Join Lines.
(Don't forget to add the keybinding(s) from the extensions details page to your keybindings.json)
Doesn't VS Code already have a "split into lines" command?
Yes, yes it does. However it differs from the one in Sublime.
In VS Code, when you split into lines your selection gets deselected and a cursor appears at the end of each line that was selected (except for the last line where the cursor appears at the end of the selection).
In Sublime, when you split into lines a cursor appears at the end of each line (with the same exception as in VS Code) and the selection is divided on each line and "given" to the same line.
I have the same problem, i'm used to Alt + drag to do 'box selections' in visual studio but it does'n work in code.
It seems to be impossible for now to do it differently than by selecting every single line.
However plugins should be supported soon so we will likely see a plugin for this if not implemented directly by microsoft.
From visual studio uservoice forums:
We plan to offer plugin support for Visual Studio Code. Thank you for your interests and look for more details in our blog in the coming weeks. http://blogs.msdn.com/b/vscode.
For the preview we are looking for exactly this type of feedback. Keep it coming.
Sean McBreen – VS Code Team Member

highlight expressions on netbeans

I want to know if there is a way to highlight the full content in an expression like if, while, etc.
I have to work in a code that is bad indented where expressions can cover over 1000 lines and I can't format it.
for exemple :
if ($somethingTrue) {
while ($somethingHappen) {
// 500 lines...
} }
if ($someCondition) {
}
look, it's very hard to see the end of the first if and what it cover...
Does someone know if there is a native feature or plugin on netbeans that do this job ?
Thanks !
You don't need any plugin/external jar file for achieving the same. Whichever expression you want to check the body of, just click on the opening brace after that expression and NetBeans will automatically show you the closing brace for that expression.
Basically, Netbeans shows the ending brace for a corresponding starting brace entry---for each of if-statements,loop-statements,method declarations,etc.
In the shown figure, see my if-statement starting with yellow brace(cursor blinking there), and the corresponding ending brace for the if-statement.
EDIT :-
You also can also have a brand new-code fold,just by typing fcom, and hitting (Tab) button on KeyBoard. And, then put whatever block you want inside it and done. Expand whenever you wish and collapse whenever you want.
Check the position of my mouse-pointer which shows the current block of if-statement. You can expand and collapse as per your wish. And, also you can have several of them for each of your expression-tree.

How to do search and replace involving fields in Microsoft Word?

I have a Word document with fields of the reference variety, which occur in the form "[field].[field]"--in other words, there's a period between the two fields. I want to globally replace this with a space.
Word offers the ^d special character to search for fields, but for some reason the query "^d.^d" does not find anything. However, ".^d" does. Now comes the problem, however--what do I specify as the replacement text in order to retain the field code? If using regular expressions, I could use a "Find What Expression" such as \1, but with regexp ("wild card") mode the ^d is not permitted.
I guess I could write a macro...
I would like to add to Bibadia's solution.
An example of an index entry field; we want to change a name we misspelled.
Make sure hidden formatting is displayed (toggle with SHIFT+CTRL+F8).
Make sure wildcards option is not selected. To search for fields, use the opening and closing field braces code (optionally use ^w for spaces, as Bibadia suggested):^19 XE "Deo, John" ^21
Replace won't recognize field braces character, but will allow to insert the clipboard's content. ;). To do that, insert in text the correct entry. CTRL+F9 to insert field and type:XE "Doe, John"
Select the field above and copy
Use ^c in the replace box
Hit Replace All
Ta-da!
It's usually better to go the macro route when finding fields because, as you say, the find algorithm that Word uses doesn't work the way you might hope with fields.
But if you know exactly what the fields contain, you can specify a search pattern that will probably work (however not in wildcard mode).
For example, if you want to look for figure number field pairs such as
{ STYLEREF 1 \s }.{ SEQ Figure \* ARABIC \s 1 }
(which would typically be the same set of fields everywhere in the document)
If you only really need to look for the following:
{ STYLEREF 1 \s }.<any field>
you could ensure that field codes are displayed and search for
^d STYLEREF 1 \s ^21.^d
or
^19 STYLEREF 1 \s ^21.^19
If you need to be more precise, you can spell out the second field as well.
"^d" only works for finding the field beginning, not the field end.
It's a shame that ^w wants to find at least 1 whitespace character because otherwise it would be more robust to look for
^19^wSTYLEREF^w1^w\s^w^21.^19
Perhaps someone else knows how to work around that without using wildcards?
Torzaburo,
I suggest that you do this using a macro. You can start by recording the macro, and later refining your processing steps within the macro.
First turn on the hidden characters by navigating to Home > Paragraph > toggle the show/hide Paragraph symbol. Also, select all and toggle the field codes on (right-click and select "Toggle Field Codes".
Open a new blank Word doc in addition to the one you have open. You will use this later. Start the macro recording and find the field using the "^d" (field code) as you said.
When the field is found, copy only the field text within the brackets, and not the full field reference. While the macro is still recording, ALT + TAB to the new blank document and paste the field code in as plain text.
At this point, do the necessary find & replace processing to the field codes. Highlight the processed field codes, copy, ALT + TAB back to the original document, and paste back between the { } brackets.
Stop the macro recording. Add any further custom processing to the macro VBA.
Select-All and re-toggle the field codes. Update the field codes.
You don't need a macro. Just toggle all field codes on by using Alt+F9. Then do a find and replace for what you want to change. Once the replacement is complete, use Alt+F9 again to toggle the field codes back off.
Disclaimer: I didn't originate this solution, but it's clean and elegant and I thought it should be included here:
(Adapted from Search & Replace Field Codes in Word):
Create or find a single instance of the field you want to convert text to
Toggle Field Codes visible (AltF9)
Copy the code for the field you want to use to the Clipboard (highlight and CtrlC)
Open the Replace dialog box (CtrlH), insert the text you want to replace in the Find What box and then enter ^c in the Replace With box.
This will replace your text with the contents of the Clipboard, turning it into the field code you copied in step 3. It also copies formatting information (font, color, etc.), to control how the field will appear when hidden. (Caveat: I've tested this with Word 2003 under Windows 7 only.)
Coming in late on this, probably way too late for Beth (sorry Beth). And this may not be quite what Beth was looking for. But for anyone interested ...
It sounds like Beth may have created captions throughout the document using INSERT CAPTION (hence the presence of field codes). This means these captions will have been (automatically) created in CAPTION style.
To globally replace the separator "." with " " (space) in such captions, take two steps:
[1] Go to REFERENCES | INSERT CAPTION, then click on NUMBERING and replace the SEPARATOR "." with "EM-DASH". This will replace all separators in captions for the selected label in the CAPTION Window. If you have other labels in use in the document (e.g. FIGURE), select the other labels one by one and repeat this process.
[2] Do a find/replace searching for special character "em-dash" (^+) in style CAPTION, replacing with " ". Click REPLACE ALL.
Voila!
NOTE: This presumes that em-dash does not appear in the caption text anywhere. If it does, then you'll need to do a pre- and post- "fiddle" to ensure these em-dashes are not touched by the global replace above.
The "pre-fiddle" is to do a global find/replace across captions, replacing the em-dash ("^+") with some other string (e.g. "EM-DASH") that doesn't ever occur in any caption's text. Then you do the separator change as described above. Finally, the "post-fiddle" is to restore the em-dashes that were in the captions, by doing a global replace of the string "EM-DASH" with the actual em-dash character "^+".

Hungry Backspace in Eclipse?

In some editors there exist plugins implementing a feature called "hungry backspace" or "hungry delete".
If this mode is active in a text editor then one hit to the backspace key will automatically delete all whitespace chars backwards from the current cursor position up to the first non-whitespace character.
For example, this feature exists for Emacs and IntelliJ IDEA.
Does anyone know if it is also available in Eclipse?
Alt-Del is probably as close as you're going to get without writing a plugin yourself. Others have asked for this feature (coming from intelliJ) but so far it doesn't exist, or it's not published.
-Adam
CTRL-backspace is pretty close too: delete previous word:
function(); (4 spaces)
+ CTRL-BACKSPACE gives:
function
Other than that, AnyEdit plugin can convert trailing spaces into tabs (but also into "", effectively removing them)
Ctrl+Shift+Left, Backspace always works for me. works in notepad, web browsers, everywhere.
Stick to the standards :)
In SciTE, and Eclipse (3.4), Ctrl+Shift+Del with the caret after the last visible character will delete these spaces. Ie. it deletes from caret to end of line.
Actually, in SciTE I don't need to do that, since I have set it up to automatically remove these trailing spaces when saving.
Note: In Preferences > General > Keys, there is a Remove Trailing Whitespace binding (without key assignment by default) which seems to apply to File.
From eclipse Windows menu/Preferences
Search for Keys and filter to "Delete Previous Word"and Bind it to the Ctrl+Backspace