Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed last month.
Improve this question
How can I search and replace a String in all files of my current project?
Let's say I have the string "/sites/default/" now I want it to be "/public/sites/default/", but there are almost 1000 files.
Goto "Search"->"File" from menubar at the top left
Enter text, file pattern and projects
Click "Replace..." button at the bottom
Enter new text click ok
Voilà...
Depending on the file type you are focused on, Ctrl+H will open up different types of search screens.
A more consistent hotkey would be using the Alt method: Tap Alt, then A, then F.
Efficient Order of Operations:
Ctrl+C the text you want to do the replacing (if available)
Highlight the text you want to be replaced
Tap ALT, then A, then F. Brings you to File Search. The selection from (2) will auto-fill the search box
In the “File name patterns” input box, type in “.java” for replacing all Java files or type in "" to replace in all files
Click “Replace…”
Ctrl+V (Paste). Or type in the value you want to do the replacing
Enter
You can find more details in my blog post: http://blog.simplyadvanced.net/android-how-to-findreplace-in-multiple-files-using-eclipse/
Use Ctrl+H for opening Eclipse search dialog, select appropriate search tab and select "Replace..." to get you to the "Search and replace" dialog
Strange but it is a two step task:
Search what you want
In the search tab right click and select replace , or replace all:
A demo at:
http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html
Tonny Madsen said it right, but sometimes this is too simplistic.
What if you want to be more selective in your replacements since not all replacements are correct for what you're trying to do?
Here's how to get more granularity to do the replacements only in certain folders, files, or instances:
First, do like he said:
Click Search --> File... OR press Ctrl + H and choose the "File Search" tab.
Enter text, file pattern and choose your Workspace or Working Set.
Then:
Click Search
When your results come up, make some folder, file, or instance selections by Ctrl + clicking on the ones you'd like to select. Ex: here's my selection. I've chosen 3 instances, 1 file, and 1 folder:
Now, right-click on your selection and go to --> Replace Selected.... Here's a screenshot of that:
Enter what you'd like to replace it "With". In my case you can see it says it is "Replacing 190 matches in 4 files". Now click OK.
Voilà!
References:
Here's the tutorial I came across that taught me this: http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html?page=2
ctrl + H will show the option to replace in the bottom .
Once you click on replace it will show as below
There is an option in search => file and shortcut is Ctrl+H. Go for further refer follow link. This is work fine with Eclipse Neon
Is there a way to find/replace across an entire project in Eclipse?
If you want to replace two lines of code with one line, then this does not work. It works in notepad++. I end up open all files in notepad++ and replaced all.
Ctrl+F gives me Find/Replace dialog box.
Or you can,
First Alt+A
Next Alt+F
Then press on Replace button.
If non of them worked:
Goto -> Window -> Preferences -> General -> Keys and search for replace then you will see binding for Find and replace. In the bottom of that window, you can add your key to Binding text box. There you can add or edit any keys as shortcut.
I have tried the following option in Helios Version of Eclipse.
Simply press CTRL+F you will get the "Find/Replace" Window on your screen
I've recently switched from Eclipse to IntelliJ IDEA 13. I use the VI keybindings.
One non-vi thing I am used to doing in Eclipse is using Shift + ↑ / Shift + ↓ to block a few lines of text. The behaviour of this text selection in Eclipse is the same as almost every other text input widget I've ever used. Typically I do one of two things after making the selection - delete this block or comment it out (⌘ + /).
I have no found equivalent keyboard-only multi-line selection function in IntelliJ IDEA 13.
Shift + ↑ does not start a block selection - it seems to page the cursor up and down the screen.
If I use the mouse to start making a selection, then the arrow keys do extend the selection. However, I'm unable to start a selection using the keyboard alone.
I'm aware of the ⌘ + W ever-outward-growing smart element selection - but if you then use the arrow keys, the selection is lost, not extended.
How can I start and then extend a selection region across multiple lines using the keyboard only on Mac OS X (that works with the VI keybindings enabled)?
Multi-line caret
For Mac, you can use ⌘+⌘(Hold)+↑ / ↓.
For Windows, replace the ⌘ with CTRL.
ESC will end multi-line mode.
Change Multi-caret Hotkey
To add a custom Keymap, ⌘+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 ⌘, SHIFT, and arrows for improved selection power.
Sounds like you need to map it. In the default key mapping Shift+↑ and Shift+↓ work as expected (i.e. as you describe). I do not have the vi mapping available to check it. Go into Settings > [IDE Settings] > Keymap. In the Keymap, go to "Editor Actions". Configure the "Down with Selection" and "Up with Selection" options. This may mean removing the Shift+↑ and Shift+↓ mappings from something else.
I use the IdeaVIM plugin on Mac OS and I can increase or decrease my selection with the keyboard only with alt-Up/Down.
It is possible I customized the VIM keymap to this, can't remember if it is default or not. However, the editor action you are looking for in the keymap settings is "Select Word at Caret" and "Unselect Word at Caret". Repeatedly pressing the keystroke smartly selects/unselects the text. It almost always selects what I want.
You can use alt+Up/Down/Right/Left or alt+mouse-select to block select on mac in IntelliJ
I'm using Checkstyle for Java in Eclipse IDE. I don't know in every java file, at second line, I always receive warning in Checkstyle : (although I'm pretty sure that I don't press tab key)
File contains tab characters (this is the first instance).
public class Percolation {
private boolean[][] grid;
...
}
When I have typed : public class Percolation {, press enter, Eclipse will make an indent for me, after that, I type private boolean[][] grid;. But, I still receive this warning.
Please tell me how to fix this. (I don't want to turn off this warning, because this is a must. Another people will check again my file).
Thanks :)
step 1 In eclipse, Preference > Java > Code Style > Formatter. Edit the Active profile.(If you don't wish to edit the built-in profile , create a new profile). Under "Active profile:" there is a drop down dialogue box .. beside it, click "Edit..." which opens up the edit dialog box. Under the "Indention" tab, you'll find Tab Policy. Change the Tab Policy from Mixed to Space only & apply the changes.
step 2 Back to your Eclipse Perspective, navigate via the menu bar: Source > Format Element (not "Format") and save.
Run checkstyle you won't find "File Tab Character: File contains tab characters (this is the first instance)." warning anymore.
To visualize the difference by enabling whitespace character that you'll find in tool bar.
In eclipse, go to Preferences > General > Editors > Text Editors
and check the box for "Insert spaces for tabs". Then it will indent with spaces instead of tabs.
another possibility is find and replace:
- copy a tab
- Got to Find and Replace Window
find: paste the tab
replace: type 4 whitespaces (or number of whitespaces a tab consists of)
-> replaceAll
For Java code:
step 1 In eclipse, Preference > Java > Code Style > Formatter. Create a new profile and initialize it with default profile. There is a drop down dialogue box .. beside it, click "Edit..." which opens up the edit dialog box. Under the "Indention" tab, you'll find Tab Policy. Change the Tab Policy from Mixed to "Space only" & apply the changes.
step 2 Correct Indentation of your code by ctrl+I. It will replace Tab with Space.
To fix this Navigate to Preferences > Java > Code Style > Formatter.
Then click on New > give name for the formatter > click on ok.
Once you complete this step, on the automatically popped up window which is the formatter you created, click on indentation > tap policy > select space only.
Or if you come back later time you could click on edit and follow the same step.
in the indentation size I prefer to put 4 > click apply and close.
After that right click on the class file you want to format > source > format.
This will cause the indentation to be spaces instead of tabs.
I was also facing the problem but I got the solutions.
Step 1 : Go to Window > Preferences > Checkstyle.
Step 2 : In the right side You will see the Global Check Configurations. There you will find that Two configurations are available. Select the configuration with Eclipse and click on Set as Default button and click on OK.
Hope this will solve your problem.
For Java Editor
Click Window » Preferences
Expand Java » Code Style
Click Formatter
Click the Edit button
Click the Indentation tab
Under General Settings, set Tab policy to: Spaces only
Click OK ad nauseum to apply the changes.
For other editors refer here How do I change Eclipse to use spaces instead of tabs?
Simply fixed that style issue (triggered by scalaStyle) by removing TAB with SPACE indent :)
Anyone know the keyboard shortcut to copy/paste a line into a new line in Eclipse, without having to highlight the entire line?
ctrl-alt-down turns my whole screen upside down (I'm on windows). Interestingly, that's what's specified in the windows->preferences.
Ctrl-Alt-Down: copies current line or selected lines to below
Ctrl-Alt-Up:: copies current line or selected lines to above
Ctrl-Shift-L: brings up a List of shortcut keys
See Windows/Preference->General->Keys.
(Tested on Windows) [Per below comments, works as well in Ubuntu, IBM RTC 4 / RSA 9]
In Eclipse, press Ctrl+Shift+L two
times in succession (or Ctrl + 3 > type: Keys > Enter).
In 'type filter text' (search) text box, type Copy Lines
Select the filtered row, right click the 'Binding' field, and do Select All
Press Ctrl+Shift+V
Give OK
From now on, for any line you want to duplicate, just press Ctrl+Shift+V.
You have to turn off the graphics hot keys that flip the screen. If you're on Windows, you need to right click on the Windows desktop and select "Graphics Properties..." (or something similar depending on your version of Windows). This will bring up a screen where you can manage graphics and display options, look for a place where you can disable hot keys, sometimes it's hidden under something like "Options and Support". Turn off the CTRL + ALT + ↑ and CTRL + ALT + ↓ hotkeys (alternatively you can just disable all graphics hot keys if you're not using them).
If you want to copy a line to the clipboard you can also use the trick:
Ctrl-Alt-Down
followed by
Ctrl-X
The drawback is that the file where you copy the line from becomes dirty.
Ctrl-D would delete a line
Ctrl-Z would undo deletion, with highlithing entire line
Ctrl-X/C cut or copy entire line
The advantage over Ctrl-Alt-Down followed by Ctrl-X suggested by other users is that it doesn't make eclipse think that the file was changed in any way. It's also faster and causes no problems even if the user has rotating screen issue with Ctrl-Alt-Down/Up keyboard shorcut. So there's no need to remap shorcuts for this.
Another way to go would be hitting Alt-Shift-Up until the entire line gets selected. If you've gone too far, of course you can select less with Alt-Shift-Down.
If Your Window pc, you may try this, it's also for STS:
Ctrl + win + Alt + Down :: Copy current line or selected line to below
Ctrl + win + Alt + Up :: Copy current line or selected line to above
I've written the linecopypaste plugin for Eclipse that mimics Visual Studio's copy/cut/paste behaviour. I've also found copycutcurrentline which appears to do the same.
On my Mac the default setting is is ALT+CMD+Down
You can change/view all key bindings by going Eclipse -> Preferences (shortcut CMD+,) and then General -> Keys
Ctrl+Alt+Down Copies current line to below like notepad++ (Ctrl+D)
If your whole screen is 180° rotted then you should disable your hotkey settings.
Right Click -> Graphics Options -> Hot Keys -> Disable
That it now you done try shortcut Ctrl+Alt+Down
Try this in MAC.
ALT + COMMAND + DOWN
it works.
If anyone using Mac computer the CTRL + ALT + DOWN keys doesn't work.
Try it with,
ALT + COMMAND + DOWN
It works.
We can assign any command to any action(given) in Eclipse
From Menu Bar go to
Window > Preferences
then search for the keys
then search copy line
then click on copy line and then click on command in Binding
and peform a command which you wish to use for duplicating line i use ctrl+shift+d
you can choose whatever you want
On Mac, I've tried the linecopypaste and it works great
cmd+c -> Copy current (unselected) line, just like "yy" command in Vi/Vim
cmd+v -> Paste it, like "p" command in Vi/Vim
Thank's Larsch for your work!
PD: Using Eclipse Luna 4.4.2 in Yosemite
I have to change the assigned key,
e.g.
Windows/Preference --> General --> Keys
Select "Duplicate Lines" under command
Click on "Binding"
Ctrl + Shift + D
Just another approach:
1) Alt+Up and Alt+Down (or Alt+Down and Alt+Up, order does not matter)
2) Ctrl+C
But of course vim's "yy" is the fastest :)
Disabling the hot keys for the Intel Driver worked for me for Windows 7. However, for Windows 8, when I tried that, it prevented eclipse from getting the Ctrl-Alt-Down keystoke. I had to change the Intel driver key binding to Ctrl-Alt-F10 (or something else it will accept). Eclipse then gets the Ctrl-Alt-Down and copies the line.
For mac, shift+alt+down_arrow works in netbeans' editor.
It's working with me on ,
Eclipse + Spring tool suite .
ALT + COMMAND + DOWN
I am using Windows 7. To disable that all I did is to Right click on the Windows desktop and select "Graphics Properties" ->Options. Then selected "Off" at the left side on the resulting screen. This disabled all hotkey combination. I think there is no way to disable only some them, its all or none. Anyway I didn't need them. So now crtl+Alt+Up and Crtl+Alt+down works for me in Eclipse and my screen stays same :)
I think similar option also exist in other versions of Windows. Have fun :)
For personal usage, I add a vim plugin like Vrapper to Eclipse and just use yy to copy entire line.
The Ctrl+Alt+Down / Ctrl+Alt+Up flips my screen so I overrode that in the Eclipse shortcuts via
Window => Preferences => General => Keys.
Search for "dupl" to find the Duplicate Lines command. I overrode the default and chose Ctrl+Shift+D. For me, that's easy to remember just like Ctrl+D to delete lines
ctrl+alt+down/up/left/right takes precedence over eclipse settings as hot keys. As an alternative, I try different approach.
Step 1: Triple click the line you want to copy & press `Ctrl`-`C`(This will
select & copy that entire line along with the `new line`).
Step 2: Put your cursor at the starting of the line where you want to to paste
your copied line & press `Ctrl`-`V`.(This will paste that entire line & will
push previous existing line to the new line, which we wanted in the first place).
The combination of Ctrl + Shift + Alt + Down worked for me on Linux.
To copy text from the begining of line to the cursor position: ctrl + insert
It does the job and save a lot of time for me.
Another shortcut way to do this is press Ctrl+Shift+L and select which command you want to perform and hit enter
its best practice for beginner.
See how to make the eclipse default shortcut work ctrl alt↓
Select line: Put cursor on the line to copy, select line with ShiftHome if cursor in the end of line or ShiftEnd if cursor is in starting of line
Duplicate line below (default expected behavior) or above ctrl alt↓ or ctrl alt ↑ but the key here is you need to select the line/block
Some answers focus on disabling the screen Rotation in Windows or any other OS, that applies to prevent accidental keypress.
I've seen this done in TextMate and I was wondering if there's a way to do it in IDEA.
Say I have the following code:
leaseLabel = "Lease";
leaseLabelPlural = "Leases";
portfolioLabel = "Portfolio";
portfolioLabelPlural = "Portfolios";
buildingLabel = "Building";
What is the best way to append '+ "foo"' to every line? Column mode won't work since the lines are not correctly aligned on the right side... unless there is an easy way to right justify the text :P
Since Idea IntelliJ IDEA 13.1 there is a possibility to edit multiple lines.
Windows
Alt + Shift + Mouse click
macOS
Option + Shift + Mouse click
for selection. More about this new improvement in the IntelliJ blog post here. Very useful feature.
I use Column Selection Mode (Cmd+Shift+8 on Mac) which allows to create multiple cursors via Shift+Up or Shift+Down then edit all the lines together.
Starting from IntelliJ IDEA 14 there is also Clone Caret Above / Below:
Windows: Ctrl, Ctrl+Up/Down
MacOS: Option,Option + Up/Down
(hold the second press of the modifier key, then press the arrow key)
Another keyboard-only approach. It's possible (since 13.1 version) to use Alt+J / Shift+Alt+J (Ctrl+G for OS X) shortcuts for creating multiple carets. Alt+J selects the next occurrence of the currently selected text and adds another caret.
Select the first semicolon
Then press Alt+J four times
Edit what you want to
Press Esc to return to the first line.
Place caret at end
Windows: CTRL + CTRL(Hold) + ↑ / ↓
Mac: option + option(Hold) + ↑ / ↓.
To place caret at the end of rows: move caret to top row, clone down to bottom, and click END.
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+↑ / ↓ on Windows and ⌘+↑ / ↓ on Mac.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.
Column mode works just fine: first select all the lines in column mode, then press END: each cursor will jump to the end of respective line.
On Linux (NO MOUSE NEEDED):
ALT + SHIFT + INSERT to enter block-mode
SHIFT + UP or SHIFT + DOWN to select multiple lines
END to jump to the end of each line
now type foo, it will append it to each line:
Now deselect everything with ESCAPE and switch back to normal selection mode with ALT + SHIFT + INSERT.
Since WebStorm 2020.2 you can use AltShiftG to add carets at the end of each selected line.
The new action for working with multiple carets (Alt+Shift+G) lets you quickly place carets at the end of each selected line and removes the selection as soon as all carets are added.
What’s new in WebStorm 2020.2
You could also do a vertical code block selection by clicking mouse wheel and dragging:
Select Next Occurrence:
Alt+J on Windows, Ctrl-G on Mac OS X
Unselect Occurrence:
Alt+Shift+J on Windows, Ctrl-Shift-G on Mac OS X
Select All Occurrences:
Ctrl+Alt+Shift+J on Windows, Ctrl-Cmd-G on Mac OS X
for more reference: link
I just use the macros for this sort of thing. I start recording the macro, do it once, then play back the macro on each line I want to modify. You'd be amazed at how fancy you can get with the macro record/playback feature.
It took me a while to find out, but on a Mac you can double-press Option (press it once, release, press it again, keep it pressed) and use Up/Down keys to create/remove carets as you wish.
You can also hold Shift+Option and click to create/remove carets at specific points.
ALT + CTRL + SHIFT + CLICK on linux
Hold ALT and use the mouse for click and drag
It's Option + Shift + Click for Macbook.
All Important Intellij Shortcuts: https://docs.google.com/document/d/1KagEr4hDmTugMJJLsYUgc122zXEnbj4A2vHoe8PtKpo/edit?usp=sharing
I hold (Shift + option + command) then click where ever I want the extra cursor to go. Using Webstorm and on a Mac
In this case you can also just select the piece of code in which you want to do this and perform a replace on it. Replace:
";
with:
" + "foo";
So in case you didn't know: If you have text selected while you perform a replace (Ctrl+R or Cmd+R) it will only apply to the selected piece of text.
For newer versions use: Alt + Shift + Insert
You can set multiple carets from the search and replace tool.
Ctrl + R to open Search & Replace tool
Write the character or word identifying the beginning of each recurrence to edit
Clic on 'Select all occurence' in the Search & Replace tool, IntelliJ will put a caret for each occurence
Live the magic
For Mac:
Option + Shift + Click & Drag
What I usually use (NetBeans, but I believe it is simple to use in any IDE) is find&replace.
You just find ;\n and replace it with + $foo;\n then you don't apply to ALL lines but you place cursor on the first line and you just hit "replace" button (depends on your IDE I suppose) 7 times to change 7 lines in no time. Easy and simple and it should be done with the most basic and the most advanced IDE you can find.
EDIT:
In IntelliJ (don't know if it works in other IDEs too) you can use your regexp search&replace to selection only so you can actually use "replace all"
For mac users it's : ALT + SHIFT + Click
All the above answer are great, but if you want multiline edit at the end of lines then you have press "End" key while your multiline selection is active.
For Mac Sequence of command will be:
shift option click # select a set of lines
command right arrow # go to the end of lines
This will do multiline select at the end of the line and you can edit it as required