如何从Emacs中的选定区域删除所有换行符?

Sła*_*osz 48 emacs replace newline

如何从Emacs中的选定区域删除所有换行符?

Bru*_*ens 74

Mx replace-string Cq Cj RET RET

诀窍是引用Cj,但否则替换换行就像替换其他任何内容.

  • 如果您正在使用文本,则替换为空格可能更实际. (7认同)
  • 怎么样'填充区域',那会这样做吗? (3认同)

Pet*_*te 14

我的密钥绑定,我认为是标准的,在Windows上:

选择地区

移 - 交替%

ctrl-Q ctrl-J

返回

返回

!

或者换句话说,查询替换区域,ctrl-q获取扩展字符,ctrl-j放入换行符,替换为nothing,all all.


Mar*_*air 11

如果你想创建一个函数来执行此操作(并将其绑定到F8),您可以尝试:

(defun remove-newlines-in-region ()
  "Removes all newlines in the region."
  (interactive)
  (save-restriction
    (narrow-to-region (point) (mark))
    (goto-char (point-min))
    (while (search-forward "\n" nil t) (replace-match "" nil t))))

(global-set-key [f8] 'remove-newlines-in-region)
Run Code Online (Sandbox Code Playgroud)

这是基于我在这里找到的一个例子.