DEV Community

Atif Afzal
Atif Afzal

Posted on • Originally published at atfzl.com on

2 2

Use emacs key bindings everywhere

I am used to emacs keybinding.

My caps lock is mapped to ctrl to avoid emacs pinky.

I am also used to making movements the emacs way , i.e.,

ctrl+f: right arrow
ctrl+b: left arrow
ctrl+p: up arrow
ctrl+n: down arrow
Enter fullscreen mode Exit fullscreen mode

I have also remapped Ctrl+g to escape because I despise the escape key in the MacBook Pro touch bar.

Mac supports this keybinding in most applications but these do not work for all applications. Like in my case it was Notability. For any kind of text editing, easy movement is a must.

After a lot of googling I found out about Karabiner-Elements which modifies the key bindings in the most stable and reliable way. It also has some nice customisations like ignoring keybindings for some set of applications. I am ignoring emacs because it already has the correct keybinding and using the modified keybindings messes it up.

After installing, open up the config ~/.config/karabiner/karabiner.json

This is my Karabiner configurations for above mentioned modifications:

profiles[0].simple_modifications =

[
  {
    "from": {
      "key_code": "caps_lock"
    },
    "to": {
      "key_code": "left_control"
    }
  }
]
Enter fullscreen mode Exit fullscreen mode

profiles[0].complex_modifications.rules =

[
  {
    "description": "Ctrl+F to right_arrow",
    "manipulators": [
      {
        "description": "emacs like movement",
        "from": {
          "key_code": "f",
          "modifiers": {
            "mandatory": [
              "left_control"
            ]
          }
        },
        "to": [
          {
            "key_code": "right_arrow"
          }
        ],
        "conditions": [
          {
            "type": "frontmost_application_unless",
            "bundle_identifiers": [
              "^org\\.gnu\\.Emacs"
            ]
          }
        ],
        "type": "basic"
      }
    ]
  },
  {
    "description": "Ctrl+B to left_arrow",
    "manipulators": [
      {
        "description": "emacs like movement",
        "from": {
          "key_code": "b",
          "modifiers": {
            "mandatory": [
              "left_control"
            ]
          }
        },
        "to": [
          {
            "key_code": "left_arrow"
          }
        ],
        "conditions": [
          {
            "type": "frontmost_application_unless",
            "bundle_identifiers": [
              "^org\\.gnu\\.Emacs"
            ]
          }
        ],
        "type": "basic"
      }
    ]
  },
  {
    "description": "Ctrl+P to up_arrow",
    "manipulators": [
      {
        "description": "emacs like movement",
        "from": {
          "key_code": "p",
          "modifiers": {
            "mandatory": [
              "left_control"
            ]
          }
        },
        "to": [
          {
            "key_code": "up_arrow"
          }
        ],
        "conditions": [
          {
            "type": "frontmost_application_unless",
            "bundle_identifiers": [
              "^org\\.gnu\\.Emacs"
            ]
          }
        ],
        "type": "basic"
      }
    ]
  },
  {
    "description": "Ctrl+N to down_arrow",
    "manipulators": [
      {
        "description": "emacs like movement",
        "from": {
          "key_code": "n",
          "modifiers": {
            "mandatory": [
              "left_control"
            ]
          }
        },
        "to": [
          {
            "key_code": "down_arrow"
          }
        ],
        "conditions": [
          {
            "type": "frontmost_application_unless",
            "bundle_identifiers": [
              "^org\\.gnu\\.Emacs"
            ]
          }
        ],
        "type": "basic"
      }
    ]
  },
  {
    "description": "Ctrl+G to Escape",
    "manipulators": [
      {
        "description": "emacs like escape",
        "from": {
          "key_code": "g",
          "modifiers": {
            "mandatory": [
              "left_control"
            ]
          }
        },
        "to": [
          {
            "key_code": "escape"
          }
        ],
        "conditions": [
          {
            "type": "frontmost_application_unless",
            "bundle_identifiers": [
              "^org\\.gnu\\.Emacs"
            ]
          }
        ],
        "type": "basic"
      }
    ]
  }
]
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay