Joining lines in Emacs

In Vim, I used to press J (or Shift + j) to join the two lines together, for example:

(defun hello () *<- cursor here
  (second line)) 


(defun hello () (second line))

In Emacs, there is no key binding for this, but we do have the join-line function to do the same thing. So we can just map some key we want to use. If you call join-line without any param, it will join the current line to the previous one, this is different from Vim, which will join the following line to the current, to do this in Emacs, you call (join-line -1).

And here's my keybinding, C-c l for join to previous line, and C-c n to join with the following line:

(global-set-key (kbd "C-c l") 'join-line)
(global-set-key (kbd "C-c n") (lambda () (interactive) (join-line -1)))

Date: 2019-03-20 Wed 00:00

Author: Huy Tran

Created: 2019-04-22 Mon 14:41