如何在Emacs中从选定区域删除所有换行符?
M-x replace-string
C-q C-j
RET
RET
技巧在于使用C-q
引用C-j
,其他情况下替换换行符与替换其他字符一样简单。
使用我认为是标准的按键绑定,在Windows上:
选择区域
Shift + Alt + %
Ctrl + Q,Ctrl + J
回车
回车
!
换句话说,查询替换区域,使用Ctrl + Q获取扩展字符,使用Ctrl + J插入新行,将它们全部替换为空。
(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)
That's based on an example I that I found here.
你也可以考虑使用老牌的 delete-blank-lines
,通常绑定到 C-x C-o。
unfill-region
可以做到这个吗? - incandescentman