Join-lines: Vim vs Emacs

Vim has a very simple system to join two lines: all you have to do is press the J (uppercase) key inside the line above.

In Emacs, instead, you must use the C-^ binding in the lower line.

But the Emacs solution may seem a bit more laborious if you use a keyboard with US International Dead Keys layout in MS Windows or GNU/Linux.

However, with a few small adjustments, it can become super-efficient.

What follows is my solution but, of course, everyone can find another one.

Caret or Circumflex

First of all we need to take a look at the US International Dead Keys keyboard layout for the key corresponding to the number 6 and, in specific to the two similar characters indicated on the top of the key.

_config.yml

You can see that on the number 6 button there are two similar characters: ^ (small) and ^.

Both are the same character, i.e. Caret or Circumflex.

The difference is in the use: the first one is used for compound characters, like â, ê, etc.

The second, instead, is used as an stand-alone character.

For the combination C-^ must be used the second version: the circumflex as a stand-alone character.

The original keys binding

The original keys binding to join two lines is apparently very simple: C-^ in the below line (Please remember the difference with Vim in which the J button is typed in the upper line.)

But in the US International Dead Keys Layout you must press three keys to obtain the ^ stand-alone character, Shift + Alt Gr + 6, and, then, add the Control key, as you can see in the following images:

_config.yml

_config.yml

Doesn’t that look like a piano finger articulation?

It’s indeed not very immediate to get.

This is one of the cases where it is best to change the original keyboard binding.

An alternative binding

It is very simple to set an alternative binding to achieve the desired result.

The best solution is to create a binding not already used by Emacs.

For example the binding C-, (Control + comma) can be very efficient because it’s easy to reach and available in the original Emacs configuration.

To obtain such a combination simply enter the following code in the .emacs configuration file:

(global-set-key (kbd "C-,") 'join-line)

After restarting Emacs, simply use the new C-, binding in the bottom line to combine it with the top line.

Thank you for your attention.