分页: 1 / 1
emacs如何自动连接两行
发表于 : 2012-05-25 19:15
由 iheartpp
vim有一个C+J的功能,自动把两行合并成一行,第一行的行尾和第二行的行首中间加一个空格,emacs该怎么做呢?
Re: emacs如何自动连接两行
发表于 : 2012-05-26 12:49
由 kardinal
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]
Re: emacs如何自动连接两行
发表于 : 2012-05-27 18:52
由 lhui
M-^合并上一行,M-0 M-^合并下一行。其实搜索join就能找到