Wishlist: A Vim plugin for Composition Mode

I love both Vim and Scrivener. It would be sweet if I could have the best of both worlds with a vim plugin for composition mode.

Maybe one already exists, that I don’t know about🤔.

I can always “import & export” which is nice, but it would be a little better if I could just have my cake and eat it too in one spot! i.e. “Composition Mode”
Cheers🥂

1 Like

Hello, fellow vim appreciator! This has been a bit of running joke in the forums for at least ten years :grinning: There are a couple of us who every now bring the subject up, mostly for fun, because it’s probably not towards the top of any list of future features…

There are two reasonably good solutions if you do want vim bindings, and both are available in both Editor and Composition mode (or rather, you are using Vim as both the editor and composition mode, for selected documents whenever you want to).

The first is to use one of the utilities / scripts you can find, such as Use vim to edit text anywhere · Martins code snippets, or GitHub - cknadler/vim-anywhere: Use Vim everywhere you’ve always wanted to. You invoke a shortcut in Scrivener, the text is copied to a vim session, and when you save / end the session, the Scrivener text is updated. I used to use one of those utilities (can’t remember which one, sorry), and they work well.

But these days I use the built-in Scrivener feature, Sync to External Folder. Basically, this lets you create and edit files outside Scrivener in any editor you want and the changes are kept in sync either automatically when you close / open Scrivener, or manually at your discretion. You can ask Scrivener to keep snapshots of the changes, so you won’t lose anything.

This has a couple of advantages over the first method, including that you can include {{inline footnotes}} and ((inline comments/annotations)) using that markup in the text edited in Vim and they will be translated to the Scrivener version automatically (and vice-versa.


You can use this method to create / edit a single file, or write the whole book in it if you want…

As you can see from the screenshot of the options, you have plenty of choice over what’s synced, when and in what format, so you’ll want to play around with it first in a test project, but for me it offers a very good workaround.

S14.3 of the manual deals comprehensively with the feature, so it’s a good place to start.

HTH.

4 Likes

While browsing for the solution many of us would love, I found one more solution which could be interesting.

There is a software called Karabiner-Elements and Karabiner-Viewer, free and safe to download. It can change mappings of the keys, and you can initiate some sort of Normal and Insert Mode.

The solution below will map your keys

The mappings I use:

  • Press COMMAND + CTRL + ESC = Initiate “Normal” mode (it will just remap HJKL to arrows)
  • Press again COMMAND + CTRL + A = To initiate insert mode

Optional: You can also add COMMAND + CTRL + I, I removed that one because I already use that shortcut to something else.

For Linux and Windows users, please find out what is the replacement for command in your OS, you can do that by opening Karabiner-Viewer and pressing the key, it will print out the name of the button

You can easilly just switch off the rule if you don’t want to use it anymore

Steps

  1. Install Karabiner sofware
  • Open Karabiner-Elements Settings
  • Find Complex Modification > Add your own Rule
  1. Paste the following text below
{
    "description": "VIM Mode using regular keyboard HJKL",
    "manipulators": [
        {
            "from": {
                "key_code": "escape",
                "modifiers": { "mandatory": ["command", "control"] }
            },
            "to": [
                {
                    "set_variable": {
                        "name": "vim_mode",
                        "value": 1
                    }
                }
            ],
            "type": "basic"
        },
        {
            "from": {
                "key_code": "escape",
                "modifiers": { "mandatory": ["command", "control", "shift"] }
            },
            "to": [
                {
                    "set_variable": {
                        "name": "vim_mode",
                        "value": 0
                    }
                }
            ],
            "type": "basic"
        },
        {
            "from": {
                "key_code": "a",
                "modifiers": { "mandatory": ["command", "control"] }
            },
            "to": [
                {
                    "set_variable": {
                        "name": "vim_mode",
                        "value": 0
                    }
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": { "key_code": "h" },
            "to": [{ "key_code": "left_arrow" }],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "h",
                "modifiers": { "mandatory": ["shift"] }
            },
            "to": [
                {
                    "key_code": "left_arrow",
                    "modifiers": ["shift"]
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": { "key_code": "j" },
            "to": [{ "key_code": "down_arrow" }],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "j",
                "modifiers": { "mandatory": ["shift"] }
            },
            "to": [
                {
                    "key_code": "down_arrow",
                    "modifiers": ["shift"]
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": { "key_code": "k" },
            "to": [{ "key_code": "up_arrow" }],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "k",
                "modifiers": { "mandatory": ["shift"] }
            },
            "to": [
                {
                    "key_code": "up_arrow",
                    "modifiers": ["shift"]
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": { "key_code": "l" },
            "to": [{ "key_code": "right_arrow" }],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "vim_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "l",
                "modifiers": { "mandatory": ["shift"] }
            },
            "to": [
                {
                    "key_code": "right_arrow",
                    "modifiers": ["shift"]
                }
            ],
            "type": "basic"
        }
    ]
}
2 Likes