Sublime Forum

Command move_caret_forward has stopped working

#1

Edit: Go here for the plugin to move caret by number of lines.

Hi all,
First post, so please be gentle :wink:
I currently have 2 user defined commands specified as such;

{ "keys": ["alt+left"], "command": "move_caret_back", "args": { "nlines": 10}  },
{ "keys": ["alt+right"], "command": "move_caret_forward", "args": { "nlines": 10} },

This was working fine on my old PC. Now that I moved to a new PC and had to setup Sublime Text 3 again, the above commands aren’t working.

When enabling command log on the console using:

sublime.log_commands(True)

I get the following log;

Package Control: No updated packages
reloading settings Packages/User/Package Syncing.sublime-settings
Package Syncing: Start Complete Sync
Package Syncing: End Complete Sync
Running make build-simTest -j8 -O
Unable to open /C/Users/simona2/AppData/Roaming/Sublime Text 3/Packages/Default/Default (Windows).sublime-keymap
indexing [queue 10]: no files were indexed out of the 3524 queued, abandoning crawl
>>> sublime.log_commands(True)
command: drag_select {"event": {"button": 1, "x": 1022.5, "y": 315.5}}
command: move_caret_forward {"nlines": 10}
command: move_caret_back {"nlines": 10}

The commands are going through, so i’m guessing the command is no longer supported or something…

I use the move_caret_forward and move_caret_back extensively… is there a replacement?

Cheers,
Simon

1 Like

#2

There’s no mention of that command in the command list; are you sure it wasn’t provided by a plugin that you haven’t enabled in the new install? A quick test seems to indicate that the command logger just logs what command it would execute, but no error is generated if you specify a command that doesn’t exist.

The closest command I can find for what you have above is the move command with a by argument of “lines” that is bound by default to the up and down arrow keys:

{ "keys": ["up"], "command": "move", "args": {"by": "lines", "forward": false} },
{ "keys": ["down"], "command": "move", "args": {"by": "lines", "forward": true} },

There does’t seem to be an argument (documented at least) that would allow for this to go for more than one line at a time, though (I’m assuming that’s what nlines is specifying).

If all else fails (and assuming I am interpreting what you want to do correctly), saving the following in a .py file in your Packages/User path will add the commands for you:

class MoveCaretBackCommand(sublime_plugin.TextCommand):
    def run(self, edit, nlines):
        for num in range (1, nlines):
            self.view.run_command ("move", {"by": "lines", "forward": False})

class MoveCaretForwardCommand(sublime_plugin.TextCommand):
    def run(self, edit, nlines):
        for num in range (1, nlines):
            self.view.run_command ("move", {"by": "lines", "forward": True})
3 Likes

#3

You my friend are a genius.

Thanks to your answer, now i clearly remember my old setup, and you’re correct by assuming that those commands were linked to a python script in the user folder on the old machine! Unfortunately, I.T. took back the laptop and now is formatted, but thanks to you, now i’m able to have those commands back.

Cheers,
Simon

1 Like

#4

This is where I got the plugin from! I found it! yay

1 Like

#5

I had the same issue as sayo9394, but the python script they referenced must’ve been coded for ST2. Your’s is much simpler and cleaner (and actually works on ST3). Thanks a bunch.

0 Likes

#6

Hi all,

I’m fairly new to sublime and came upon this plugin as moving the caret to the top/bottom of the current visible lines is something I use extremely often in my current IDE. Followed all the instructions, but I have a feeling that I’m installing incorrectly, or that ST3 on OS X broke the plugin. My console is spitting out the following:

File “/Users/ageis/Library/Application Support/Sublime Text 3/Packages/User/move_caret.py”, line 2, in
class Move_caret_topCommand(sublime_plugin.TextCommand):
File “/Users/ageis/Library/Application Support/Sublime Text 3/Packages/User/move_caret.py”, line 6, in Move_caret_topCommand
row = self.view.rowcol(screenful.a)[0] + 1
NameError: name ‘self’ is not defined

Any help is greatly appreciated.
Thanks,

0 Likes

#7

It looks like the code as posted in that forum link is not properly indented; in python indentation is important.

For example,the code:

import sublime, sublime_plugin
class Move_caret_topCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        screenful = self.view.visible_region()
        col = self.view.rowcol(self.view.sel()[0].begin())[1]
    row = self.view.rowcol(screenful.a)[0] + 1
    target = self.view.text_point(row, col)

    self.view.sel().clear()
    self.view.sel().add(sublime.Region(target))

does not work because the last 4 lines are a part of the run method but they’re not indented to the same level as the rest of the method.

Modifying it to indent those lines solves the problem you’re having:

import sublime, sublime_plugin
class Move_caret_topCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        screenful = self.view.visible_region()
        col = self.view.rowcol(self.view.sel()[0].begin())[1]
        row = self.view.rowcol(screenful.a)[0] + 1
        target = self.view.text_point(row, col)

        self.view.sel().clear()
        self.view.sel().add(sublime.Region(target))

You would have to make a similar modification to all of the commands defined in that post as they all seem to have the same issue.

1 Like