Menu

Join line to following line

I wrote a while ago about using M-^ to join the current line to the previous line. In fact, when editing I find that I most often want to join a line to the following line. I used to do this by using C-e to move to the end of the line and then C-d to delete until I got the next line joined to the current one. It is easier to do this with a single key using a simple function, which I set to C-j. Add the following to your emacs config file:

;; join line to next line(global-set-key (kbd "C-j")(lambda()(interactive)(join-line -1)))

You can keep hitting C-j to keep joining the next line.

Update

I originally used M-j as the keybinding for this, but Kaushal Modi pointed out in the comments that C-j is a better choice.

You are quite right – I hadn’t spotted that! It is handy to have on a single key so you can bash it out repeatedly.

Kaushal Modi

The default bindings for M-j is priceless for me. Let’s say you are on a comment line “;; abc| def” where | is the cursor. If you hit M-j there, that single comment line converts to 2 lines: “;; abc” and “;; def”. But I also feel that need to frequently do (join-line -1). So I have a “pull-up” funciton that does that plus something special when call within a comment code.