emacs如何自动连接两行

Vim、Emacs配置和使用
回复
iheartpp
帖子: 133
注册时间: 2008-09-18 20:15

emacs如何自动连接两行

#1

帖子 iheartpp » 2012-05-25 19:15

vim有一个C+J的功能,自动把两行合并成一行,第一行的行尾和第二行的行首中间加一个空格,emacs该怎么做呢?
kardinal
帖子: 750
注册时间: 2006-03-19 11:39

Re: emacs如何自动连接两行

#2

帖子 kardinal » 2012-05-26 12:49

kill-line 时,光标在行末,且该行不是空行,把下面一行连接在一起(可以接受一个数字参数,把下面 N 行连接在一起);否则和平时一样
delete-horizontal-space 我作了些调整,一般情况下中间会保留空格;
如果你没有进行相应的调整,应该是不会保留空格的,可以在这句后面加个 (insert " ")
具体情况可以参考 https://github.com/ran9er/init.emacs/bl ... _advice.el

[lisp]
(defadvice kill-line (around merge-line (&optional arg) activate)
"if this line is not empty and cursor in the end of line, merge next N line"
(interactive "P")
(let ((n (or arg 1)))
(if (and (null (bolp)) (eolp))
(while (< 0 n)
(delete-char 1)
(delete-horizontal-space) ;;(insert " ")
(if (< 1 n) (end-of-line))
(setq n (1- n)))
ad-do-it)))
[/lisp]
lhui
帖子: 78
注册时间: 2009-09-04 16:42

Re: emacs如何自动连接两行

#3

帖子 lhui » 2012-05-27 18:52

M-^合并上一行,M-0 M-^合并下一行。其实搜索join就能找到
回复