Sublime Forum

Is there any way to change vi mode mappings?

#1

I want to map my J to move 7 lines down, but I didn’t find any way to do that :frowning:

0 Likes

#2

Presuming that you’re using the Vintage package that ships with Sublime, you want a keymap that looks like this:

    { "keys": ["J"], "command": "chain",
      "args": {
          "commands": [
              [ "push_repeat_digit", { "digit": 9 }],
              [ "set_motion", {
                    "motion": "move",
                    "motion_args": {"by": "lines", "forward": true, "extend": true },
                    "linewise": true
                  }
              ]
          ]
      },
      "context": [
        {"key": "setting.command_mode"}
       ]
    },

This chains together the key sequences for what would be 9j in standard vi, i.e. take the j action 9 times.

If you’re not using ST4 then you need to install the Chain of Command package to get the chain command (it is built-in in ST4).

This won’t work if you’re using some other vi package; in that case you would need to look into its documentation to determine how to map keys.

0 Likes

#3

waaaw, that a COOL STUFF! Thanks :smiley: btw, how to map K to move 7 line up, i tried to replace forward to backward but seems dont have ant effect

0 Likes

#4

i read the document in sublime’s official website, but seems it just give a example of jj to exit_insert_mode, is there any documents of vi mode mapping? appreciate for your reply :smiley:

0 Likes

#5

For that you likely want "forward": false instead of having it set to true.

0 Likes

#6

thanks :smiley:

0 Likes

#7

For looking at the default bindings, use View Package File from the command line, and then enter vintage keymap to filter the list to the keymap files in the Vintage package; the Default one is the base, and the ones with an OS in them are applied on top of the defaults to get OS specific variations as needed. There may also be an entry for it in the Preferences menu under Packages > Vintage, I’m not sure offhand.

0 Likes

#8

wish you have a good day sir :smiley:

0 Likes

#9

I’ll take a try :smiley:

0 Likes