Question

i am working with Sublime Text2 in vintage mode. I disabled the arrow keys, so i don't use them to move the cursor in insert mode. Now is was wondering, if it is possible, to map the up/down keys, so that they will move a line of code up and down. In vim it is easy possible by just mapping the keys to do a sequence like "dd k P" to delete the line move cursor up and past it above.

The syntax for the key mapping in Sublime still is quite complicated to me as a beginner.

Thanks

Was it helpful?

Solution

Insert the following into your user key bindings.

[
    { "keys": ["up"], "command": "swap_line_up" },
    { "keys": ["down"], "command": "swap_line_down" }
]

The key mapping file is just JSON. There are 4 keys.

keysis a list of key entries. An entry will generally be something like ["<modifier> + <character>"]. You can define multi level keybindings by creating additional entries in the array. An example of this is to show and hide the side bar. The entry for this is ["ctrl+k", "ctrl+b"]. The available keys are described here.

command is a string specifying the command to run. To see what command is running with a particular action, you can enter sublime.log_commands(True) in the ST console.

args are the arguments passed to the command. This is a dictionary object. The keys for this correspond to the parameter name for a given command.

context is a list of dictionary entries to conditionally execute a given command. These can be somewhat complicated. There is a reference for context here.

I think the best way to familiarize yourself with the key bindings is to just try things out. I used the default keys as a reference.

You might want to keep this as a reference.

You can run a series of commands by creating macros. These are just lists of commands and arguments and are further described here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top