Here is a command to merge two lines, if these two lines share a common prefix, don't duplicate it
(defun my-merge-two-lines ()
"Merge the next line into the current line."
(interactive)
(save-excursion
(let (current-line next-line prefix)
(setq current-line
(buffer-substring (line-beginning-position) (line-end-position)))
(kill-whole-line)
(setq next-line
(buffer-substring (line-beginning-position) (line-end-position)))
(kill-whole-line)
(setq prefix (fill-common-string-prefix current-line next-line))
(insert
(concat current-line " " (substring next-line (length prefix)) "\n")))))
For example, assuming the point is on the first line
key: foo
key: bar
key: baz
run the above command twice, the text becomes
key: foo bar baz
If you like the idea, you can simply use the builtin M-^ (delete-indentation
/join-line
), note that you need manually set the prefix to "key: "
via C-x . (set-fill-prefix
).
<newline>key:
with an empty string?