How to move X number of lines?


#1

For example, I want to map a keyboard shortcut that moves up 10 lines at a time. How might I do that?

In vim-mode, I can achieve the same by typing 10k to move up by 10 lines. How would I map ctrl-k to do the same thing?


#2

This would be the function you’re looking for.


#3

@DamnedScholar Seems so! How do we obtain the instance? Or is there a command associated with it?


#4

Putting this in your init.coffee will do what you want.

atom.commands.add 'atom-text-editor', 'user:up-10-lines', ->
    return unless editor = atom.workspace.getActiveTextEditor()

    editor.moveUp(10)

And you can bind the command simply enough.

'atom-text-editor':
   'ctrl-k': 'user:up-10-lines'

Keep in mind that ctrl-k has a variety of bindings attached to it already, so if you press that combination by itself, you’ll have to type something else so that Atom realizes you’re not using one of the other combinations.


#5

Thanks a ton!

I noticed that (with cmd-k on OS X)! Is there a way to disable all of those (since I’m not using them), so the delay can be gone?


#7

You can unset bindings. I personally feel like the number of bindings attached to that key already makes it not worthwhile. Are all of your modifier keys spoken for when it comes to the direction pad? Because a modifier key and up or down would be pretty intuitive.


#8

Coming from Vim, IJKL with H as the insert key is similarly intuitive to the direction pad, which is what I had for a good while, but I’ve recently settled with Vim’s HJKL with I as the insert key since it works everywhere with less configuration.

What are the implications of

'*':
  'cmd-k': 'unset!'

, if any?


#9

For your purposes? None, because you’re going to have to unset each keybinding, from cmd-k cmd-0 down through cmd-k up.