Matlab Editor: How to limit a "replace" to just the selected text?
古いコメントを表示
Matlab Editor: How to limit a "replace" to just the selected text?
I don't see a check-box for this.
It would be very useful when searching and replacing.
Is this even possible in the Matlab editor (cf the Visual Studio editor).
3 件のコメント
I guess I don't understand the problem. In the editor, I highlight a section of code then hit ctrl+f. This brings up the 'Find and Replace' dialog with the highlighted text filled into the 'Find' box. I then type in something to replace the text in the 'Replace' box. If I push the replace button MATLAB replaces only that section that is highlighted with what I put in the replace field. Then I close the 'Find and Replace' dialog.
Thus, as I described, MATLAB was limited to 'replacing' just the selected text.
Bryan
2020 年 12 月 23 日
If we are lucky they might introduce this function before 2040.
Walter Roberson
2020 年 12 月 23 日
I seem to recall reading that this is supported in the Live Script editor, but it would take me research to locate that. Live Script editor gets new features first.
採用された回答
その他の回答 (8 件)
AwedBy Matlab
2012 年 10 月 19 日
9 投票
It's beyond belief that MathWorks are ignoring user requests to implement this very basic feature! Right now if you want to do a find&replace within a selection of your code, you have to Cut the text to a word processor, do the find&replace there, then Paste it back into Matlab. Completely ludicrous that they release two versions a year, yet it doesn't cross their minds to add this essential feature!
1 件のコメント
Walter Roberson
2012 年 10 月 19 日
We don't know that it hasn't crossed their minds: we only know that it isn't publicly available through any known commands.
Marco Pretorius
2023 年 9 月 11 日
編集済み: Marco Pretorius
2023 年 9 月 11 日
9 投票
This is now possible with MATLAB R2023a by pressing "ctrl + H" and clicking on "Find in selection"

You can look at the updated documentation as well: https://www.mathworks.com/help/matlab/matlab_prog/find-and-replace-text-in-files.html
Jan
2011 年 5 月 14 日
2 投票
No, this is not possible in the Matlab editor. Let's ask Yair, if his EditorMacro could solve this.
4 件のコメント
Oliver Woodford
2012 年 9 月 20 日
It should be. I have just submitted a feature request.
Sinan Islam
2021 年 2 月 9 日
Why some basic options are impossible in MATLAB editor?!!!
Babak Zandi
2021 年 6 月 11 日
編集済み: Babak Zandi
2021 年 6 月 11 日
Still not possible after 10 years? unbelievable @MathWorks Support Team
Walter Roberson
2021 年 8 月 4 日
Ed Callway comments to Babak Zandi:
Yup, I waste HOURS doing search and replace over large areas by hand. Every other editor trivially handles search/replace on highlighted text. C'mon, this is a 1 week coop project, not a giant rewrite.
the cyclist
2011 年 5 月 14 日
0 投票
I am not 100% sure if this is what you mean, but if you select some text, and "copy" it (e.g. with cntl-c in Windows) before opening the search/replace window with cntl-f, then that text will appear in the "Find What" textbox, and you can replace it.
1 件のコメント
Kevin Claytor
2012 年 9 月 20 日
I don't think that's what he means, but FYI - you don't even have to copy the text first, just highlighting the text and pressing ctrl-f should auto-fill the "find" box.
Micky Harris
2015 年 1 月 7 日
0 投票
I think the question is how to do multiple replacements in the selected text of the open file. Or another way to say this limit the scope of replacement to only what is selected. The other editors i use notepad++ and nedit have this feature.
2 件のコメント
James Bell
2016 年 9 月 5 日
It's abhorrent that they still don't have this. I just open a new file in matlab and do the find/replace there... do they even have human factors engineers at Mathworks or just a bunch of 60's C programmers?
Walter Roberson
2016 年 9 月 6 日
James Bell, C as a programming language was not started until 1971, so if Mathworks has a bunch of 60's C programmers then they would have to be time travelers.
Leonard König
2017 年 8 月 24 日
0 投票
Sam Johnson's Solution works! Not as comfortable as a checkbox in the search and replace GUI, but at least it works. Sadly that MathWorks wasn't able to add this funktion in the past 6 years.
2 件のコメント
brian zhang
2018 年 5 月 20 日
can't believe this does not work! a basic function for programmer.
Sinan Islam
2021 年 2 月 9 日
I also get surprised when MATLAB lack the most basic tools and options.
WAPAstobbem
2018 年 6 月 21 日
0 投票
For me, the replace feature is about 50% working. I can highlight a section of text, but a Replace All will still replace from that cursor point to the end of the file. However, everything before the cursor point remains fine. So, I'm doing something wrong with the controls, or else the end cursor point is not yet considered under Replace All. Individual Replace seems to be working just fine.
Aron Magesh
2021 年 9 月 22 日
0 投票
Yes, it strange that the Find and Replace feature does not work for selected part of the code. I have to copy the selected text/code to a blank script, do F&R and then paste back.
カテゴリ
ヘルプ センター および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!