2011-03-04 48 views

回答

66

M-X替换字符串 C-Q&A-J RET RET

关键是要引用的C-J,但除此之外,更换新行就像是更换别的。

+5

如果您正在使用文本,则可能更适合以空格替换空格。 – lex82

+1

'unfill-region'怎么办? – incandescentman

+0

是emacs中提供的不完整区域,还是您必须将它添加到自己? – bph

13

随着我的键绑定,我认为是标准的,在Windows上:

选择区域

转变 - 交替%

CTRL-Q CTRL-J

回报

return

或者换一种说法,查询替换区域,按Ctrl-q以获取扩展字符,按Ctrl-j放入换行符,全部替换为空白。

9

如果你想创建一个函数来做到这一点(和其绑定到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) 

这是基于一个例子,我说我found here

-2

您可能还会考虑旧备用delete-blank-lines,通常绑定到C-x C-o

+3

这是行不通的,除非所有的换行符都是空行。 –

相关问题