[英]How to replace spaces with A[ in emacs
I have an input file like this 我有一个这样的输入文件
line 1
line 2
line 3
There are four spaces before all the lines I want to replace. 我要替换的所有行之前有四个空格。
I want the end result to be: 我希望最终结果是:
A[line 1
A[line 2
A[line 3
(Its funny, so editor doesn't want to display line by line) (很有趣,所以编辑器不想一行一行地显示)
I tried Mx replace-regex ^[]+ -> A\\[
, but get error invalid regex "Unmatched [ or [^"
我尝试了
Mx replace-regex ^[]+ -> A\\[
,但收到错误的invalid regex "Unmatched [ or [^"
I tried Mx replace-regex ^[]+ -> A[
, but get same error. 我尝试了
Mx replace-regex ^[]+ -> A[
,但收到相同的错误。
Replacing the [
is a problem. 更换
[
是一个问题。 How to fix this? 如何解决这个问题?
Try 尝试
M-x query-replace-regex RET ^ RET A[ RET
^^^
notice the 4 spaces here
In your examples you are missing a space inside the character class: ^[ ]+
在您的示例中,字符类内部缺少空格:
^[ ]+
Prettier would probably be: ^[[:space:]]+
for every kind of white-space. 对于每种
^[[:space:]]+
漂亮的可能是: ^[[:space:]]+
。
Rectangles give you another way to deal with these issues. 矩形为您提供了处理这些问题的另一种方法。 Cua-mode provides an even nicer system.
Cua模式提供了更好的系统。 To use it, first add the following to your .emacs:
要使用它,首先将以下内容添加到您的.emacs中:
(setq cua-enable-cua-keys nil)
(cua-mode)
Then, with point at the *
in the following: 然后,在下面指向
*
:
* line 1 line 2 line 3
Hit C-enter
, and use the arrow keys (or Cn
and Cf
) to move point to: 点击
C-enter
,然后使用箭头键(或Cn
和Cf
)将点移至:
line 1 line 2 *line 3
The blanks will all be highlighted. 空白将全部突出显示。 Type
A[
to insert the characters. 键入
A[
以插入字符。 Then hit Cw
to delete the spaces. 然后按
Cw
键删除空格。
M-x query-replace-regex RET ^ + RET A[ RET
因为它是一种可替换的字符,所以不需要方括号或类
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.