English help on website



特定の範囲内だけで検索したい場合(Ver9.34対応版)
目次検索系文− 特定の範囲内だけで検索したい場合

特定の範囲内だけで検索または置換をする方法が幾つかあります。
まずは普通の操作として行うとしたら、秀丸エディタヘルプ(マクロヘルプでない)の
[目次]→[コマンド]→[検索系コマンド]→[いろいろな検索例]→[特定の範囲内だけで検索したい場合]
のところに説明があります。
マクロの場合、これらの操作と同等の文として書くといいです。

選択した範囲を使う方法は、replaceallfastのパラメータのinselectで行単位、inselect2で文字単位にできます。
replaceallfastをすると選択が解除されるので、もう一度するには、selectinselect([範囲内検索を選択]コマンド相当)を使います。
setcompatiblemode 0x20000;
disabledraw;
if(selecting){
  replaceallfast "A","B",inselect2;
  selectinselect;
  replaceallfast "C","D",inselect2;
  selectinselect;
}
endmacro;

部分編集を使う方法は、rangeeditin、rangeeditoutを使います。行単位のみです。
setcompatiblemode 0x2000C;//0x000C=部分編集を使う
disabledraw;
if(selecting){
  rangeeditin;
  replaceallfast "A","B";
  replaceallfast "C","D";
  rangeeditout;
}
endmacro;

カラーマーカーを使う場合は、incolormarkerを使います。
手動操作の場合は手数が多くて面倒ですが、マクロにすると文字単位にできて、いちいち選択し直さなても対象を維持できるのでやりやすい場合があります。
setcompatiblemode 0x20000;
//disabledraw;
if(selecting){
  colormarker "#F00","#FF0", -1, 0, 0, "mylayer";
  escape;
  message "色を付けました";
  settargetcolormarker "mylayer";
  replaceallfast "A","B", incolormarker;
  replaceallfast "C","D", incolormarker;
  message "置換しました";
  deletecolormarkerall "mylayer";
  message "色を消しました";
}
endmacro;